Structure Query Language: by Prof - Manikandan QMC College, Medavakkam
Structure Query Language: by Prof - Manikandan QMC College, Medavakkam
QUERY LANGUAGE
By
Prof.Manikandan
DEFINITION
SQL consist of a set of facilities for defining,
accessing, and managing relational data base.
Very flexible.
Free from syntax.
High level language.
Advantages:
High level language that provides a higher degree of
abstraction than procedural language.
SQL applications are portable.
Provides well defined results.
SQL is not case sensitive
DDL STATEMENTS
1.CREATE :
CREATE TABLE <TABLE NAME> <COLUMN1><DATA TYPE 1>,
<COLUMN2><DATA TYPE 2>..);
EXAMPLE :
CREATE TABLE BCA(NAME VARCHAR2(20),
REG_NUM NUMBER(5),
MARK1 NUMBER(5),
MARK2 NUMBER(5),
MARK3 NUMBER(5),
TOTAL NUMBER(5));
(;
2.ALTER:
ALTER TABLE <BASE TABLE NAME>
ADD/MODIFY<COLUMN1><DATA TYPE 1>,
<COLUMN2><DATA TYPE 2>..);
EXAMPLE :
ALTER TABLE BCA ADD AVG NUMBER(5);
New
To
column added.
3.DROP:
EXAMPLE :
DROP TABLE BCA;
DML STATEMENTS
1.INSERT :
One
row inserted.
2.UPDATE:
UPDATE <BASE TABLE NAME> SET
<COLUMN NAME>=VALUE
WHERE <COLUMN NAME =VALUE);
EXAMPLE :
UPDATE BCA SET NAME='VASU'
WHERE REG_NUM=1001;
Increase
To
3.DELETE:
TCL STATEMENTS
1.COMMIT :
COMMIT
Used
base.
to undo the transaction that have not already been committed to the data
ROLLBACK [WORK];
3.SAVEPOINT:
DCL STATEMENTS
1.GRANT AND REVOKE :
EAMPLE
SELECT*FROM IIIBCA;
2.DEFINITE RETRIEVAL
Display names, reg numbers of students who
have fail either in mark1 or mark2.
SELECT NAME, REGNUM FROM IIIBCA
WHERE MARK1<30 OR MARK2<30;
4.SELECT USING IN
If we want to get the rows which contains certain
values, use the IN conditional expression.
SELECT NAME FROM IIIBCA WHERE AVG IN(65,35);
AVG()
: Average
. Find the average total of the students.
SELECT AVG(TOTAL) FROM IIIBCA;
1.