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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Inserting a date in SQL 2000

Author  Topic 

darenkov
Yak Posting Veteran

90 Posts

Posted - 2005-01-18 : 01:04:40
Hi, I have created a table with a smalldatetime field. I was wondering if there was any way I could have the current date inserted automatically when the row is created?

If not can anyone suggest or show me a couple lines of T-SQL for how this can be done manually (if possible)?

cheers

Hippi
Yak Posting Veteran

63 Posts

Posted - 2005-01-18 : 01:34:30
quote:
Originally posted by darenkov

Hi, I have created a table with a smalldatetime field. I was wondering if there was any way I could have the current date inserted automatically when the row is created?

If not can anyone suggest or show me a couple lines of T-SQL for how this can be done manually (if possible)?

cheers


You can create a table with a column having the default value of the current date. If I remember exactly, there is an example in BOL.

HTH
Go to Top of Page

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2005-01-18 : 13:21:19
Default value


Getdate()

Jim
Users <> Logic
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-01-18 : 14:34:47
Jim's the man with a plan


USE Northwind
GO

SET NOCOUNT ON
CREATE TABLE myTable99(Col1 int IDENTITY(1,1), Col2 datetime DEFAULT(GetDate()), Col3 char(1))
GO

INSERT INTO myTable99(Col3)
SELECT 'x' UNION ALL
SELECT 'y' UNION ALL
SELECT 'z'
GO

SELECT * FROM myTable99
GO

SET NOCOUNT OFF
DROP TABLE myTable99
GO





Brett

8-)
Go to Top of Page

darenkov
Yak Posting Veteran

90 Posts

Posted - 2005-01-19 : 01:02:34
thanks guys, thanks Brett
Go to Top of Page
   

- Advertisement -