SlideShare a Scribd company logo
Structured Query Language
Introduction
The Structured Query Language (SQL) is a non-procedural programming
language used for storing, manipulatingand retrieving the data in a databases.
SQL was the first commercial language introduced for E.F
Codd's Relational model.
Data Definition Language
It is used to define the structure of tables in the database.
CREATE, ALTER, USE, DROP, TRUNCATE COMMAND
Data Manipulation Language
It is used for managing data in database.
SELECT, UPDATE, DELETE, INSERT COMMAND
Data Control Language
It is used to control user access in a database.
GRANT, REVOKE COMMAND
Grant: Gives user access privileges to database.
Revoke: Take back permissions from user.
It is used to manage transactions in database.
COMMIT, ROLLBACK, SAVEPOINT COMMAND
The COMMIT command is the transactional command used to save changes
invoked by a transaction to the database.
The ROLLBACK command is the transactional command used to undo
transactions that have not already been saved to the database.
The SAVEPOINT command is used to temporarily save a transaction so that
you can rollback to that point whenever necessary.
SQL – CREATE DATABASE:
Syntax:
SQL> CREATE DATABASE database_name;
Example:
SQL> CREATE DATABASE STUDENT_DB;
SQL> SHOW DATABASES;
SQL – SELECT DATABASE:
The SQL USE statement is used to select any existing database in the SQL
schema.
SQL> USE database_name;
SQL – DROP DATABASE:
This statement is used to drop an existing SQL Database.
Syntax:
SQL> DROP DATABASE database_name;
Example:
SQL> DROP DATABASE STUDENT_DB;
SQL – CREATE TABLE:
Syntax:
SQL> CREATE TABLE table_name(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size)
);
Example:
SQL> CREATE TABLE student(
Student_ID int,
Student_namevarchar (255),
City varchar (255),
Marks int
);
SQL – ALTER TABLE:
TO ADD COLUMN
Syntax:
ALTER TABLE table_name ADDcolumn_name datatype;
TO DROP COLUMN
Syntax:
ALTER TABLE table_name DROP COLUMNcolumn_name;
TO ADD NOT NULL
Syntax:
ALTER TABLE table_name MODIFYcolumn_name datatype NOT NULL;
TO ADD PRIMARY KEY
Syntax:
ALTER TABLE table_name ADDPRIMARYKEY(column);
How to check whether a table exists & the property or description of a table?
Syntax:
SQL> DESC table_name;
Example:
SQL> DESC student;
SQL – DROP TABLE:
This statementis used to drop an existing table in database.
SQL DROP statement is used to delete or remove indexes from a table in the
database.
Syntax:
SQL> DROP TABLE table_name;
Example:
SQL> DROP TABLE student;
SQL – TRUNCATE TABLE:
The SQL TRUNCATE TABLE command is used to delete complete data from an
existing table.
You can also use DROP TABLE command to delete complete table but it would
remove complete table structure from the database and you would need to re-
create this table once again if you wish you store some data.
Syntax:
TRUNCATE TABLE table_name;
SQL – SELECT TABLE:
This statementis used to select data from a database.
Syntax:
SELECT column-name1,column-name2,column-name(s)from table_name;
Example:
SELECT studentid,studentnamefrom student;
A special character asterisk * is used to address all the data (belonging to all
columns) in a query.
Syntax:
SELECT * from table_name;
Example:
SELECT * from student;
SQL – INSERT TABLE:
Syntax:
INSERT INTO table_name (column-names)
VALUES (values);
SQL – DELETE TABLE:
Syntax:
DELETE FROM table_name
WHERE [condition];
The statement SQL DELETE ALL ROWS is used to delete all rows from the
table.
Syntax:
DELETE FROM table_name;
SQL – UPDATE TABLE:
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];
CONSTRAINT
NOT NULL CONSTRAINT
Syntax:
CREATE TABLE table_name(
column_name1 data_type(size) NOT NULL,
column_name2 data_type(size) NOT NULL,
column_name3 data_type(size)
);
PRIMARY KEY CONSTRAINT
Syntax:
CREATE TABLE table_name(
column_name1 data_type(size) PRIMARY KEY,
column_name2 data_type(size) NOT NULL,
column_name3 data_type(size)
);
UNIQUE CONSTRAINT
Syntax:
CREATE TABLE table_name(
column_name1 data_type(size) NOT NULL UNIQUE,
column_name2 data_type(size) NOT NULL,
column_name3 data_type(size)
);
CHECK CONSTRAINT
Syntax:
CREATE TABLE table_name(
column_name1 INTEGER AUTOINCREMENT,
column_name2 data_type(size),
column_name3 data_type(size) DEFAULT value,
CHECK column_name1 condition
);
DEFAULT CONSTRAINT
Syntax:
CREATE TABLE table_name(
column_name1 INTEGER AUTOINCREMENT,
column_name2 data_type(size),
column_name3 data_type(size) DEFAULT value
);
CLAUSE
WHERE CLAUSE
Syntax:
SELECT column_name1, column_name2
FROM table_name
WHERE [condition];
ORDER BY CLAUSE
Syntax;
SELECT column_name1, column_name2
FROM table_name
ORDER BY column_name1,
column_name2, ASC;
SELECT column_name1,
column_name2
FROM table_name
ORDER BY column_name1,
column_name2, DESC;
GROUP BY CLAUSE
Syntax;
SELECT column_name, function (column_name)
FROM table_name
WHERE condition
GROUP BY column_name;
LIKE CLAUSE
Syntax:
SELECT column_name1, column_name2
FROM table_name
WHERE column_name1 LIKE ‘A%’;
Syntax:
SELECT column_name1, column_name2
FROM table_name
WHERE column_name1 LIKE ‘A_’;
AND/OR OPERATOR
Syntax:
SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] AND [condition2]...AND [conditionN];
SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] OR [condition2]...OR [conditionN];

