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
 General SQL Server Forums
 New to SQL Server Programming
 Default datetime value

Author  Topic 

kayode
Starting Member

1 Post

Posted - 2006-12-29 : 06:21:11
How could one assign a datetime default value in SQL Server 2005?
and how could one assign a composite key in SQL Server? an anyone help?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-29 : 06:55:45
Since CREATE DEFAULT is not supported in SQL 2005, I guess you have to do it at table definition level:

Create Table abc
(
datecol datetime default(getdate())
)


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2006-12-29 : 09:22:43
Ummmm... DEFAULTs are really CONSTRAINTs... you can add a constraint that is a default. BOL has an example as follows...

CREATE TABLE doc_exz ( column_a INT, column_b INT) ;
GO
INSERT INTO doc_exz (column_a)
VALUES ( 7 ) ;
GO
ALTER TABLE doc_exz
ADD CONSTRAINT col_b_def
DEFAULT 50 FOR column_b ;

GO
INSERT INTO doc_exz (column_a)
VALUES ( 10 ) ;
GO
SELECT * FROM doc_exz ;
GO
DROP TABLE doc_exz ;
GO

Here's the online link for the above...
[url]http://msdn2.microsoft.com/en-us/library/ms190273.aspx[/url]
So far as the composite key thing goes... I strongly recommend that you lookup the above link as it has everything you need for your question. All you have to do is use more than 1 column name in the parenthesis... like this...
ALTER TABLE yourtable
ADD CONSTRAINT PK_yourtable_columnnames
PRIMARY KEY CLUSTERED (list of column names)

--Jeff Moden
Go to Top of Page
   

- Advertisement -