Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
TheKai
Starting Member
16 Posts |
Posted - 2011-05-14 : 00:05:13
|
| Hi there. I'm trying to delete related records from several tables. Based on some reading, I thought the following query would work, but it's no good. Any ideas?I want to delete all records, that are marked as IsTemp=1 in the tblMaster table and all related records from the other tables, matching on the ID field of the tblMaster table.DELETE tblMaster, -- query analyzer complains about this commaPropertiesFloat,PropertiesInt,PropertiesLong,PropertiesString,StatsFROMtblMasterPropertiesFloat,PropertiesInt,PropertiesLong,PropertiesString,StatsWHEREtblMaster.IsTemp = 1ANDPropertiesFloat.ID = tblMaster.IDANDPropertiesInt.ID = tblMaster.IDANDtblPropertiesLong.ID = tblMaster.IDANDtblPropertiesString.ID = tblMaster.IDANDtblStats.ID = tblMaster.ID |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-05-14 : 00:24:03
|
You can't. You have to do it table by table KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2011-05-14 : 23:35:04
|
| Please post real DDL. Learn to use ISO-11179 rules for the data element names, avoid needless dialect and use ISO-8601 temporal formats, codes and so forth. People cannot read your mind, so post your code and clear specs if you really want help. What you did post looks like a nightmare of EAV. Google it.--CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-05-15 : 04:28:07
|
| All DML statements (insert, update, delete) must target a single table per statement. Delete from the child tables first, then from the parent.--Gail ShawSQL Server MVP |
 |
|
|
|
|
|
|
|