DBMS Module 3 PPT
DBMS Module 3 PPT
• SQL allows users to query the database in a number of ways, using English-
like statements
Save
Drop Update
point
Truncate Delete
Rename
• SQL statements are not case sensitive. Generally, keywords of SQL are written
in uppercase.
LONG
Varchar2(size) Char(size) Number(p,s) Date
•RENAME old_table_name to
Syntax
new_table_name;
select name, marks from student where marks not between 70 and 90;
select name, address from student where id>=1 and name like ‘%E%’;
• Specific row or rows are modified if you specify the WHERE clause.
update student set address=“Mumbai” where rno=5;
• All rows in the table are modified if you omit the WHERE clause.
update student set address=“Mumbai”;
4/21/2022 DBMS : III : Introduction to Structured Query Language 25
DML Commands (Cont…) Delete
We can remove existing rows by using the DELETE statement.
delete from table where condition;
All rows in the table are deleted if you omit the where clause.
delete from student;
• Grant
Syntax:grant privileges to user;
Example: grant create, select to admin;
• Revoke
revoke select on student from admin;
• FOREIGN KEY : Defines the column in the child table at the table constraint level.
• REFERENCES : Identifies the table and column in the parent table.
• ON DELETE CASCADE : Deletes the dependent rows in the child table when a row in the
parent table is deleted.
4/21/2022 DBMS : III : Introduction to Structured Query Language 38
Constraints – CHECK
• Defines a condition that each row must satisfy.
create table branch (
branch_name varchar(20),
branch_city varchar(20),
assets integer,
primary key (branchname),
check (bcity in ‘Pune’,’Mumbai’)
check (assets > 0));
select avg(salary)
from departments
group by department_id;
• All columns in the SELECT list that are not in group functions must be in the GROUP BY clause.
SELECT AVG(salary)
FROM employees
GROUP BY department_id;
4/21/2022 DBMS : III : Introduction to Structured Query Language 49
Having Clause
• Rows are grouped
• The group function is applied
• Group matching the HAVING clause are displayed.
• If you include group function in a select clause you can not select
individual results unless the individual columns appears in group by
clause.
• Any column or expression in the select list that is not an aggregate
function must be in group by clause.
• Can’t use column alias in this clause.