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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help with query !!

Author  Topic 

Kaytee007
Starting Member

2 Posts

Posted - 2014-04-04 : 18:58:16
The question I am stuck on is this !
Create an INSERT trigger called tr_insert_shippers on the Shippers table preventing inserting a row with a company name which already exists. Use the following query to test your trigger.

So far what i have done. I am very new to triggers and dont really have a clue what I am doing wrong. Help me out please !

CREATE TRIGGER tr_insert_shippers
ON Shippers
FOR INSERT
AS


DECLARE @Duplicate Varchar(20)


IF EXISTS (SELECT CompanyName FROM Shippers WHERE CompanyName = @Duplicate)

BEGIN
PRINT ('Duplicate Data' )
ROLLBACK TRANSACTION
END
GO
-
   

- Advertisement -