Tag: databases

Questions Related to databases

With SQL, how do you select all the columns from a table named "Persons"?

  1. SELECT [all] FROM Persons ;

  2. SELECT *. FROM Persons ;

  3. SELECT *.Persons ;

  4. SELECT * FROM Persons ;


Correct Option: D
  1. SELECT [all] FROM Persons WHERE FirstName='Peter' ;

  2. SELECT * FROM Persons WHERE FirstName='Peter' ;

  3. SELECT * FROM Persons WHERE FirstName LIKE 'Peter' ;

  4. SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter' ;


Correct Option: B
  1. SELECT * FROM Persons WHERE FirstName LIKE '%a';

  2. SELECT * FROM Persons WHERE FirstName='a' ;

  3. SELECT * FROM Persons WHERE FirstName LIKE 'a%' ;

  4. SELECT * FROM Persons WHERE FirstName='%a%;


Correct Option: C
  1. SELECT * FROM Persons SORT 'FirstName' DESC ;

  2. SELECT * FROM Persons ORDER BY FirstName DESC;

  3. SELECT * FROM Persons ORDER FirstName DESC ;

  4. SELECT * FROM Persons SORT BY 'FirstName' DESC ;


Correct Option: B
  1. UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen';

  2. MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen ;

  3. UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen' ;

  4. MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen' ;


Correct Option: A

With SQL, how can you delete the records where the "FirstName" is "Peter" in the Persons Table?

  1. DELETE FROM Persons WHERE FirstName = 'Peter' ;

  2. DELETE FirstName='Peter' FROM Persons;

  3. DELETE ROW FirstName='Peter' FROM Persons ;

  4. TRUNCATE FROM Persons WHERE FirstName='Peter'


Correct Option: A
Explanation:

To solve this question, the user needs to know the basic syntax for deleting records in SQL, including the correct use of the DELETE command and WHERE clause.

Now, let's go through each option and explain why it is right or wrong:

A. DELETE FROM Persons WHERE FirstName = 'Peter' ; This option is correct. The DELETE command is used to delete records from a table in SQL. The WHERE clause is used to specify the condition that must be met for a record to be deleted. In this case, we want to delete all records where the FirstName is Peter, so we use the WHERE FirstName = 'Peter' condition.

B. DELETE FirstName='Peter' FROM Persons; This option is incorrect. The correct syntax for the DELETE command is DELETE FROM table_name, followed by the WHERE clause. In this option, the syntax is incorrect because the table name is missing, and the condition is in the wrong place.

C. DELETE ROW FirstName='Peter' FROM Persons ; This option is incorrect. The correct syntax for the DELETE command is DELETE FROM table_name, followed by the WHERE clause. In this option, the syntax is incorrect because the ROW keyword is not used in the correct way.

D. TRUNCATE FROM Persons WHERE FirstName='Peter' This option is incorrect. The TRUNCATE command is used to delete all records from a table, not specific records that meet a certain condition. Also, the syntax is incorrect because the WHERE clause is used in the wrong place.

The Answer is: A. DELETE FROM Persons WHERE FirstName = 'Peter' ;