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 |
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-09-17 : 00:37:40
|
| Hi,i have a database name call cw and have some table in cw example like Employee1. Inside Employee1, i have EmployeeID,...,CreatedDate and LastUpdated.the created Date and Last Updated is use for when insert data or update data,it will record of current data.Here is my sql script, but doesn't work.Anyone can help???? or have another good way to do it???CREATE TRIGGER tr[Employee1]CreateDate ON [Employee1]FOR INSERT ASUPDATE [Employee1] SET [Employee1].CreatedDate=getdate()FROM [Employee1] INNER JOIN Inserted ON [Employee1].[EmployeeID]= Inserted.[EmployeeID]GOCREATE TRIGGER tr[Employee1]LastUpdatedDate ON [Employee1]FOR UPDATE ASUPDATE [Employee1] SET [Employee1].LastUpdated=getdate()FROM [Employee1] INNER JOIN Inserted ON [Employee1].[EmployeeID]= Inserted.[EmployeeID]Thanks... |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-09-17 : 01:42:33
|
| Looks fine to me, except I have a doubt about the square brackets in the Trigger Name (dunno if that is in your code, or just the example you have posted here?) tr[Employee1]CreateDate |
 |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-09-17 : 03:04:20
|
quote: Originally posted by Kristen Looks fine to me, except I have a doubt about the square brackets in the Trigger Name (dunno if that is in your code, or just the example you have posted here?) tr[Employee1]CreateDate
Thanks for reply...but i will have this error:Msg 8197, Level 16, State 4, Procedure trEmployeeCreateDate, Line 1The object 'Employee' does not exist or is invalid for this operation.Msg 8197, Level 16, State 4, Procedure trEmployeeLastUpdatedDate, Line 2The object 'Employee' does not exist or is invalid for this operation. |
 |
|
|
yvette
Yak Posting Veteran
74 Posts |
Posted - 2010-09-17 : 03:05:31
|
quote: Originally posted by yvette
quote: Originally posted by Kristen Looks fine to me, except I have a doubt about the square brackets in the Trigger Name (dunno if that is in your code, or just the example you have posted here?) tr[Employee1]CreateDate
Thanks for reply...but i will have this error:Msg 8197, Level 16, State 4, Procedure trEmployeeCreateDate, Line 1The object 'Employee' does not exist or is invalid for this operation.Msg 8197, Level 16, State 4, Procedure trEmployeeLastUpdatedDate, Line 2The object 'Employee' does not exist or is invalid for this operation.
i change my table name to Employee. |
 |
|
|
|
|
|
|
|