DBMS: Structured Query Language(SQL)


Structure Query Language(SQL) is a database query language used for storing and managing data in Relational DBMS. SQL was the first commercial language introduced for E.F Codd’s Relational model of database. Today almost all RDBMS(MySql, Oracle, Infomix, Sybase, MS Access) use SQL as the standard database query language. SQL is used to perform all types of data operations in RDBMS.

Brief History of SQL

Here, are important landmarks from the history of SQL:

  • 1970 – Dr. Edgar F. “Ted” Codd described a relational model for databases.
  • 1974 – Structured Query Language appeared.
  • 1978 – IBM released a product called System/R.
  • 1986 – IBM developed the prototype of a relational database, which is standardized by ANSI.
  • 1989- First ever version launched of SQL
  • 1999 – SQL 3 launched with features like triggers, object-orientation, etc.
  • SQL2003- window functions, XML-related features, etc.
  • SQL2006- Support for XML Query Language
  • SQL2011-improved support for temporal databases

Types of SQL

Here are five types of widely used SQL queries.

  • Data Definition Language (DDL)
  • Data Manipulation Language (DML)
  • Data Control Language(DCL)
  • Transaction Control Language(TCL)
  • Data Query Language (DQL)
Types of SQL

Let see each of them in detail:

What is DDL?

Data Definition Language helps you to define the database structure or schema. Let’s learn about DDL commands with syntax.

All DDL commands are auto-committed. That means it saves all the changes permanently in the database.

Five types of DDL commands in SQL are:

CommandDescription
createto create new table or database
alterfor alteration
truncatedelete data from table
dropto drop a table
renameto rename a table

CREATE

CREATE statements is used to define the database structure schema:

Syntax:

CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]); 

For example:

Create database university;
Create table students;
Create view for_students;

DROP

Drops commands remove tables and databases from RDBMS.

Syntax

DROP TABLE ;

For example:

Drop object_type object_name;
Drop database university;
Drop table student;

ALTER

Alters command allows you to alter the structure of the database.

Syntax:

To add a new column in the table

ALTER TABLE table_name ADD column_name COLUMN-definition; 

To modify an existing column in the table:

ALTER TABLE MODIFY(COLUMN DEFINITION....);  

For example:

Alter table guru99 add subject varchar; 

TRUNCATE:

This command used to delete all the rows from the table and free the space containing the table.

Syntax:

TRUNCATE TABLE table_name;  

Example:

TRUNCATE table students;

What is Data Manipulation Language?

Data Manipulation Language (DML) allows you to modify the database instance by inserting, modifying, and deleting its data. It is responsible for performing all types of data modification in a database.

There are three basic constructs which allow database program and user to enter data and information are:

DML commands are not auto-committed. It means changes are not permanent to database, they can be rolled back.

CommandDescription
insertto insert a new row
updateto update existing row
deleteto delete a row
mergemerging two rows or two tables

INSERT:

This is a statement is a SQL query. This command is used to insert data into the row of a table.

Syntax:

INSERT INTO TABLE_NAME  (col1, col2, col3,.... col N)  
VALUES (value1, value2, value3, .... valueN);  
Or 
INSERT INTO TABLE_NAME    
VALUES (value1, value2, value3, .... valueN);    

For example:

INSERT INTO students (RollNo, FIrstName, LastName) VALUES ('60', 'Tom', Erichsen');

UPDATE:

This command is used to update or modify the value of a column in the table.

Syntax:

UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [WHERE CONDITION]   

For example:

UPDATE students    
SET FirstName = 'Jhon', LastName= 'Wick' 
WHERE StudID = 3;

DELETE:

This command is used to remove one or more rows from a table.

Syntax:

DELETE FROM table_name [WHERE condition];  

For example:

DELETE FROM students 
WHERE FirstName = 'Jhon';

What is DCL?

DCL (Data Control Language) includes commands like GRANT and REVOKE, which are useful to give “rights & permissions.” Other permission controls parameters of the database system.

CommandDescription
grantgrant permission of right
revoketake back permission.

Grant:

This command is use to give user access privileges to a database.

Syntax:

GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;  

For example:

GRANT SELECT ON Users TO'Tom'@'localhost;

Revoke:

It is useful to back permissions from the user.

Syntax:

REVOKE privilege_nameON object_nameFROM {user_name |PUBLIC |role_name}

For example:

REVOKE SELECT, UPDATE ON student FROM BCA, MCA;  

What is TCL?

Transaction control language or TCL commands deal with the transaction within the database.

CommandDescription
committo permanently save
rollbackto undo change
savepointto save temporarily

DQL: Data Query Language

Data query language is used to fetch data from tables based on conditions that we can easily apply.

CommandDescription
selectretrieve records from one or more table

Like it? Share with your friends!

What's Your Reaction?

hate hate
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win
Choose A Format
Personality quiz
Series of questions that intends to reveal something about the personality
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Poll
Voting to make decisions or determine opinions
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Countdown
The Classic Internet Countdowns
Open List
Submit your own item and vote up for the best submission
Ranked List
Upvote or downvote to decide the best list item
Meme
Upload your own images to make custom memes
Video
Youtube and Vimeo Embeds
Audio
Soundcloud or Mixcloud Embeds
Image
Photo or GIF
Gif
GIF format