Class XII Database
Class XII Database
Why database?
Sql:
Sql commands is divided into 4 parts:
1. DDL:(Data Definition Language)
Create, alter, drop, rename, truncate.
** It works on table structure not the table
data.
2. DML:(Data Manipulation Language)
Select,insert, update,delete
** It works on table data rather than table
structure.
3. TCL: (Transaction control language)
Commit, rollback, savepoint
4. DCL:(Data Control Language):
Grant, revoke
6/5
10/5
UPDATE COMMAND:
Update emp set salary=salary+2000 ;
Update emp set salary=salary+2000 where empid=101;
Alter Command:
Alter with Add: to add column PH in the table
Alter table emp ADD (PH int(10));
Alter with modify : it will modify the given datatype,its
size,constraint etc.
Alter table emp Modify empname varchar(15);
Select command:
1)Select * from emp; (it will display whole records of the
table)
2)Select * from emp where empid=102;(it will display all
data of empid 102)
3) operator:
a) Between: give the records based on certain ranges.
b) like: pattern matching
c) in: It works on range of values
not in: just opposite of IN
c) not null
between:
Q. Fetch the records of those employee whose salary
ranges between 10000 and 50000;
Select * from emp where salary between 10000 and 50000;
Note: both ranges included
IN:
Q. Display the records of those employee who either
belongs to dept no 10 or 20
Ans: Select * from emp where dept IN(10,20);
Not IN is just opposite to IN operator
Or
Select * from emp where dept = 10 or dept=20;
NOT NULL
Q: Display the details of those employee whose dept is not
null.
Ans: Select * from emp where dept is NOT NULL;
NULL
Select * from emp where dept is NULL;
12/5
AGGREGATE FUNCTION: ONLY WORK FOR THE GROUP OF
VALUES
1. MAX()
2. MIN()
3. SUM()
4. COUNT()
5. AVG()
13/5
OPERATOR:
ARITHMETIC OPERATOR: + , - ,*,/
RELATIONAL OPERATOR: >,<,>=,<=
LOGICAL OPERATOR: AND, OR, NOT
ORDER BY CLAUSE:- To Arrange the data either in
ascending or descending (by default: ascending(asc)
For descending we have to use desc command along with
order by).
Q: arrange the records in ascending order of dept.
Select * from emp order by dept asc;
Q: arrange the records in descending order of dept.
Select * from emp order by dept desc;