Posted by ZeldorBlat on 03/22/06 21:49
R.A.M. wrote:
> Hello,
> I am learning SQL Server 2005.
> I need to create a trigger which increments number of book's
> publications:
>
> CREATE TRIGGER InsertPublication
> ON Publications
> AFTER INSERT
> AS
> BEGIN
> SET NOCOUNT ON;
> DECLARE @Num smallint
> SET @Num = SELECT NumPublications FROM Books WHERE ISBN IN
> (SELECT ISBN FROM inserted);
> UPDATE Books
> SET NumPublications = @Num + 1
> WHERE ISBN IN
> (SELECT ISBN FROM inserted);
> END
>
> Unfortunately I receive a message:
>
> Incorrect syntax near the keyword 'SELECT'.
>
> Could you explain me please how to correct the code?
> I am new to SQL Server.
> Thank you very much.
> /RAM/
CREATE TRIGGER InsertPublication
ON Publications
AFTER INSERT
AS
BEGIN
UPDATE Books
SET NumPublications = NumPublications + 1
FROM Books, inserted
WHERE Books.ISBN = inserted.ISBN
END
Navigation:
[Reply to this message]
|