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
 Other Forums
 MS Access
 Create Table

Author  Topic 

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-05-22 : 01:34:10
Dear All,
How can I add a Default value and Set the Field as identy in a create table query statement

Thnks
Dana

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-22 : 01:37:28
[code]-- creating identity column
create table xyz
(
col1 int identity(1,1)
)

-- creating default value
create table pqr
(
col1 int default(0)
)[/code]

or you can create default using CREATE DEFAULT and bind it later using sp_bindefault.

But, you can't have both identity and default on same column at a time.

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

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-05-22 : 01:50:29
Dear Harsh,
Thanks for Your Reply.How can combine both these?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-22 : 02:01:44
I already told you can't have default on identity column.

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

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-05-22 : 02:34:28
Thanks Harsh,
How to set a string value as a Default value ?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-22 : 02:40:21
Similar to what I shown for INT column.

create table xyz
(
col1 varchar(50) default 'MyDefault'
)




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

danasegarane76
Posting Yak Master

242 Posts

Posted - 2007-05-22 : 04:57:26
Thanks Harsh :)
Go to Top of Page
   

- Advertisement -