More Related Content

What's hot (20)

PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
PPTX
Oracle Database DML DDL and TCL
Abdul Rehman
 
PPTX
Database Management - Lecture 2 - SQL select, insert, update and delete
Al-Mamun Sarkar
 
PPTX
Avinash database
avibmas
 
PPTX
8. sql
khoahuy82
 
PDF
Sql commands
Mohd Tousif
 
PPTX
SQL(DDL & DML)
Sharad Dubey
 
PPT
SQL DDL
Vikas Gupta
 
PPTX
Null values, insert, delete and update in database
Hemant Suthar
 
DOCX
Ddl commands
Vasudeva Rao
 
PDF
Database Systems - SQL - DDL Statements (Chapter 3/2)
Vidyasagar Mundroy
 
PPTX
Sql basics
Aman Lalpuria
 
PPTX
Oracle SQL DML Statements
A Data Guru
 
PPT
Sql DML
Vikas Gupta
 
PPTX
Creating database using sql commands
Belle Wx
 
PPTX
DDL,DML,SQL Functions and Joins
Ashwin Dinoriya
 
PPTX
Commands of DML in SQL
Ashish Gaurkhede
 
PPTX
SQL - DML and DDL Commands
Shrija Madhu
 
PDF
Nested Queries Lecture
Felipe Costa
 
ODP
Sql commands
Balakumaran Arunachalam
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Oracle Database DML DDL and TCL
Abdul Rehman
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Al-Mamun Sarkar
 
Avinash database
avibmas
 
8. sql
khoahuy82
 
Sql commands
Mohd Tousif
 
SQL(DDL & DML)
Sharad Dubey
 
SQL DDL
Vikas Gupta
 
Null values, insert, delete and update in database
Hemant Suthar
 
Ddl commands
Vasudeva Rao
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Vidyasagar Mundroy
 
Sql basics
Aman Lalpuria
 
Oracle SQL DML Statements
A Data Guru
 
Sql DML
Vikas Gupta
 
Creating database using sql commands
Belle Wx
 
DDL,DML,SQL Functions and Joins
Ashwin Dinoriya
 
Commands of DML in SQL
Ashish Gaurkhede
 
SQL - DML and DDL Commands
Shrija Madhu
 
Nested Queries Lecture
Felipe Costa
 

Similar to COMPUTERS SQL (20)

PPT
SQL. It education ppt for reference sql process coding
aditipandey498628
 
DOCX
SQL Tutorial for BCA-2
Raj vardhan
 
PPTX
SQL.pptx for the begineers and good know
PavithSingh
 
PDF
Sql smart reference_by_prasad
paddu123
 
PDF
Sql smart reference_by_prasad
paddu123
 
PPTX
Sql basic things
Nishil Jain
 
PPTX
SQl data base management and design
franckelsania20
 
PPTX
SQL: Data Definition Language(DDL) command
sonali sonavane
 
PPTX
sql.pptx
slavskrillex
 
PPTX
SQL ppt.pptx
fa4185561
 
DOCX
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
PDF
SQL Fundamentals - Lecture 2
MuhammadWaheed44
 
PPTX
SQL
Mohamed Essam
 
PDF
Introduction to SQL..pdf
mayurisonawane29
 
