How to make a table to get the date / time when the values ​​from other tables were changed? viper

Possible duplicate:
How to execute a search function for sql database and how to get the time when the information from the table has been edited?

I have a table with three columns: name, age, birthday, date. There is also an option on my asp.net site page on each row of columns there is an edit button, so I can edit the text with name, age, birthday. How can I say that when I edit the text from the name column, the date column will have the value: "Name has been edited: date / time", etc.

Anyone help me? I tried this from 4 days ago and I could not find anything. I am using SQL 2008 database, Thanks

+4
source share
1 answer

Well, follow an example. (Remember, we can do it differently)

First of all, you need to add a new column to the table

Alter table INFORMATION add LastUpdate datetime null 

Then you create a trigger (be careful, you must declare the variable Name, as your table)

 Create TRIGGER trig_Information ON Information FOR UPDATE AS BEGIN declare @Name as varchar(100) /*Look up your column type*/ select @Name = i.Name from Inserted i update Information set LastUpdate = getdate() where Name = @Name END 

So, every time someone updates any register of this table, the trigger updates the LastUpdate field with the date / time of the operation.

MS. If your table has more than one PC, specify where in the sentence.

see ya

+1
source

Source: https://habr.com/ru/post/1399200/


All Articles