Trouble with this simple trigger script
create trigger personInsertTrigger on dbo.Person for INSERT
as
declare t开发者_如何学编程mpPersonID INT
set tmpPersonID = (select ID from INSERTED)
insert into dbo.PersonRecords values (tmpPersonID, now())
I get the following error:
Msg 155, Level 15, State 2, Procedure personInsertTrigger, Line 3 'INT' is not a recognized CURSOR option. Msg 195, Level 15, State 10, Procedure personInsertTrigger, Line 6 'now' is not a recognized built-in function name.
Can anyone help me complete this little script? I want it to save the Person's ID and the time it was inserted into a second table called PersonRecords.
Thanks.
use @ for variables -
declare @tmpPersonID INT
Local variables must begin with @. Cursors don't use the @ notation, so it is interpreting your declare as a cursor not a variable.
Also instead of now()
I think you need to use getdate()
The variable needs to start with an @
Change
declare tmpPersonID INT
to
declare @tmpPersonID INT
Have a look at
DECLARE @local_variable (Transact-SQL)
精彩评论