0% found this document useful (0 votes)
8 views2 pages

Lab 2

لابات داتا بيس
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Lab 2

لابات داتا بيس
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab #2

DML Statements(On One Table)

1. Inserting New Rows

It is possible to write insert into statements in two ways:

1- specifies both the column names and the values to be inserted:

INSERT INTO <tablename> [<column list>]


VALUES (<expression>{[,<expression>]})

2- if you are adding all values to all columns, you don’t need to spcify column names

INSERT INTO <tablename>


VALUES (value1,value2,…..)
Hint: you should make sure the order of the values is in the same order as
the columns in the table.

Example 1:

❖ Insert new student into the student table with the following properties:
Student id=1 , Name= Ali, Age=19, and City= ‘Cairo’

INSERT INTO Student VALUES (2,’Wafaa',19,'Cairo',null,null)

INSERT INTO Student (SSN,Name,Age,City) VALUES (1,'Ali',19,'Cairo')

///////////////////////////////////////////////////////////////////////////////////

2. Updating Values in Rows

UPDATE <tablename>
SET <column name>=<expression>,<column name>=<expression>
[WHERE <Condition>]

Example 1:

❖ Increase the age of students by 1

update Student
set age=age+1

Example 2: (Using Where Clause)

❖ Change the name of the STudent with SSN 1 to be ‘AHMED’

update Student
set name='ahmed'
where SSN=1
Eng-Abdallah Hamed lab-2 Database
Example 3: (Update more than one cloumn with a condition)

❖ Change the name of the STAFF with id 1 back to ‘ALI’ and let his age be 18

update Student
set name='Ali',
age=18
where SSN=1

3. Deleting rows from a table

DELETE
FROM <table name>
[WHERE <Condition>]

Example 1:

❖ Delete all rows of table Student (Don’t try it)

delete from Student

Example 2:

❖ Delete the Student with id 2

delete from Student


where SSN=2

Example 3: (Using more than one condition)

❖ Delete the STudent that has an id 1 or 2

delete from Student


where SSN=2 or
SSN=1

BETTER STATEMENT THAT DOES THE SAME JOB OF THE PREVIOUS ONE :

delete from Student


where SSN IN (1,2);

Eng-Abdallah Hamed lab-2 Database

You might also like