Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Structured Query Language (SQL)

SQL (Structured Query Language) is used to perform operations on the records


stored in the database, such as updating records, inserting records, deleting
records, creating and modifying database tables, views, etc.
SQL is not a database system, but it is a query language.
This database language is mainly designed for maintaining the data in
relational database management systems. It is a special tool used by data
professionals for handling structured data (data which is stored in the form of
tables). 

Data Definition Language (DDL)


In the context of SQL, data definition or data description language (DDL) is a
syntax for creating and modifying database objects such as tables, indices, and
users. DDL statements are similar to a computer programming language for
defining data structures, especially database schemas. Common examples of
DDL statements include  CREATE ,  ALTER , and  DROP .

Commands:
CREATE
Example:
CREATE TABLE Students
(
ROLL_NO int(3),
NAME varchar(20),
SUBJECT varchar(20),
);

ALTER
For example, the command to add (then remove) a column named bubbles for
an existing table named sink is:

ALTER TABLE sink ADD bubbles INTEGER;

DROP
DROP TABLE table_name;
table_name: Name of the table to be deleted.
Data Manipulation Language (DML)
A data manipulation language (DML) is a computer programming
language used for adding (inserting), deleting, and modifying (updating) data in
a database. A DML is often a sublanguage of a broader database language such
as SQL, with the DML comprising some of the operators in the language. Read-
only selecting of data is sometimes distinguished as being part of a
separate data query language (DQL), but it is closely related and sometimes
also considered a component of a DML; some operators may perform both
selecting (reading) and writing.
Commands:
INSERT
INSERT INTO table_name VALUES (value1, value2, value3,…);
INSERT INTO Student VALUES (‘5′,’HARSH’,’WEST BENGAL’,’XXXXXXXXXX’,’19’);

UPDATE
UPDATE Student SET NAME = 'PRATIK' WHERE Age = 20;

DELETE
DELETE FROM Student WHERE NAME = 'Ram';

/* Create a table called NAMES */


CREATE TABLE Employee(Emp_Id integer PRIMARY KEY,
Name Varchar(20),
Department varchar(10),
Salary decimal(10,2),
Experience integer(2),
DOJ Date );

Create table Leave(


Emp_Id integer,
leave integer );
/* Create few records in this table */
INSERT INTO Employee VALUES('001','Ahmed Hussain','Accts','15000','3','2-jan-
05');
INSERT INTO Employee VALUES('002','Ravinder Singh','System','35000','5','12-
feb-08');
INSERT INTO Employee VALUES('003','Jully Bhatt','System','20000','5','15-jan-
09');
INSERT INTO Employee VALUES('004','Shiva Mathur','Accts','15000','7','12-jul-
09');
INSERT INTO Employee VALUES('005','Sonia Jolly','Accts','12000','3','1-dec-06');
INSERT INTO Employee VALUES('006','Sumita Singh','Purchase','18000','10','12-
nov-04');

INSERT INTO Leave VALUES('001','3');


INSERT INTO Leave VALUES('002','2');
INSERT INTO Leave VALUES('003','4');
INSERT INTO Leave VALUES('004','5');
INSERT INTO Leave VALUES('005','5');
INSERT INTO Leave VALUES('006','1');

SELECT * FROM Employee;


SELECT * FROM Leave;

You might also like