- Data Definition Language (DDL)
- Data Manipulation Language (DML)
- Integrity
- View defination
- Transaction control
- Embedded SQL & dynamic SQL
- Authorization
- Data Control Language (DCL)
Domain Type (Data type):
SQL supports a variety of built in data types including:
a) Char(n): A fixed length character string with user defined length.
b) Varchar(n): Variable length character string with user defined maximum length.
c) Int: An integer
d) smallint: a small integer.
e) Float(n): A floating point number with precision of at least n digit.
f) Date: Date containing a year, month and day of the month.
g) Time: The time of day, in hrs, minutes and seconds
h) Timestamp: A combination of date and time
1. Data Definition Language (DDL)
It allows you to create, alter or remove different kind database objects such as tables, views, indexes. Some of the DDL commands are as follows:
a) Create database command: creates a new database
For example:
create database DCEIII
b) Drop database command: delete a database
For example:
drop database DCEIII
c) Create table command : creates a new table
For example:
create table student
(
sn int not null,
fname varchar(30),
lname varchar(30),
address varchar(30),
phone varchar(30),
)
d) Drop table command: deletes a table
For example:
drop table stud
e) Alter table command: used to add/drop/modify attribute to an existing table.
For example:
alter table student
add remark varchar(30);
2. Data Manipulation Language (DML)
SQL DML allows you to query and change data from existing database object. Some of the DML commands are as follows:
INSERT INTO - inserts new data into a database
For example:
insert into student(sn,fname,lname,address,phone,remark)
values(1,'Resham','Giri','Dang',9847836990,'teacher')
SELECT statement :
The SELECT statement is used to select data from a database.
For example:
SELECT fname,phone
FROM student
and
select * from student
UPDATE - updates records in a database
update student set
address='Pyuthan' where sn=1
DELETE - deletes records from a database
delete from student
where sn=2
3. Data Control Language (DCL)
It is used to control the kind of data access to the database and transaction control.
Grant, revoke are used for data access control.
Commit, rollback and save point are transaction control command.
Grouping by clause
SQL Constraints:
Data Integrity:
Basic Structure of an SQL
Benefits of SQL
- It is simple, flexible and powerful.
- It can process more than one record at a time.
- We can do various operations using it, like querying data, creating and updating tables and inserting and deleting rows
- Program written is SQL are portable. They can be easily transferred from one database system to another.
- · All popular RDBMS support SQL.