SlideShare a Scribd company logo
1 of 25
SQL Commands
(Part 3)
By: Ms. Rubab For DIT
Delete Statement(DML Statement)
The DELETE Statement in SQL is used to delete existing records from a
table. We can delete a single record or multiple records depending on
the condition we specify in the WHERE clause.
table_name: name of the table
some_condition: condition to choose particular
record.
DELETE FROM table_name WHERE some_condition;
By: Ms. Rubab For DIT
DELETE Stataement
We can delete single as well as multiple records
depending on the condition.
The Condition is provided in the WHERE clause.
If we omit the WHERE clause then all the records will be
deleted, and the table will be empty.
By: Ms. Rubab For DIT
Sample Table
Roll_No Name Address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
By: Ms. Rubab For DIT
Example 1 : Deleting single record:
Roll_No Name Address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
Delete the rows where NAME = ‘Sajid’. This will delete only the
first row.
DELETE FROM Student WHERE NAME = ‘Sajid';
By: Ms. Rubab For DIT
Example 1 : Deleting single record(Processing)
Roll_No Name Address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
Delete the rows where NAME = ‘Sajid’. This will delete only the
first row.
DELETE FROM Student WHERE NAME = ‘Sajid';
By: Ms. Rubab For DIT
Example 1 : Deleting single record (OUTPUT)
Roll_No Name Address Phone Age
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
Delete the rows where NAME = ‘Sajid’. This will delete only the
first row.
DELETE FROM Student WHERE NAME = ‘Sajid';
By: Ms. Rubab For DIT
Example 2: Deleting Multiple records:
Roll_No Name Address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
Delete the rows where Age = ‘17’. This will delete only the first
row.
DELETE FROM Student WHERE Age = ‘17';
By: Ms. Rubab For DIT
Example 2: Deleting Multiple
records(Processing)
Roll_No Name Address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
Delete the rows where Age = ‘17’. This will delete only the first
row.
DELETE FROM Student WHERE Age = ‘17';
By: Ms. Rubab For DIT
Example 2: Deleting Multiple
records(Output)
Roll_No Name Address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
Delete the rows where Age = ‘17’. This will delete only the first
row.
DELETE FROM Student WHERE Age = ‘17';
By: Ms. Rubab For DIT
Delete all the records
There are two
queries to Delete all
the records in a table
Query1: "DELETE FROM Student";
Query2: "DELETE * FROM Student";
OUTPUT: All the records in the table will be deleted, there are no records left to display. The
table Student will become empty!
By: Ms. Rubab For DIT
DDL Commands
1. CREATE: This command is used to create the database or its
objects (like tables, database, views, etc) (Details Discussed
in SQL Commands Part 1)
2. DROP: This command is used to delete objects from the
database.
3. ALTER: This is used to alter the structure of the database.
4. TRUNCATE: This is used to remove all records from a table,
including all spaces allocated for the records are removed.
5. RENAME: This is used to rename an object existing in the
database.
By: Ms. Rubab For DIT
SQL | DROP
DROP is used to delete a whole database or just a table.The DROP
statement destroys the objects like an existing database, table, index,
or view.
A DROP statement in SQL removes a component from a relational
database management system (RDBMS).
Syntax:
DROP object object_name
By: Ms. Rubab For DIT
Drop Syntax: Examples:
1.
DROP TABLE table_name;
table_name: Name of the table to be deleted.
2.
DROP DATABASE database_name;
database_name: Name of the database to be deleted.
The DROP command works for a single table, multiple tables or
the entire database
By: Ms. Rubab For DIT
SQL | Truncate
The result of this operation quickly removes all data from a table
It is faster than DELETE as DELETE removes the data row by row.
Syntax:
TRUNCATE TABLE table_name;
table_name: Name of the table to be truncated.
By: Ms. Rubab For DIT
DELETE DROP TRUNCATE
DML Command
Deletes the rows of a table, could
be a single row , multiple rows or
all the rows of a table, based on
the clause.
DELETE Deletes only the Data not
the structure of the Table
Rollback is possible before commit
DDL Command
DROP Deletes the entire schema/
structure (Which means the
contents as well as name and
constraints)
DDL Command
It also deletes the rows of a Table.
It doesn’t allow single Row
Deletion as it doesn’t support
WHERE Clause
Rollback is not possible
Rollback creates a temporary log of the data in the database that helps in data recovery before commit statement
DELETE VS DROP VS TRUNCTAE
By: Ms. Rubab For DIT
SQL | ALTER
ALTER TABLE is used to add, delete/drop or modify columns in
the existing table. It is also used to add and drop various
constraints on the existing table.
3 Types of
ALTERS
ADD DELETE/DROP Modify
By: Ms. Rubab For DIT
ALTER TABLE – ADD
ADD is used to add columns into the existing table. Sometimes
we may require to add additional information, in that case we do
not require to create the whole database again, ADD comes to
our rescue.
Syntax:
ALTER TABLE table_name ADD (Columnname_1 datatype,
Columnname_2 datatype, … Columnname_n datatype);
table_name: Name of the table to be altered
Columnname: Name of the Columns to be added
Datatype: Type of Data to be supported by new column
By: Ms. Rubab For DIT
ALTER TABLE – DROP
DROP COLUMN is used to drop column in a table. Deleting the unwanted
columns from the table.
Syntax:
ALTER TABLE table_name DROP COLUMN column_name;
By: Ms. Rubab For DIT
ALTER TABLE-MODIFY
It is used to modify the existing columns in a table. Multiple
columns can also be modified at once.
ALTER TABLE table_name
ALTER COLUMN column_name column_type;
Example:
ALTER TABLE Student
MODIFY COURSE varchar(20);
By: Ms. Rubab For DIT
SQL | ALTER (RENAME)
Sometimes we may want to rename our table to give it a more
relevant name. For this purpose we can use ALTER TABLE to
rename the name of table.
Syntax(MySQL):
ALTER TABLE table_name RENAME TO new_table_name;
Columns can be also be given new name with the use of ALTER
TABLE.
Syntax(MySQL):
ALTER TABLE `students` CHANGE
`old_name` `new_name` datatype(size);
By: Ms. Rubab For DIT
Sample Table
Roll_No Name Address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
Table Name: DATA
By: Ms. Rubab For DIT
Re-naming Table:
Roll_No Name Address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
ALTER TABLE DATA RENAME TO Students;
TABLE NAME: Students
By: Ms. Rubab For DIT
Re-naming columns:
Roll_No Name Address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
ALTER TABLE Students RENAME Column Name TO
std_name,Address TO std_address;
TABLE NAME: Students
By: Ms. Rubab For DIT
Re-naming columns:
Roll_No std_name std_address Phone Age
1 Sajid Sobhodero Xxxxxxxxxxx 18
2 Majid Ranipur Xxxxxxxxxxx 18
3 Abid Hinjorja Xxxxxxxxxxx 18
4 Zahid Sajiyoon Xxxxxxxxxxx 17
5 Anwar Niwaro Xxxxxxxxxxx 17
6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18
ALTER TABLE Students RENAME Column Name TO
std_name,Address TO std_address;
TABLE NAME: Students
By: Ms. Rubab For DIT

