SlideShare a Scribd company logo
1 of 2
Download to read offline
8/10/13 SQL DELETE, TRUNCATE, DROP Statements
beginner-sql-tutorial.com/sql-delete-statement.htm 1/2
SQL Delete Statement
The DELETE Statement is used to delete rows from a table.
The Syntax of a SQL DELETE statement is:
DELETE FROM table_name [WHERE condition];
table_name -- the table name which has to be updated.
NOTE:The WHERE clause in the sql delete command is optional and it identifies the rows in the column that gets
deleted. If you do not include the WHERE clause all the rows in the table is deleted, so be careful while writing a
DELETE query without WHERE clause.
For Example: To delete an employee with id 100 from the employee table, the sql delete query would be like,
DELETE FROM employee WHERE id = 100;
To delete all the rows from the employee table, the query would be like,
DELETE FROM employee;
SQL TRUNCATE Statement
The SQL TRUNCATE command is used to delete all the rows from the table and free the space containing the
table.
Syntax to TRUNCATE a table:
TRUNCATE TABLE table_name;
For Example: To delete all the rows from employee table, the query would be like,
TRUNCATE TABLE employee;
Difference between DELETE and TRUNCATE Statements:
DELETE Statement: This command deletes only the rows from the table based on the condition given in the
where clause or deletes all the rows from the table if no condition is specified. But it does not free the space
containing the table.
TRUNCATE statement: This command is used to delete all the rows from the table and free the space
containing the table.
SQL DROP Statement:
The SQL DROP command is used to remove an object from the database. If you drop a table, all the rows in the
table is deleted and the table structure is removed from the database. Once a table is dropped we cannot get it
back, so be careful while using DROP command. When a table is dropped all the references to the table will not
8/10/13 SQL DELETE, TRUNCATE, DROP Statements
beginner-sql-tutorial.com/sql-delete-statement.htm 2/2
be valid.
Syntax to drop a sql table structure:
DROP TABLE table_name;
For Example: To drop the table employee, the query would be like
DROP TABLE employee;
Difference between DROP and TRUNCATE Statement:
If a table is dropped, all the relationships with other tables will no longer be valid, the integrity constraints will be
dropped, grant or access privileges on the table will also be dropped, if want use the table again it has to be
recreated with the integrity constraints, access privileges and the relationships with other tables should be
established again. But, if a table is truncated, the table structure remains the same, therefore any of the above
problems will not exist.

More Related Content

What's hot

What's hot (20)

SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Sql
SqlSql
Sql
 
What is SQL? | Edureka
What is SQL? | EdurekaWhat is SQL? | Edureka
What is SQL? | Edureka
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
SQL commands
SQL commandsSQL commands
SQL commands
 
DB2 LUW Auditing
DB2 LUW AuditingDB2 LUW Auditing
DB2 LUW Auditing
 
pl/sql Procedure
pl/sql Procedurepl/sql Procedure
pl/sql Procedure
 
MS Sql Server: Creating Views
MS Sql Server: Creating ViewsMS Sql Server: Creating Views
MS Sql Server: Creating Views
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
SQL UNION
SQL UNIONSQL UNION
SQL UNION
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Sql comandos
Sql comandosSql comandos
Sql comandos
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 

Viewers also liked

Sql create table statement
Sql create table statementSql create table statement
Sql create table statement
Vivek Singh
 
Sql update statement
Sql update statementSql update statement
Sql update statement
Vivek Singh
 
3. frequency distribution
3. frequency distribution3. frequency distribution
3. frequency distribution
Ilham Bashir
 
Data Representations
Data RepresentationsData Representations
Data Representations
bujols
 
Stem & leaf plots + histograms
Stem & leaf plots + histogramsStem & leaf plots + histograms
Stem & leaf plots + histograms
ListeningDaisy
 
Sql insert statement
Sql insert statementSql insert statement
Sql insert statement
Vivek Singh
 
Sql server ___________session_19(triggers)
Sql server  ___________session_19(triggers)Sql server  ___________session_19(triggers)
Sql server ___________session_19(triggers)
Ehtisham Ali
 
Stem and leaf plot
Stem and leaf plotStem and leaf plot
Stem and leaf plot
bbeiers
 

Viewers also liked (20)

