0% found this document useful (0 votes)
20 views

SQL Basics

Uploaded by

Vikram Divakar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

SQL Basics

Uploaded by

Vikram Divakar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

SQL

Institute of Aeronautical Engineering

• What is SQL?
• Why Use SQL?
• Brief History of SQL
• Types of SQL
• What is DDL?
• What is DML?
• What is DCL? DON’T WRITE
• What is TCL?
OR PLACE ANY
• What is DQL?
IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
What is SQL?

• SQL(Structured Query Language) is a database language


designed for the retrieval and management of data in a relational
database.

• SQL is the standard language for database management. All the


RDBMS systems like MySQL, MS Access, Oracle, Sybase,
Postgres, and SQL Server use SQL as their standard database
language.

DON’T WRITE
OR PLACE ANY
IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering

Why use SQL


• It helps users to access data in the RDBMS system.

• It helps you to describe the data.

• It allows you to define the data in a database and manipulate that


specific data.

• With the help of SQL, you can create and drop databases and
tables.
DON’T WRITE
• SQL offers you to use the function in a database, create a view OR PLACE ANY
and stored procedure.
IMAGE IN THIS
• You can set permissions on tables, procedures, and views.
AREA.
.
.
SQL
Institute of Aeronautical Engineering
Brief 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 (American National Standards Institue)
• 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. DON’T WRITE
• SQL2006- Support for XML Query Language OR PLACE ANY
• SQL2011-improved support for temporal databases IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
Types of SQL

Here are five types of widely used SQL queries.

• Data Definition Language (DDL)

• Data Manipulation Language (DML)

• Data Control Language(DCL)


DON’T WRITE
• Transaction Control Language(TCL) OR PLACE ANY
IMAGE IN THIS
• Data Query Language (DQL)
AREA.
.
.
SQL
Institute of Aeronautical Engineering
SQL Commands

DON’T WRITE
OR PLACE ANY
IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
What is DDL?

Data Definition Language helps you to define the database structure or schema.

Five types of DDL commands are:


1) CREATE

CREATE statements is used to define the database structure schema:


Syntax:

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


DON’T WRITE
For example:
OR PLACE ANY
Create database university;
Create table students;
IMAGE IN THIS
Create view for_students; AREA.
.
.
SQL
Institute of Aeronautical Engineering
DDL-Drop

2) DROP

Drop command remove tables and databases from RDBMS.

Syntax
DROP TABLE ;

For example:
Drop object_type object_name;
DON’T WRITE
Drop database university;
OR PLACE ANY
Drop table student;
IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
DDL-Alter

3) ALTER
Alter 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;


DON’T WRITE
To modify an existing column in the table:
OR PLACE ANY
ALTER TABLE MODIFY(COLUMN DEFINITION....);
IMAGE IN THIS
Alter table Student Add subject varchar; AREA.
.
.
SQL
Institute of Aeronautical Engineering
DDL-Truncate

4) 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;
DON’T WRITE
OR PLACE ANY
IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
DDL-Rename
5) Rename
SQL Server does not have any statement that directly renames a table.
However, it does provide you with a stored procedure named sp_rename
that allows you to change the name of a table.

The following shows the syntax of using the sp_rename stored procedure for
changing the name of a table:

EXEC sp_rename 'old_table_name', 'new_table_name'


Note that both the old and new name of the table whose name is being changed
must be enclosed in single quotations. DON’T WRITE
OR PLACE ANY
IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
What is DML?
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:

Here are three important DML commands:


• INSERT DON’T WRITE
• UPDATE OR PLACE ANY
• DELETE IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
DML-Insert

INSERT:
This is a Insert statement and 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
DON’T WRITE
VALUES (value1, value2, value3, .... valueN);
OR PLACE ANY
For example: IMAGE IN THIS
INSERT INTO students (RollNo, FIrstName, LastName) VALUES ('60', 'Tom', AREA.
Erichsen'); .
.
SQL
Institute of Aeronautical Engineering
DML-Update

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:
DON’T WRITE
UPDATE students
SET FirstName = ‘John', LastName= 'Wick'
OR PLACE ANY
WHERE StudID = 3; IMAGE IN THIS
AREA.
.
.
Institute of Aeronautical
SQL Engineering
DML-Delete

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 = ‘John';
DON’T WRITE
OR PLACE ANY
IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
What is DCL?

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

Examples of DCL commands:

Commands that come under DCL:


• Grant
• Revoke
DON’T WRITE
OR PLACE ANY
IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
DCL-Grant & Revoke
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 take back permissions from the user. DON’T WRITE


Syntax: OR PLACE ANY
REVOKE privilege_name ON object_nameFROM {user_name |PUBLIC |role_name} IMAGE IN THIS
For example: AREA.
REVOKE SELECT, UPDATE ON student FROM BCA, MCA;
.
.
SQL
Institute of Aeronautical Engineering
What is TCL?

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

Commit
This command is used to save all the transactions to the database.

Syntax:
Commit;

DON’T WRITE
For example:
DELETE FROM Students
OR PLACE ANY
WHERE RollNo =25; IMAGE IN THIS
COMMIT; AREA.
.
.
SQL
Institute of Aeronautical Engineering
TCL-Rollback & SavePoint
Rollback
Rollback command allows you to undo transactions that have not already been
saved to the database.
Syntax:
ROLLBACK;
Example:
DELETE FROM Students WHERE RollNo =25;

SAVEPOINT

DON’T WRITE
This command helps you to sets a savepoint within a transaction.
Syntax:
OR PLACE ANY
SAVEPOINT SAVEPOINT_NAME; IMAGE IN THIS
Example: AREA.
SAVEPOINT RollNo; .
.
SQL
Institute of Aeronautical Engineering
What is DQL?

Data Query Language (DQL) is used to fetch the data from the database. It
uses only one command:

SELECT:
This command helps you to select the attribute based on the condition described
by the WHERE clause.
Syntax:
SELECT expressions FROM TABLES WHERE conditions;
For example:
SELECT FirstName FROM Student WHERE RollNo > 15; DON’T WRITE
OR PLACE ANY
IMAGE IN THIS
AREA.
.
.
SQL
Institute of Aeronautical Engineering
Summary
• SQL is a database language designed for the retrieval and management of
data in a relational database.
• It helps users to access data in the RDBMS system
• In the year 1974, the term Structured Query Language appeared
• Five types of SQL queries are 1) Data Definition Language (DDL) 2) Data
Manipulation Language (DML) 3) Data Control Language(DCL) 4)
Transaction Control Language(TCL) and, 5) Data Query Language (DQL)
• Data Definition Language(DDL) helps you to define the database structure
or schema.
• Data Manipulation Language (DML) allows you to modify the database
instance by inserting, modifying, and deleting its data. DON’T WRITE
• DCL (Data Control Language) includes commands like GRANT and OR PLACE ANY
REVOKE, which are useful to give "rights & permissions."
IMAGE IN THIS
• Transaction control language or TCL commands deal with the transaction
within the database. AREA.
• Data Query Language (DQL) is used to fetch the data from the database. .
.

You might also like