More Related Content

Similar to SQL Commands Part 3.pptx

introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functionsfarwa waqar
 
SQL Keywords and Functions.pptx
SQL Keywords and Functions.pptxSQL Keywords and Functions.pptx
SQL Keywords and Functions.pptxRUBAB79
 
Creating a database
Creating a databaseCreating a database
Creating a databaseRahul Gupta
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIMsKanchanaI
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Rapid postgresql learning, part 2
Rapid postgresql learning, part 2Rapid postgresql learning, part 2
Rapid postgresql learning, part 2Ali MasudianPour
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptDrRShaliniVISTAS
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sqlnaveen
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sqlnaveen
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL Rc Os
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for BeginnersAbdelhay Shafi
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL CommandsShrija Madhu
 

Similar to SQL Commands Part 3.pptx (20)

introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
SQL Keywords and Functions.pptx
SQL Keywords and Functions.pptxSQL Keywords and Functions.pptx
SQL Keywords and Functions.pptx
 
Creating a database
Creating a databaseCreating a database
Creating a database
 
Interview Questions.pdf
Interview Questions.pdfInterview Questions.pdf
Interview Questions.pdf
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql
SqlSql
Sql
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
GFGC CHIKKABASUR ( DDL COMMANDS )
GFGC CHIKKABASUR ( DDL COMMANDS )GFGC CHIKKABASUR ( DDL COMMANDS )
GFGC CHIKKABASUR ( DDL COMMANDS )
 
