I am currently developing a webpage, and I want to add date&time to my database whenever there is an entry on the database.
-
What meaning would this datatime entry have? When would this entry change if at all?Oded– Oded2012-02-18 16:11:22 +00:00Commented Feb 18, 2012 at 16:11
-
whenever there is an entry to the database, it automatically adds the current date & time when was that certain entry was made and had been successfully added to the databasejade calingin– jade calingin2012-02-18 16:16:26 +00:00Commented Feb 18, 2012 at 16:16
Add a comment
|
1 Answer
Create a column of type datetime with a default value of getdate()
Each time an insert is added, it should stamp it with the current date/time
SQL code to add the column:
ALTER TABLE {tablename}
ADD {column_name} {DateTime} {NULL|NOT NULL} DEFAULT {getdate()}
8 Comments
jade calingin
can you guide me on how to do that? sorry, cause I'm new to this one :)
Jeff
I added to the answer - I am not sure the specifics of your database though. I am assuming MSSQL - The above should work if that is the case. Then all yo would have to do is read from the datetime to see when the row was inserted.
jade calingin
so I just add a column that has a timeStamp data type? then it will automatically generates the date&time for every entry?
jade calingin
is there any special coding to do in order to get that data type to work?
jmoreno
This works for INSERTS if the value is not set to null. It does not work for updates or where the column is included amoung the values (either explicitly by column list or implicitly by insert into select *)
|