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)
 brainfart....

Author  Topic 

mikejohnson
Posting Yak Master

153 Posts

Posted - 2003-05-19 : 15:03:07
Can't remember any Default Values when it comes to designing a table. I'm looking to automatically insert the date for each record once inserted. Can't believe I can't remember this. Also, do you know of a site that has a nice list of items that are valid for the 'Default Value'?
Thanks,
mike

nr
SQLTeam MVY

12543 Posts

Posted - 2003-05-19 : 15:24:03
datetime default getdate()
?

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-05-19 : 15:35:23

Here's a sample Alter. BTW Created_TS is not really a timestamp datatype. It was a DB2 Programmer who did the design (its datetime)


ALTER TABLE [dbo].[Company] WITH NOCHECK ADD
CONSTRAINT [cons_Company_Created_Ts] DEFAULT (getdate()) FOR [Created_Ts],
PRIMARY KEY CLUSTERED
(
[Company_Name]
) WITH FILLFACTOR = 90 ON [PRIMARY]


Brett

8-)
Go to Top of Page

chadmat
The Chadinator

1974 Posts

Posted - 2003-05-20 : 01:28:26
Valid values for the default are any value of the column's datatype.

-Chad

http://www.clrsoft.com

Software built for the Common Language Runtime.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-05-20 : 11:25:23
I'm still amazed...I understand, though from what everyone has posted in a previous thread, but also would like to know of a practical application (other than it's easier to use 0):


USE NorthWind
GO
CREATE TABLE myTable(col1 int IDENTITY(1,1), col2 datetime, col3 char(1))
GO
ALTER TABLE [dbo].[myTable] WITH NOCHECK ADD
CONSTRAINT [cons_myTable_col2] DEFAULT (0) FOR [Col2],
PRIMARY KEY CLUSTERED
(
[col1]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
INSERT INTO myTable(col3) SELECT 'X'
GO
SELECT * FROM myTable
GO
DROP TABLE myTable
GO



Brett

8-)
Go to Top of Page
   

- Advertisement -