Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Auto Date Column 1

Status
Not open for further replies.

ironvid

IS-IT--Management
Sep 2, 2003
10
GB
I need to add a column to automaticly add the date that the record was created.

I am a Complete begineer to sql so the more detail the better,I am using SQL 2000

thanks for any help

regards....stephen
 
Read up on Triggers - really is the best way to learn.

Dickie Bird (:)-)))
 
You could set the default value of the column to be getdate()

i.e. if you were creating the table programmatically you would
CREATE TABLE [dbo].[Table1] (
[ID] [int] NOT NULL ,
[MyDateColumn] [datetime] NOT NULL DEFAULT GETDATE()
) ON [PRIMARY]
GO
 
Adding a DEFAULT is much better than using a trigger in this scenario. In addition to hmckillop's post, to add a column to an existing table you can use:

Code:
ALTER TABLE Table1
ADD CreateDate datetime NOT NULL CONSTRAINT DF_CreateDate DEFAULT (getdate())

--James
 
(getdate()) IS WHAT I WAS LOOKING FOR

THANKS hmckillop & james
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top