Rapid postgresql learning, part 2
Rapid postgresql learning, part 2Rapid postgresql learning, part 2
Rapid postgresql learning, part 2
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.ppt
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
 
DDL and DML statements.pptx
DDL and DML statements.pptxDDL and DML statements.pptx
DDL and DML statements.pptx
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Mysql
MysqlMysql
Mysql
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 

More from RUBAB79

Database.docx
Database.docxDatabase.docx
Database.docxRUBAB79
 
RDBMS.docx
RDBMS.docxRDBMS.docx
RDBMS.docxRUBAB79
 
MySQL String Functions.docx
MySQL String Functions.docxMySQL String Functions.docx
MySQL String Functions.docxRUBAB79
 
Difference between RDBMS and DBMS.docx
Difference between RDBMS and DBMS.docxDifference between RDBMS and DBMS.docx
Difference between RDBMS and DBMS.docxRUBAB79
 
Ms Access 1.pptx
Ms Access 1.pptxMs Access 1.pptx
Ms Access 1.pptxRUBAB79
 
Lecture 4-RDBMS.pptx
Lecture 4-RDBMS.pptxLecture 4-RDBMS.pptx
Lecture 4-RDBMS.pptxRUBAB79
 
SQL Introduction.pptx
SQL Introduction.pptxSQL Introduction.pptx
SQL Introduction.pptxRUBAB79
 
SQL Operators.pptx
SQL Operators.pptxSQL Operators.pptx
SQL Operators.pptxRUBAB79
 
SQL Commands Part 1.pptx
SQL Commands Part 1.pptxSQL Commands Part 1.pptx
SQL Commands Part 1.pptxRUBAB79
 
Database Lecture 3.pptx
Database Lecture 3.pptxDatabase Lecture 3.pptx
Database Lecture 3.pptxRUBAB79
 
SQL Conversion Functions.pptx
SQL Conversion Functions.pptxSQL Conversion Functions.pptx
SQL Conversion Functions.pptxRUBAB79
 
SQL Commands Part 2.pptx
SQL Commands Part 2.pptxSQL Commands Part 2.pptx
SQL Commands Part 2.pptxRUBAB79
 
DATABASE Lecture 1 and 2.pptx
DATABASE Lecture 1 and 2.pptxDATABASE Lecture 1 and 2.pptx
DATABASE Lecture 1 and 2.pptxRUBAB79
 

More from RUBAB79 (13)

Database.docx
Database.docxDatabase.docx
Database.docx
 
RDBMS.docx
RDBMS.docxRDBMS.docx
RDBMS.docx
 
MySQL String Functions.docx
MySQL String Functions.docxMySQL String Functions.docx
MySQL String Functions.docx
 
Difference between RDBMS and DBMS.docx
Difference between RDBMS and DBMS.docxDifference between RDBMS and DBMS.docx
Difference between RDBMS and DBMS.docx
 
Ms Access 1.pptx
Ms Access 1.pptxMs Access 1.pptx
Ms Access 1.pptx
 
Lecture 4-RDBMS.pptx
Lecture 4-RDBMS.pptxLecture 4-RDBMS.pptx
Lecture 4-RDBMS.pptx
 
SQL Introduction.pptx
SQL Introduction.pptxSQL Introduction.pptx
SQL Introduction.pptx
 
SQL Operators.pptx
SQL Operators.pptxSQL Operators.pptx
SQL Operators.pptx
 