PPTX
SQL
Shyam Khant
 
PDF
STRUCTURED QUERY LANGUAGE
SarithaDhanapal
 
PPTX
Its about a sql topic for basic structured query language
IMsKanchanaI
 
PDF
Dms 22319 micro project
ARVIND SARDAR
 
PDF
Chapter Five - Relational Query Languages.pdf
Eyob Seyfu
 
PPTX
Relational Database Language.pptx
Sheethal Aji Mani
 
SQL. It education ppt for reference sql process coding
aditipandey498628
 
SQL Tutorial for BCA-2
Raj vardhan
 
SQL.pptx for the begineers and good know
PavithSingh
 
Sql smart reference_by_prasad
paddu123
 
Sql smart reference_by_prasad
paddu123
 
Sql basic things
Nishil Jain
 
SQl data base management and design
franckelsania20
 
SQL: Data Definition Language(DDL) command
sonali sonavane
 
sql.pptx
slavskrillex
 
SQL ppt.pptx
fa4185561
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
SQL Fundamentals - Lecture 2
MuhammadWaheed44
 
Introduction to SQL..pdf
mayurisonawane29
 
STRUCTURED QUERY LANGUAGE
SarithaDhanapal
 
Its about a sql topic for basic structured query language
IMsKanchanaI
 
Dms 22319 micro project
ARVIND SARDAR
 
Chapter Five - Relational Query Languages.pdf
Eyob Seyfu
 
Relational Database Language.pptx
Sheethal Aji Mani
 
Ad

More from Rc Os (20)

PPT
Dove
Rc Os
 
PPT
CLASS IV ENGLISH
Rc Os
 
PPT
CLASS 4 MATHS
Rc Os
 
PPT
CLASS 4 MATHS
Rc Os
 
PPT
CLASS III MATHS
Rc Os
 
PPT
CLASS III MATHS
Rc Os
 
PPT
Changing times.
Rc Os
 
PPT
3 class english
Rc Os
 
PPT
Clss ii english-the mouse---
Rc Os
 
PPT
Rainbow
Rc Os
 
PPT
NUMBERS 1 TO 20
Rc Os
 
PPT
TIME
Rc Os
 
PPT
MEASUREMENTS
Rc Os
 
PPT
DATA HANDLING
Rc Os
 
PPT
patterns
Rc Os
 
PPT
Who is heavier
Rc Os
 
PPT
Sundari
Rc Os
 
PPTX
The tiger and the mosquitoe
Rc Os
 
DOCX
Photoshop
Rc Os
 
DOCX
COMPUTERS Database
Rc Os
 
Dove
Rc Os
 
CLASS IV ENGLISH
Rc Os
 
CLASS 4 MATHS
Rc Os
 
CLASS 4 MATHS
Rc Os
 
CLASS III MATHS
Rc Os
 
CLASS III MATHS
Rc Os
 
Changing times.
Rc Os
 
3 class english
Rc Os
 
Clss ii english-the mouse---
Rc Os
 
Rainbow
Rc Os
 
NUMBERS 1 TO 20
Rc Os
 
TIME
Rc Os
 
MEASUREMENTS
Rc Os
 
DATA HANDLING
Rc Os
 
patterns
Rc Os
 
Who is heavier
Rc Os
 
Sundari
Rc Os
 
The tiger and the mosquitoe
Rc Os
 
Photoshop
Rc Os
 
COMPUTERS Database
Rc Os
 
Ad

Recently uploaded (20)

PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 

