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 |
|
lucsky8
Posting Yak Master
105 Posts |
Posted - 2009-10-21 : 08:58:07
|
Hi we have a report sheet for schools.Just to let you know i did not design the table.I need to create a stored procedure to delete a report.Here the tables i trying to delete, in this example i want to delete the report with the id 89I would like to create a SP exe uspDelteReport 89 and will delete all the information that are relatated in all the tableI hope explain my self wright!Sorry for my bad english I know i need to loop in someway but i have no ideaTks in advanceLucI need to delete them in this order because of the relation-tblDescripteur-tblCommentaire-tblHabiletes_Attitudes-tblObjet-tblSction-tblNomBullThe above example is the way that i do it manuallySELECT * FROM tblNomBull WHERE ID = 89SELECT * FROM tblSection WHERE ID_Bull = 89SELECT * FROM tblObjet WHERE ID_Sec = 277 OR ID_Sec = 279 OR ID_Sec = 280SELECT * FROM tblHabiletes_Attitudes WHERE ID_Obj = 1061 OR ID_Obj = 1062 OR ID_Obj = 1063 OR ID_Obj = 1064 OR ID_Obj = 1070 OR ID_Obj = 1071 OR ID_Obj = 1072 OR ID_Obj = 1073 OR ID_Obj = 1074 OR ID_Obj = 1075 OR ID_Obj = 1076 OR ID_Obj = 1077 OR ID_Obj = 1078SELECT * FROM tblCommentaire WHERE ID_Obj = 1061 OR ID_Obj = 1062 OR ID_Obj = 1063 OR ID_Obj = 1064 OR ID_Obj = 1070 OR ID_Obj = 1071 OR ID_Obj = 1072 OR ID_Obj = 1073 OR ID_Obj = 1074 OR ID_Obj = 1075 OR ID_Obj = 1076 OR ID_Obj = 1077 OR ID_Obj = 1078SELECT * FROM tblDescripteur WHERE ID_Obj = 1061 OR ID_Obj = 1062 OR ID_Obj = 1063 OR ID_Obj = 1064 OR ID_Obj = 1070 OR ID_Obj = 1071 OR ID_Obj = 1072 OR ID_Obj = 1073 OR ID_Obj = 1074 OR ID_Obj = 1075 OR ID_Obj = 1076 OR ID_Obj = 1077 OR ID_Obj = 1078 |
|
|
lucsky8
Posting Yak Master
105 Posts |
Posted - 2009-10-21 : 10:19:30
|
I think i got it :--Get sectionDECLARE @TempSection table ( idSection int ) INSERT INTO @TempSectionSELECT ID FROM tblSection WHERE ID_Bull = 88--Get objectDECLARE @TempObjet table ( idObjet int ) INSERT INTO @TempObjetSELECT ID FROM tblObjet INNER JOIN @TempSection on idSection = tblObjet.ID_Sec DELETE tblHabiletes_Attitudes FROM tblHabiletes_Attitudes inner join @TempObjet on idObjet = tblHabiletes_Attitudes.ID_ObjDELETE tblCommentaire FROM tblCommentaire inner join @TempObjet on idObjet = tblCommentaire.ID_ObjDELETE tblDescripteur FROM tblDescripteur inner join @TempObjet on idObjet = tblDescripteur.ID_ObjDELETE tblObjet FROM tblObjet inner join @TempSection on idSection = tblObjet.ID_SecDELETE tblSection FROM tblSection WHERE ID_Bull = 88DELETE tblNomBull FROM tblNomBull WHERE ID = 88 |
 |
|
|
|
|
|