illustrate insert, delete, alter, drop, and update statements in SQL with examples

illustrate insert, delete, alter, drop and update statements in SQL with examples

Answer:

SQL statements for INSERT, DELETE, ALTER, DROP, and UPDATE operations:

  1. 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);
  1. DELETE: Used to delete records from a table based on a condition. Example:
   DELETE FROM employees
   WHERE employee_id = 1;
  1. ALTER: Used to modify a table structure, such as adding a new column. Example:
   ALTER TABLE employees
   ADD COLUMN email VARCHAR(255);
  1. 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;
  1. UPDATE: Used to update existing records in a table based on a condition. Example:
   UPDATE employees
   SET department_id = 102
   WHERE employee_id = 1;

Leave a Reply

Your email address will not be published. Required fields are marked *