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 |
Borgen313
Starting Member
2 Posts |
Posted - 2012-10-11 : 07:40:13
|
Hi. I am pretty new to this sql server 2012 programming and have a difficult task in school wich i can't seem to figure out. So I now ask for your help.The task is as follows:Create a AFTER INSERT trigger for the table Sokande that verifies the new row(s) postalcode (postNr) and city is correct. This is done by finding the postalcode and making sure the city is correct. If the postalcode isn't found or the city doesn't match, the new row(s) should be deleted from the Sokande table by the trigger.So thats the task I've been working on for two days. I hope you understand and I hope any of you can help me in any way possible.Thanks, Borgen313. |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-10-11 : 07:46:24
|
Usually people on the forum are reluctant to post answers to school-related work for fear that they may be doing a disservice rather than helping. If you post what you have tried so far, I am sure many people on the forum would be very glad to help.Take a look at this page, write something that you think is right, even if it doesn't do everything you want to and post the code: http://msdn.microsoft.com/en-us/library/ms189799.aspx |
 |
|
Borgen313
Starting Member
2 Posts |
Posted - 2012-10-11 : 08:01:00
|
Okey good to know. But no need to worry about that, everyone doing the task right now is just about to give up and this is our last hope.This is what we have tried so far:CREATE TRIGGER dbo.check_delete_postNr_ort ON dbo.SokandeAFTER INSERTASBEGINDECLARE @isokarNr numericDECLARE @ipostNr charDECLARE @iort varcharDECLARE @ppostNr charDECLARE @port varcharSELECT @isokarNr = sokarNr, @ipostNr = postNr, @iort = ortFROM INSERTEDSELECT @ppostNr = postNr, @port = ortFROM PostnummerWHERE postNr = @ipostNrORort = @iortIF @ipostNr <> @ppostNr OR @iort <> @portDELETE FROM SokandeWHERE sokarNr = @isokarNrELSERETURNEND |
 |
|
|
|
|