SQL Commands Part 1.pptx
SQL Commands Part 1.pptxSQL Commands Part 1.pptx
SQL Commands Part 1.pptx
 
Database Lecture 3.pptx
Database Lecture 3.pptxDatabase Lecture 3.pptx
Database Lecture 3.pptx
 
SQL Conversion Functions.pptx
SQL Conversion Functions.pptxSQL Conversion Functions.pptx
SQL Conversion Functions.pptx
 
SQL Commands Part 2.pptx
SQL Commands Part 2.pptxSQL Commands Part 2.pptx
SQL Commands Part 2.pptx
 
DATABASE Lecture 1 and 2.pptx
DATABASE Lecture 1 and 2.pptxDATABASE Lecture 1 and 2.pptx
DATABASE Lecture 1 and 2.pptx
 

Recently uploaded

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

SQL Commands Part 3.pptx

  • 1. SQL Commands (Part 3) By: Ms. Rubab For DIT
  • 2. Delete Statement(DML Statement) The DELETE Statement in SQL is used to delete existing records from a table. We can delete a single record or multiple records depending on the condition we specify in the WHERE clause. table_name: name of the table some_condition: condition to choose particular record. DELETE FROM table_name WHERE some_condition; By: Ms. Rubab For DIT
  • 3. DELETE Stataement We can delete single as well as multiple records depending on the condition. The Condition is provided in the WHERE clause. If we omit the WHERE clause then all the records will be deleted, and the table will be empty. By: Ms. Rubab For DIT
  • 4. Sample Table Roll_No Name Address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 By: Ms. Rubab For DIT
  • 5. Example 1 : Deleting single record: Roll_No Name Address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 Delete the rows where NAME = ‘Sajid’. This will delete only the first row. DELETE FROM Student WHERE NAME = ‘Sajid'; By: Ms. Rubab For DIT
  • 6. Example 1 : Deleting single record(Processing) Roll_No Name Address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 Delete the rows where NAME = ‘Sajid’. This will delete only the first row. DELETE FROM Student WHERE NAME = ‘Sajid'; By: Ms. Rubab For DIT
  • 7. Example 1 : Deleting single record (OUTPUT) Roll_No Name Address Phone Age 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 Delete the rows where NAME = ‘Sajid’. This will delete only the first row. DELETE FROM Student WHERE NAME = ‘Sajid'; By: Ms. Rubab For DIT
  • 8. Example 2: Deleting Multiple records: Roll_No Name Address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 Delete the rows where Age = ‘17’. This will delete only the first row. DELETE FROM Student WHERE Age = ‘17'; By: Ms. Rubab For DIT
  • 9. Example 2: Deleting Multiple records(Processing) Roll_No Name Address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 Delete the rows where Age = ‘17’. This will delete only the first row. DELETE FROM Student WHERE Age = ‘17'; By: Ms. Rubab For DIT
  • 10. Example 2: Deleting Multiple records(Output) Roll_No Name Address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 Delete the rows where Age = ‘17’. This will delete only the first row. DELETE FROM Student WHERE Age = ‘17'; By: Ms. Rubab For DIT
  • 11. Delete all the records There are two queries to Delete all the records in a table Query1: "DELETE FROM Student"; Query2: "DELETE * FROM Student"; OUTPUT: All the records in the table will be deleted, there are no records left to display. The table Student will become empty! By: Ms. Rubab For DIT
  • 12. DDL Commands 1. CREATE: This command is used to create the database or its objects (like tables, database, views, etc) (Details Discussed in SQL Commands Part 1) 2. DROP: This command is used to delete objects from the database. 3. ALTER: This is used to alter the structure of the database. 4. TRUNCATE: This is used to remove all records from a table, including all spaces allocated for the records are removed. 5. RENAME: This is used to rename an object existing in the database. By: Ms. Rubab For DIT
  • 13. SQL | DROP DROP is used to delete a whole database or just a table.The DROP statement destroys the objects like an existing database, table, index, or view. A DROP statement in SQL removes a component from a relational database management system (RDBMS). Syntax: DROP object object_name By: Ms. Rubab For DIT
  • 14. Drop Syntax: Examples: 1. DROP TABLE table_name; table_name: Name of the table to be deleted. 2. DROP DATABASE database_name; database_name: Name of the database to be deleted. The DROP command works for a single table, multiple tables or the entire database By: Ms. Rubab For DIT
  • 15. SQL | Truncate The result of this operation quickly removes all data from a table It is faster than DELETE as DELETE removes the data row by row. Syntax: TRUNCATE TABLE table_name; table_name: Name of the table to be truncated. By: Ms. Rubab For DIT
  • 16. DELETE DROP TRUNCATE DML Command Deletes the rows of a table, could be a single row , multiple rows or all the rows of a table, based on the clause. DELETE Deletes only the Data not the structure of the Table Rollback is possible before commit DDL Command DROP Deletes the entire schema/ structure (Which means the contents as well as name and constraints) DDL Command It also deletes the rows of a Table. It doesn’t allow single Row Deletion as it doesn’t support WHERE Clause Rollback is not possible Rollback creates a temporary log of the data in the database that helps in data recovery before commit statement DELETE VS DROP VS TRUNCTAE By: Ms. Rubab For DIT
  • 17. SQL | ALTER ALTER TABLE is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table. 3 Types of ALTERS ADD DELETE/DROP Modify By: Ms. Rubab For DIT
  • 18. ALTER TABLE – ADD ADD is used to add columns into the existing table. Sometimes we may require to add additional information, in that case we do not require to create the whole database again, ADD comes to our rescue. Syntax: ALTER TABLE table_name ADD (Columnname_1 datatype, Columnname_2 datatype, … Columnname_n datatype); table_name: Name of the table to be altered Columnname: Name of the Columns to be added Datatype: Type of Data to be supported by new column By: Ms. Rubab For DIT
  • 19. ALTER TABLE – DROP DROP COLUMN is used to drop column in a table. Deleting the unwanted columns from the table. Syntax: ALTER TABLE table_name DROP COLUMN column_name; By: Ms. Rubab For DIT
  • 20. ALTER TABLE-MODIFY It is used to modify the existing columns in a table. Multiple columns can also be modified at once. ALTER TABLE table_name ALTER COLUMN column_name column_type; Example: ALTER TABLE Student MODIFY COURSE varchar(20); By: Ms. Rubab For DIT
  • 21. SQL | ALTER (RENAME) Sometimes we may want to rename our table to give it a more relevant name. For this purpose we can use ALTER TABLE to rename the name of table. Syntax(MySQL): ALTER TABLE table_name RENAME TO new_table_name; Columns can be also be given new name with the use of ALTER TABLE. Syntax(MySQL): ALTER TABLE `students` CHANGE `old_name` `new_name` datatype(size); By: Ms. Rubab For DIT
  • 22. Sample Table Roll_No Name Address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 Table Name: DATA By: Ms. Rubab For DIT
  • 23. Re-naming Table: Roll_No Name Address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 ALTER TABLE DATA RENAME TO Students; TABLE NAME: Students By: Ms. Rubab For DIT
  • 24. Re-naming columns: Roll_No Name Address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 ALTER TABLE Students RENAME Column Name TO std_name,Address TO std_address; TABLE NAME: Students By: Ms. Rubab For DIT
  • 25. Re-naming columns: Roll_No std_name std_address Phone Age 1 Sajid Sobhodero Xxxxxxxxxxx 18 2 Majid Ranipur Xxxxxxxxxxx 18 3 Abid Hinjorja Xxxxxxxxxxx 18 4 Zahid Sajiyoon Xxxxxxxxxxx 17 5 Anwar Niwaro Xxxxxxxxxxx 17 6 Ghulam Nabi Razal Memon Xxxxxxxxxxx` 18 ALTER TABLE Students RENAME Column Name TO std_name,Address TO std_address; TABLE NAME: Students By: Ms. Rubab For DIT