Sql create table statement
Sql create table statementSql create table statement
Sql create table statement
 
Sql wksht-7
Sql wksht-7Sql wksht-7
Sql wksht-7
 
Sql commands
Sql commandsSql commands
Sql commands
 
Part 15 triggerr
Part 15  triggerrPart 15  triggerr
Part 15 triggerr
 
Sql update statement
Sql update statementSql update statement
Sql update statement
 
SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database Trigger
 
Chapter03
Chapter03Chapter03
Chapter03
 
Ch4 notes for students
Ch4 notes for studentsCh4 notes for students
Ch4 notes for students
 
3. frequency distribution
3. frequency distribution3. frequency distribution
3. frequency distribution
 
Data Representations
Data RepresentationsData Representations
Data Representations
 
Stem & leaf plots + histograms
Stem & leaf plots + histogramsStem & leaf plots + histograms
Stem & leaf plots + histograms
 
6. triggers
6. triggers6. triggers
6. triggers
 
Sql insert statement
Sql insert statementSql insert statement
Sql insert statement
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11
 
Sql server ___________session_19(triggers)
Sql server  ___________session_19(triggers)Sql server  ___________session_19(triggers)
Sql server ___________session_19(triggers)
 
Finding Interquartile Range from Stem-Leaf Plot 1
Finding Interquartile Range from Stem-Leaf Plot 1Finding Interquartile Range from Stem-Leaf Plot 1
Finding Interquartile Range from Stem-Leaf Plot 1
 
Symmetry and Skew
Symmetry and Skew Symmetry and Skew
Symmetry and Skew
 
Stem and leaf plot
Stem and leaf plotStem and leaf plot
Stem and leaf plot
 
SAP HANA - Manually to insert_data_table
SAP HANA - Manually to insert_data_tableSAP HANA - Manually to insert_data_table
SAP HANA - Manually to insert_data_table
 

Similar to Sql delete, truncate, drop statements

Sql alter table statement
Sql alter table statementSql alter table statement
Sql alter table statement
Vivek Singh
 
ii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docxii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docx
lakshmi77
 

Similar to Sql delete, truncate, drop statements (20)

Sql alter table statement
Sql alter table statementSql alter table statement
Sql alter table statement
 
Data Definition Language (DDL)
Data Definition Language (DDL) Data Definition Language (DDL)
Data Definition Language (DDL)
 
ii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docxii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docx
 
GFGC CHIKKABASUR ( DDL COMMANDS )
GFGC CHIKKABASUR ( DDL COMMANDS )GFGC CHIKKABASUR ( DDL COMMANDS )
GFGC CHIKKABASUR ( DDL COMMANDS )
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
 
Sql
SqlSql
Sql
 
Interview Questions.pdf
Interview Questions.pdfInterview Questions.pdf
Interview Questions.pdf
 
Les02
Les02Les02
Les02
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
Assignment 3
Assignment 3Assignment 3
Assignment 3
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Sql tables
Sql tablesSql tables
Sql tables
 
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
 
Babitha2.mysql
Babitha2.mysqlBabitha2.mysql
Babitha2.mysql
 

More from Vivek Singh

C programming session 14
C programming session 14C programming session 14
C programming session 14
Vivek Singh
 
C programming session 13
C programming session 13C programming session 13
C programming session 13
Vivek Singh
 
C programming session 11
C programming session 11C programming session 11
C programming session 11
Vivek Singh
 
C programming session 10
C programming session 10C programming session 10
C programming session 10
Vivek Singh
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
Vivek Singh
 
C programming session 07
C programming session 07C programming session 07
C programming session 07
Vivek Singh
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
Vivek Singh
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
Vivek Singh
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
Vivek Singh
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Vivek Singh
 
C programming session 16
C programming session 16C programming session 16
C programming session 16
Vivek Singh
 
Niit aptitude question paper
Niit aptitude question paperNiit aptitude question paper
Niit aptitude question paper
Vivek Singh
 
Excel shortcut and tips
Excel shortcut and tipsExcel shortcut and tips
Excel shortcut and tips
Vivek Singh
 
Sql where clause
Sql where clauseSql where clause
Sql where clause
Vivek Singh
 
