Database Management Systems (2130703)

BE | Semester-3   Summer-2018 | 05/23/2018

Q2) (a)

List and explain DML statements with suitable example.

Different DML statements are

Insert:

  • The INSERT INTO statement is used to insert new records in a table.

Syntax:

INSERT INTO TABLE_NAME
 [(col1, col2, col3,...colN)]
VALUES (value1, value2, value3,...valueN);

OR

INSERT INTO TABLE_NAME
VALUES (value1, value2, value3,...valueN);

Example:

INSERT INTO employee (id, name, dept, age, salary)
VALUES (105, 'Srinath', 'Aeronautics', 27, 33000);

Update:

  • The UPDATE statement is used to update existing records in a table.

Syntax:

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated.

Example:

To update the location of an employee, the sql update query would be,
UPDATE employee
SET location ='Mysore'
WHERE id = 101;

Delete:

  • The SQL DELETE Query is used to delete the existing records from a table. You can use WHERE clause with DELETE query to delete selected rows, otherwise all the records would be deleted.

Syntax:

DELETE FROM table_name
 [WHERE condition];
VALUES (value1, value2, value3,...valueN);

Example:

To delete an employee with id 100 from the employee table, the sql delete query would be
DELETE FROM employee
WHERE id = 100;
To delete all the rows from the employee table, the query would be,
 DELETE FROM employee;