COMPUTERS SQL

  • 1. Structured Query Language Introduction The Structured Query Language (SQL) is a non-procedural programming language used for storing, manipulatingand retrieving the data in a databases. SQL was the first commercial language introduced for E.F Codd's Relational model. Data Definition Language It is used to define the structure of tables in the database. CREATE, ALTER, USE, DROP, TRUNCATE COMMAND Data Manipulation Language It is used for managing data in database. SELECT, UPDATE, DELETE, INSERT COMMAND Data Control Language It is used to control user access in a database. GRANT, REVOKE COMMAND Grant: Gives user access privileges to database. Revoke: Take back permissions from user. It is used to manage transactions in database. COMMIT, ROLLBACK, SAVEPOINT COMMAND The COMMIT command is the transactional command used to save changes invoked by a transaction to the database. The ROLLBACK command is the transactional command used to undo transactions that have not already been saved to the database. The SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that point whenever necessary. SQL – CREATE DATABASE: Syntax: SQL> CREATE DATABASE database_name; Example: SQL> CREATE DATABASE STUDENT_DB; SQL> SHOW DATABASES;
  • 2. SQL – SELECT DATABASE: The SQL USE statement is used to select any existing database in the SQL schema. SQL> USE database_name; SQL – DROP DATABASE: This statement is used to drop an existing SQL Database. Syntax: SQL> DROP DATABASE database_name; Example: SQL> DROP DATABASE STUDENT_DB; SQL – CREATE TABLE: Syntax: SQL> CREATE TABLE table_name( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size) ); Example: SQL> CREATE TABLE student( Student_ID int, Student_namevarchar (255), City varchar (255), Marks int ); SQL – ALTER TABLE: TO ADD COLUMN Syntax: ALTER TABLE table_name ADDcolumn_name datatype; TO DROP COLUMN
  • 3. Syntax: ALTER TABLE table_name DROP COLUMNcolumn_name; TO ADD NOT NULL Syntax: ALTER TABLE table_name MODIFYcolumn_name datatype NOT NULL; TO ADD PRIMARY KEY Syntax: ALTER TABLE table_name ADDPRIMARYKEY(column); How to check whether a table exists & the property or description of a table? Syntax: SQL> DESC table_name; Example: SQL> DESC student; SQL – DROP TABLE: This statementis used to drop an existing table in database. SQL DROP statement is used to delete or remove indexes from a table in the database. Syntax: SQL> DROP TABLE table_name; Example: SQL> DROP TABLE student; SQL – TRUNCATE TABLE: The SQL TRUNCATE TABLE command is used to delete complete data from an existing table. You can also use DROP TABLE command to delete complete table but it would remove complete table structure from the database and you would need to re- create this table once again if you wish you store some data. Syntax: TRUNCATE TABLE table_name; SQL – SELECT TABLE: This statementis used to select data from a database. Syntax: SELECT column-name1,column-name2,column-name(s)from table_name; Example:
  • 4. SELECT studentid,studentnamefrom student; A special character asterisk * is used to address all the data (belonging to all columns) in a query. Syntax: SELECT * from table_name; Example: SELECT * from student; SQL – INSERT TABLE: Syntax: INSERT INTO table_name (column-names) VALUES (values); SQL – DELETE TABLE: Syntax: DELETE FROM table_name WHERE [condition]; The statement SQL DELETE ALL ROWS is used to delete all rows from the table. Syntax: DELETE FROM table_name; SQL – UPDATE TABLE: Syntax: UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN WHERE [condition]; CONSTRAINT NOT NULL CONSTRAINT Syntax: CREATE TABLE table_name( column_name1 data_type(size) NOT NULL, column_name2 data_type(size) NOT NULL, column_name3 data_type(size) ); PRIMARY KEY CONSTRAINT Syntax: CREATE TABLE table_name( column_name1 data_type(size) PRIMARY KEY, column_name2 data_type(size) NOT NULL,
  • 5. column_name3 data_type(size) ); UNIQUE CONSTRAINT Syntax: CREATE TABLE table_name( column_name1 data_type(size) NOT NULL UNIQUE, column_name2 data_type(size) NOT NULL, column_name3 data_type(size) ); CHECK CONSTRAINT Syntax: CREATE TABLE table_name( column_name1 INTEGER AUTOINCREMENT, column_name2 data_type(size), column_name3 data_type(size) DEFAULT value, CHECK column_name1 condition ); DEFAULT CONSTRAINT Syntax: CREATE TABLE table_name( column_name1 INTEGER AUTOINCREMENT, column_name2 data_type(size), column_name3 data_type(size) DEFAULT value ); CLAUSE WHERE CLAUSE Syntax: SELECT column_name1, column_name2 FROM table_name WHERE [condition]; ORDER BY CLAUSE Syntax; SELECT column_name1, column_name2 FROM table_name ORDER BY column_name1, column_name2, ASC; SELECT column_name1, column_name2 FROM table_name
  • 6. ORDER BY column_name1, column_name2, DESC; GROUP BY CLAUSE Syntax; SELECT column_name, function (column_name) FROM table_name WHERE condition GROUP BY column_name; LIKE CLAUSE Syntax: SELECT column_name1, column_name2 FROM table_name WHERE column_name1 LIKE ‘A%’; Syntax: SELECT column_name1, column_name2 FROM table_name WHERE column_name1 LIKE ‘A_’; AND/OR OPERATOR Syntax: SELECT column1, column2, columnN FROM table_name WHERE [condition1] AND [condition2]...AND [conditionN]; SELECT column1, column2, columnN FROM table_name WHERE [condition1] OR [condition2]...OR [conditionN];