Sql tutorial, tutorials sql
Sql tutorial, tutorials sqlSql tutorial, tutorials sql
Sql tutorial, tutorials sql
Vivek Singh
 
Sql select statement
Sql select statementSql select statement
Sql select statement
Vivek Singh
 
Sql query tuning or query optimization
Sql query tuning or query optimizationSql query tuning or query optimization
Sql query tuning or query optimization
Vivek Singh
 
Sql query tips or query optimization
Sql query tips or query optimizationSql query tips or query optimization
Sql query tips or query optimization
Vivek Singh
 

More from Vivek Singh (20)

C programming session 14
C programming session 14C programming session 14
C programming session 14
 
C programming session 13
C programming session 13C programming session 13
C programming session 13
 
C programming session 11
C programming session 11C programming session 11
C programming session 11
 
C programming session 10
C programming session 10C programming session 10
C programming session 10
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
 
C programming session 07
C programming session 07C programming session 07
C programming session 07
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
C programming session 16
C programming session 16C programming session 16
C programming session 16
 
Niit aptitude question paper
Niit aptitude question paperNiit aptitude question paper
Niit aptitude question paper
 
Excel shortcut and tips
Excel shortcut and tipsExcel shortcut and tips
Excel shortcut and tips
 
Sql where clause
Sql where clauseSql where clause
Sql where clause
 
Sql tutorial, tutorials sql
Sql tutorial, tutorials sqlSql tutorial, tutorials sql
Sql tutorial, tutorials sql
 
Sql subquery
Sql subquerySql subquery
Sql subquery
 
Sql select statement
Sql select statementSql select statement
Sql select statement
 
Sql rename
Sql renameSql rename
Sql rename
 
Sql query tuning or query optimization
Sql query tuning or query optimizationSql query tuning or query optimization
Sql query tuning or query optimization
 
Sql query tips or query optimization
Sql query tips or query optimizationSql query tips or query optimization
Sql query tips or query optimization
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
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
 

Sql delete, truncate, drop statements

  • 1. 8/10/13 SQL DELETE, TRUNCATE, DROP Statements beginner-sql-tutorial.com/sql-delete-statement.htm 1/2 SQL Delete Statement The DELETE Statement is used to delete rows from a table. The Syntax of a SQL DELETE statement is: DELETE FROM table_name [WHERE condition]; table_name -- the table name which has to be updated. NOTE:The WHERE clause in the sql delete command is optional and it identifies the rows in the column that gets deleted. If you do not include the WHERE clause all the rows in the table is deleted, so be careful while writing a DELETE query without WHERE clause. For Example: To delete an employee with id 100 from the employee table, the sql delete query would be like, DELETE FROM employee WHERE id = 100; To delete all the rows from the employee table, the query would be like, DELETE FROM employee; SQL TRUNCATE Statement The SQL TRUNCATE command is used to delete all the rows from the table and free the space containing the table. Syntax to TRUNCATE a table: TRUNCATE TABLE table_name; For Example: To delete all the rows from employee table, the query would be like, TRUNCATE TABLE employee; Difference between DELETE and TRUNCATE Statements: DELETE Statement: This command deletes only the rows from the table based on the condition given in the where clause or deletes all the rows from the table if no condition is specified. But it does not free the space containing the table. TRUNCATE statement: This command is used to delete all the rows from the table and free the space containing the table. SQL DROP Statement: The SQL DROP command is used to remove an object from the database. If you drop a table, all the rows in the table is deleted and the table structure is removed from the database. Once a table is dropped we cannot get it back, so be careful while using DROP command. When a table is dropped all the references to the table will not
  • 2. 8/10/13 SQL DELETE, TRUNCATE, DROP Statements beginner-sql-tutorial.com/sql-delete-statement.htm 2/2 be valid. Syntax to drop a sql table structure: DROP TABLE table_name; For Example: To drop the table employee, the query would be like DROP TABLE employee; Difference between DROP and TRUNCATE Statement: If a table is dropped, all the relationships with other tables will no longer be valid, the integrity constraints will be dropped, grant or access privileges on the table will also be dropped, if want use the table again it has to be recreated with the integrity constraints, access privileges and the relationships with other tables should be established again. But, if a table is truncated, the table structure remains the same, therefore any of the above problems will not exist.