Delete From From!

Posto questo esempio di codice SQL :| perchè chiacchierando con un amico è emerso che la sintassi del "delete from from" è molto utile ma non molto conosciuta.

PROBLEMA: Devo cancellare i record della tabella "Tabella_A" che esistono nella tabella "Tabella_B" (testato su Sql Server 2008).

 

Se la chiave di relazione fra le due tabelle è solo una posso risolverla molto velocemente così:

DELETE

FROM Tabella_A

WHERE Chiave IN

( SELECT Chiave FROM Tabella_B WHERE Tabella_A.Chiave = Tabella_B.Chiave )

 

Se le chiavi di relazione sono due o più:

DELETE

FROM Tabella_A

FROM Tabella_A A INNER JOIN Tabella_B B ON A.Chiave = B.Chiave

In generale la parte in bold è il subset di dati che mi dice quali record dovrò cancellare dalla tabella in Italic.

 

So che questo può sembrare un post "del piffero" ma delle volte può risultare utile!

 

Riccardo.

posted @ venerdì 13 giugno 2008 19:45

Print

Comments on this entry:

# re: Delete From From!

Left by Mauro Franchi at 13/06/2008 20:36
Gravatar
Non la conoscevo! Grazie per la segnalazione.

# Delete From From - Precisazione

Left by Riccardo at 15/07/2008 14:52
Gravatar
Delete From From - Precisazione

# re: Delete From From!

Left by Curry at 10/02/2016 21:18
Gravatar
Good info and Thanks for sharing this with us.
Buy Medicine

# re: Delete From From!

Left by www.karresults.nic.in at 17/12/2017 10:18
Gravatar
Thats a great post. I really enjoy reading this post. You can check your results anytime in this website.

# re: Delete From From!

Left by gcu student login at 31/12/2017 13:26
Gravatar
To open an account or access the existing account you must have credentials like student ID or user ID which are given by the college.

# re: Delete From From!

Left by kick day quotes at 18/01/2018 13:53
Gravatar
Hello Dear, Really your blog is very interesting.... it contains great and unique information. I enjoyed to visiting your blog. Its just amazing.... Thanks very much.

# re: Delete From From!

Left by David at 16/04/2018 22:18
Gravatar
Thanks For Sharing An Awesome Information!

http://www.lacartes.com/business/DDN-India/659136

# re: Delete From From!

Left by Marcus Pollos at 16/04/2018 22:20
Gravatar
This is what I am looking from last couple of years Thanks For Sharing This:)

http://www.bestbrandsworldwide.com/ddn-india

# re: Delete From From!

Left by Max at 16/04/2018 22:21
Gravatar
Thanks For Sharing An Awesome Information!

http://www.bestbrandsworldwide.com/ddn-india-seo-chandigarh

# trail cam

Left by trail camera at 08/06/2018 15:00
Gravatar

# re: Delete From From!

Left by kodi at 10/06/2018 15:45
Gravatar

# re: Delete From From!

Left by sites at 27/08/2018 13:30
Gravatar

# re: Delete From From!

Left by visit at 01/09/2018 14:47
Gravatar

# re: Delete From From!

Left by new site at 05/09/2018 12:35
Gravatar
Comments have been closed on this topic.
«novembre»
domlunmarmergiovensab
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567