{"id":4269,"date":"2017-11-10T09:33:30","date_gmt":"2017-11-10T09:33:30","guid":{"rendered":"http:\/\/vivegroups.com\/?p=4269"},"modified":"2022-08-28T15:30:15","modified_gmt":"2022-08-28T15:30:15","slug":"sql-delete-statement","status":"publish","type":"post","link":"https:\/\/iteducation.vivegroups.com\/sql-delete-statement\/","title":{"rendered":"SQL DELETE Statement"},"content":{"rendered":"

SQL DELETE Statement : SQL\u00a0DELETE statement is used to delete existing records in a table.<\/p>\n

DELETE Syntax<\/h3>\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

Demo Database<\/h2>\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>\nCustomerName<\/strong><\/td>\nContactName<\/strong><\/td>\nAddress<\/strong><\/td>\nCity<\/strong><\/td>\nPostalCode<\/strong><\/td>\nCountry<\/strong><\/td>\n<\/tr>\n
1<\/td>\nAlfreds Futterkiste<\/td>\nMaria Anders<\/td>\nObere Str. 57<\/td>\nBerlin<\/td>\n12209<\/td>\nGermany<\/td>\n<\/tr>\n
2<\/td>\nAna Trujillo Emparedados y helados<\/td>\nAna Trujillo<\/td>\nAvda. de la Constituci\u00f3n 2222<\/td>\nM\u00e9xico D.F.<\/td>\n05021<\/td>\nMexico<\/td>\n<\/tr>\n
3<\/td>\nAntonio Moreno Taquer\u00eda<\/td>\nAntonio Moreno<\/td>\nMataderos 2312<\/td>\nM\u00e9xico D.F.<\/td>\n05023<\/td>\nMexico<\/td>\n<\/tr>\n
4<\/td>\nAround the Horn<\/td>\nThomas Hardy<\/td>\n120 Hanover Sq.<\/td>\nLondon<\/td>\nWA1 1DP<\/td>\nUK<\/td>\n<\/tr>\n
5<\/td>\nBerglunds snabbk\u00f6p<\/td>\nChristina Berglund<\/td>\nBerguvsv\u00e4gen 8<\/td>\nLule\u00e5<\/td>\nS-958 22<\/td>\nSweden<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

SQL DELETE Example<\/h2>\n

The following SQL statement deletes the customer “Alfreds Futterkiste” from the “Customers” table:<\/p>\n

Example<\/h3>\n

DELETE\u00a0FROM\u00a0Customers
\nWHERE\u00a0CustomerName=’Alfreds Futterkiste’;<\/p>\n

output<\/strong><\/h4>\n

The “Customers” table will now look like this:<\/p>\n\n\n\n\n\n\n\n
CustomerID<\/strong><\/td>\nCustomerName<\/strong><\/td>\nContactName<\/strong><\/td>\nAddress<\/strong><\/td>\nCity<\/strong><\/td>\nPostalCode<\/strong><\/td>\nCountry<\/strong><\/td>\n<\/tr>\n
2<\/td>\nAna Trujillo Emparedados y helados<\/td>\nAna Trujillo<\/td>\nAvda. de la Constituci\u00f3n 2222<\/td>\nM\u00e9xico D.F.<\/td>\n05021<\/td>\nMexico<\/td>\n<\/tr>\n
3<\/td>\nAntonio Moreno Taquer\u00eda<\/td>\nAntonio Moreno<\/td>\nMataderos 2312<\/td>\nM\u00e9xico D.F.<\/td>\n05023<\/td>\nMexico<\/td>\n<\/tr>\n
4<\/td>\nAround the Horn<\/td>\nThomas Hardy<\/td>\n120 Hanover Sq.<\/td>\nLondon<\/td>\nWA1 1DP<\/td>\nUK<\/td>\n<\/tr>\n
5<\/td>\nBerglunds snabbk\u00f6p<\/td>\nChristina Berglund<\/td>\nBerguvsv\u00e4gen 8<\/td>\nLule\u00e5<\/td>\nS-958 22<\/td>\nSweden<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

 <\/p>\n

Delete All Records<\/h2>\n

It 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}]}}