In SQL, which command (s) is (are) used to remove rows from a table.a...
The SQL DELETE command allows you to delete a single record or multiple records from a table. After performing a delete operation, one needs to commit or rollback the transaction to make the change permanent or to undo it.
Option (2) is invalid no such command in SQL by name of “Remove”.
Truncate removes all rows from a table. The operation can’t be rolled back and no trigger will be fired. Truncate is faster and doesn’t use as much undo space as a DELETE.
View all questions of this test
In SQL, which command (s) is (are) used to remove rows from a table.a...
Explanation:
In SQL, the DELETE command is used to remove one or more rows from a table based on specified conditions. The REMOVE command does not exist in SQL and is not used for removing rows from a table. The TRUNCATE command is used to remove all the rows from a table, but it does not allow any conditions to be specified.
Difference between DELETE and TRUNCATE commands:
- The DELETE command is used to remove one or more rows from a table based on specified conditions, while the TRUNCATE command is used to remove all the rows from a table.
- The DELETE command is a DML (Data Manipulation Language) statement, while the TRUNCATE command is a DDL (Data Definition Language) statement.
- The DELETE command can be rolled back (undone) if it is within a transaction, while the TRUNCATE command cannot be rolled back.
Example:
Suppose we have a table named "Employees" with the following data:
| EmployeeID | FirstName | LastName |
|------------|-----------|----------|
| 1 | John | Smith |
| 2 | Jane | Doe |
| 3 | David | Johnson |
To delete a specific row from the table, we can use the DELETE command with a WHERE clause. For example, to delete the row with EmployeeID = 2, we can use the following SQL statement:
```
DELETE FROM Employees
WHERE EmployeeID = 2;
```
After executing this statement, the row with EmployeeID = 2 will be removed from the table.
To remove all the rows from the table, we can use the TRUNCATE command. For example, to remove all the rows from the "Employees" table, we can use the following SQL statement:
```
TRUNCATE TABLE Employees;
```
After executing this statement, all the rows in the "Employees" table will be removed.
Therefore, the correct answer is option 'B' - Remove is not a valid command in SQL for removing rows from a table.
To make sure you are not studying endlessly, EduRev has designed Railways study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Railways.