data manipulation language (dml)

13
DATA MANIPULATION LANGUAGE (DML)

Upload: upton-fletcher

Post on 30-Dec-2015

21 views

Category:

Documents


1 download

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 Presentation

TRANSCRIPT

Page 1: DATA MANIPULATION LANGUAGE (DML)

DATA MANIPULATION

LANGUAGE (DML)

Page 2: 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

Page 3: DATA MANIPULATION LANGUAGE (DML)

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", ...)

Page 4: DATA MANIPULATION LANGUAGE (DML)

SQL INSERT STATEMENT

Example

INSERT INTO Employees

VALUES ( ‘05 ’,’Vasquez, Djoanna Marie’)

INSERT INTO Employees (Name)

VALUES (‘Vasquez, Djoanna Marie ’)

Page 5: DATA MANIPULATION LANGUAGE (DML)

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’

Page 6: DATA MANIPULATION LANGUAGE (DML)

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

Page 7: DATA MANIPULATION LANGUAGE (DML)

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

Page 8: DATA MANIPULATION LANGUAGE (DML)

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  

Page 9: DATA MANIPULATION LANGUAGE (DML)

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

Page 10: DATA MANIPULATION LANGUAGE (DML)

EXERCISES

Page 11: DATA MANIPULATION LANGUAGE (DML)

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.

Page 12: DATA MANIPULATION LANGUAGE (DML)

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

Page 13: DATA MANIPULATION LANGUAGE (DML)

GOOD DAY!!!

HOPE YOU HAVE LEARNED

SOMETHING TODAY..