DB-2 Update & Delete Records
DB-2 Update & Delete Records
Dr.Amgad Monir
Contents
• UPDATE
• DELETE
• BASIC QUERIES
Create table with contents
CREATE TABLE student (
student_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(40) NOT NULL,
major VARCHAR(40) DEFAULT 'undecided'
);
UPDATE student
SET major = 'Bio'
WHERE major = 'Biology';
UPDATE student
SET major = 'Engineer'
UPDATE student
SET major = 'System Analyst'
WHERE student_id = 1;
UPDATE student
SET major = 'Practical Science'
WHERE major="Engineer" OR major="System Analyst";
UPDATE student
SET name="khaled", major="programmer"
WHERE student_id=4;
select *
from student
ORDER BY major,name;
LIMIT
select *
select * from student
from student ORDER BY student_id DESC
LIMIT 2; LIMIT 2;
Where
select name,major
select * select name,major
from student
from student from student
where major="programmer" OR
where major="programmer"; where major="programmer";
major="Biology";
Where
select *
from student
where student_id <3 and name <> "jack";
Where
select *
from student
where name in ("Jack","Ahmed") ;
Where
select *
from student
where name in("Jack","ahmed") and student_id > 3;