0

I am currently developing a webpage, and I want to add date&time to my database whenever there is an entry on the database.

2
  • What meaning would this datatime entry have? When would this entry change if at all? Commented 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 database Commented Feb 18, 2012 at 16:16

1 Answer 1

2

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()}
Sign up to request clarification or add additional context in comments.

8 Comments

can you guide me on how to do that? sorry, cause I'm new to this one :)
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.
so I just add a column that has a timeStamp data type? then it will automatically generates the date&time for every entry?
is there any special coding to do in order to get that data type to work?
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 *)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.