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
 SQL TRIGGER THE MULTIPART IDENTIFIER CANT BE BOUND

Author  Topic 

EmilyJohns30
Starting Member

3 Posts

Posted - 2014-12-05 : 22:03:32
I am VERY new to coding. I am in high school and I would really like to learn SQL. I am trying to teach myself, but I have some questions. I created a video store database. I have a 3 tables customers, movies, and rentals. I am getting some general syntax errors and SQL TRIGGER THE MULTI-PART IDENTIFIER CANT BE BOUND on i.Rental.rentNum.

Any suggestions you can offer will be helpful!

CREATE TRIGGER
insteadOFInsert ON Rental
INSTEAD OF INSERT
AS
DECLARE @rentNum int, @action varchar(60)

SELECT (@Rent_rentNum=i.Rental.rentNum FROM inserted i);
SET (@action='stop rental trigger.',
@Rent_rentNum=(SELECT rentNum FROM inserted);

BEGIN
BEGIN TRAN
SET NOCOUNT ON
IF (@RENT_rentNum=Rental.rentNum)
BEGIN
RAISEERROR ('You cannot rent the same move twice');
ROLLBACK
END
ELSE
BEGIN
INSERT INTO
Rental(rentNum)
VALUES
(@rentNum)
INSERT INTO
Rent values (rentNum);
COMMIT
PRINT 'Updated'
END
END

Emily J

EmilyJohns30
Starting Member

3 Posts

Posted - 2014-12-05 : 22:57:41
Anyone??

Emily J
Go to Top of Page

mandm
Posting Yak Master

120 Posts

Posted - 2014-12-06 : 06:15:18
You have unmatched parentheses in this section (shown in red). Try removing them or adding the matching one for each.

SELECT @Rent_rentNum=i.Rental.rentNum FROM inserted i);
SET @action='stop rental trigger.'
@Rent_rentNum=(SELECT rentNum FROM inserted;

Also on a more general note the code assumes that there will only be one row in the "inserted" table which may not always be the case. This could be problematic if say someone rented 3 movies.
Go to Top of Page

EmilyJohns30
Starting Member

3 Posts

Posted - 2014-12-06 : 11:29:13
quote:
Originally posted by mandm

You have unmatched parentheses in this section (shown in red). Try removing them or adding the matching one for each.

SELECT @Rent_rentNum=i.Rental.rentNum FROM inserted i);
SET @action='stop rental trigger.'
@Rent_rentNum=(SELECT rentNum FROM inserted;

Also on a more general note the code assumes that there will only be one row in the "inserted" table which may not always be the case. This could be problematic if say someone rented 3 movies.



I am using sql mgnt studio 2008 (fyi)
Sorry, those were just typos- i cant copy from the vm. I'm still getting the errors

Emily J
Go to Top of Page

mandm
Posting Yak Master

120 Posts

Posted - 2014-12-06 : 13:01:44
What are you trying to do on this line?

SELECT (@Rent_rentNum=i.Rental.rentNum FROM inserted i)

You are trying to reference the alias 'i' for inserted and the rental table.
Go to Top of Page
   

- Advertisement -