SQL DELETE Statement : SQL\u00a0DELETE statement is used to delete existing records in a table.<\/p>\n
DELETE\u00a0FROM\u00a0table_name<\/em><\/strong>
\n WHERE\u00a0condition<\/em>;<\/strong><\/p>\n
Note:<\/strong><\/p>\n
Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record(s) that should be deleted. If you omit the WHERE clause, all records in the table will be deleted!<\/p>\n
Below is a selection from the “Customers” table in the Northwind sample database:<\/p>\n\n\n\n\n\n\n\n\n
CustomerID<\/strong><\/td>\n | CustomerName<\/strong><\/td>\n | ContactName<\/strong><\/td>\n | Address<\/strong><\/td>\n | City<\/strong><\/td>\n | PostalCode<\/strong><\/td>\n | Country<\/strong><\/td>\n<\/tr>\n | |||||||||||||||||||||||||||||||||||
1<\/td>\n | Alfreds Futterkiste<\/td>\n | Maria Anders<\/td>\n | Obere Str. 57<\/td>\n | Berlin<\/td>\n | 12209<\/td>\n | Germany<\/td>\n<\/tr>\n | |||||||||||||||||||||||||||||||||||
2<\/td>\n | Ana Trujillo Emparedados y helados<\/td>\n | Ana Trujillo<\/td>\n | Avda. de la Constituci\u00f3n 2222<\/td>\n | M\u00e9xico D.F.<\/td>\n | 05021<\/td>\n | Mexico<\/td>\n<\/tr>\n | |||||||||||||||||||||||||||||||||||
3<\/td>\n | Antonio Moreno Taquer\u00eda<\/td>\n | Antonio Moreno<\/td>\n | Mataderos 2312<\/td>\n | M\u00e9xico D.F.<\/td>\n | 05023<\/td>\n | Mexico<\/td>\n<\/tr>\n | |||||||||||||||||||||||||||||||||||
4<\/td>\n | Around the Horn<\/td>\n | Thomas Hardy<\/td>\n | 120 Hanover Sq.<\/td>\n | London<\/td>\n | WA1 1DP<\/td>\n | UK<\/td>\n<\/tr>\n | |||||||||||||||||||||||||||||||||||
5<\/td>\n | Berglunds snabbk\u00f6p<\/td>\n | Christina Berglund<\/td>\n | Berguvsv\u00e4gen 8<\/td>\n | Lule\u00e5<\/td>\n | S-958 22<\/td>\n | Sweden<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n SQL DELETE Example<\/h2>\nThe following SQL statement deletes the customer “Alfreds Futterkiste” from the “Customers” table:<\/p>\n Example<\/h3>\nDELETE\u00a0FROM\u00a0Customers output<\/strong><\/h4>\n | |||||||||||||||||||||||||||||||||||
CustomerID<\/strong><\/td>\n | CustomerName<\/strong><\/td>\n | ContactName<\/strong><\/td>\n | Address<\/strong><\/td>\n | City<\/strong><\/td>\n | PostalCode<\/strong><\/td>\n | Country<\/strong><\/td>\n<\/tr>\n | |||||||||||||||||||||||||||||||||||
2<\/td>\n | Ana Trujillo Emparedados y helados<\/td>\n | Ana Trujillo<\/td>\n | Avda. de la Constituci\u00f3n 2222<\/td>\n | M\u00e9xico D.F.<\/td>\n | 05021<\/td>\n | Mexico<\/td>\n<\/tr>\n | |||||||||||||||||||||||||||||||||||
3<\/td>\n | Antonio Moreno Taquer\u00eda<\/td>\n | Antonio Moreno<\/td>\n | Mataderos 2312<\/td>\n | M\u00e9xico D.F.<\/td>\n | 05023<\/td>\n | Mexico<\/td>\n<\/tr>\n | |||||||||||||||||||||||||||||||||||
4<\/td>\n | Around the Horn<\/td>\n | Thomas Hardy<\/td>\n | 120 Hanover Sq.<\/td>\n | London<\/td>\n | WA1 1DP<\/td>\n | UK<\/td>\n<\/tr>\n | |||||||||||||||||||||||||||||||||||
5<\/td>\n | Berglunds snabbk\u00f6p<\/td>\n | Christina Berglund<\/td>\n | Berguvsv\u00e4gen 8<\/td>\n | Lule\u00e5<\/td>\n | S-958 22<\/td>\n | Sweden<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n Delete All Records<\/h2>\nIt is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:<\/p>\n DELETE\u00a0FROM\u00a0table_name<\/em>;<\/p>\n or:<\/p>\n DELETE\u00a0*\u00a0FROM\u00a0table_name<\/em>;<\/p>\n","protected":false},"excerpt":{"rendered":" SQL DELETE Statement : SQL\u00a0DELETE statement is used to delete existing records in a table. DELETE Syntax DELETE\u00a0FROM\u00a0table_name WHERE\u00a0condition; Note: Be careful when deleting records<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[386],"tags":[412,413],"class_list":["post-4269","post","type-post","status-publish","format-standard","hentry","category-sql","tag-sql-delete","tag-sql-delete-statement"],"_links":{"self":[{"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/posts\/4269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/comments?post=4269"}],"version-history":[{"count":1,"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/posts\/4269\/revisions"}],"predecessor-version":[{"id":13173,"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/posts\/4269\/revisions\/13173"}],"wp:attachment":[{"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/media?parent=4269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/categories?post=4269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iteducation.vivegroups.com\/wp-json\/wp\/v2\/tags?post=4269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} |