illustrate insert, delete, alter, drop and update statements in SQL with examples
Answer:
SQL statements for INSERT
, DELETE
, ALTER
, DROP
, and UPDATE
operations:
- INSERT: Used to insert new records into a table. Example:
INSERT INTO employees (employee_id, first_name, last_name, department_id) VALUES (1, 'John', 'Doe', 101);
- DELETE: Used to delete records from a table based on a condition. Example:
DELETE FROM employees WHERE employee_id = 1;
- ALTER: Used to modify a table structure, such as adding a new column. Example:
ALTER TABLE employees ADD COLUMN email VARCHAR(255);
- DROP: Used to delete a table or a column from a table. Example (Drop a table):
DROP TABLE employees;
Example (Drop a column):
ALTER TABLE employees DROP COLUMN email;
- UPDATE: Used to update existing records in a table based on a condition. Example:
UPDATE employees SET department_id = 102 WHERE employee_id = 1;