data manipulation language (dml)
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
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
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 OrdersWhere 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:
LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Storgt 67
LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen
Nina Storgt 67
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
LastNameFirstName
Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Nina Stien 12 Stavanger
EXERCISES
Exercises
1. Insert the following records in the Branch table. (B009, 34 Fish Rd, Aberdeen)
2. Insert the following records in the Properties table.(PG18, 56 Lawrence St, Glasgow, House, 3, 700)
3. Delete all houses located in Glasgow.4. Delete all properties whose number of
rooms is greater than 45. 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..