250 likes | 564 Views
DATA MANIPULATION LANGUAGE (DML). DATA MANIPULATION. There are the standard Data Manipulation Language (DML) elements. DML is the subset of the language used to add, update and delete data: INSERT DELETE UPDATE. INSERT.
E N D
DATA MANIPULATION • There are the standard Data Manipulation Language (DML) elements. • DML is the subset of the language used to add, update and delete data: • INSERT • DELETE • UPDATE
INSERT • INSERT is used to add rows (formally tuples) to an existing table, for example: SYNTAX INSERT INTO "table_name" ("column1", "column2", ...)VALUES ("value1", "value2", ...)
SQL INSERT STATEMENT Example INSERT INTO Employees VALUES ( ‘05 ’,’Vasquez, Djoanna Marie’) INSERT INTO Employees (Name) VALUES (‘Vasquez, Djoanna Marie ’)
SQL DELETE STATEMENT • DELETE removes zero or more existing rows from a table DELETE FROM "table_name"WHERE {condition} Example: DELETE FROM Orders Where Product =‘Printer’
DELETE ALL ROWS • It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact: Syntax DELETE FROM table_name Or DELETE * FROM table_name
SQL UPDATE Statement • UPDATE is used to modify the values of a set of existing table rows Syntax UPDATE table_name SET column_name = new_value WHERE column_name = some_value
Person We want to add a first name to the person with a last name of "Rasmussen": UPDATE Person SET FirstName = 'Nina‘ WHERE LastName = 'Rasmussen‘ Result:
Update Several Columns in a Row We want to change the address and add the name of the city: UPDATE PersonSET Address = 'Stien 12', City = 'Stavanger‘ WHERE LastName = 'Rasmussen‘ Result
Exercises • Insert the following records in the Branch table. (B009, 34 Fish Rd, Aberdeen) • Insert the following records in the Properties table.(PG18, 56 Lawrence St, Glasgow, House, 3, 700) • Delete all houses located in Glasgow. • Delete all properties whose number of rooms is greater than 4 • Delete all the records in the Branch table.
6. Delete all staff who was born from 1958 to 1970 7. Change the last name of Mary Howe to Mary White 8. Increase the salary of all employees by 5% 9. Increase the salary of Assistants by 5% 10.Change all properties to houses whose type is flat and located in Glasgow
GOOD DAY!!! HOPE YOU HAVE LEARNED SOMETHING TODAY..