tags:

views:

29

answers:

1

In Microsoft SQL Server, I want to alter a field to "NOT NULL" AND DEFAULT ''. I've already issued the following two commands:

ALTER TABLE USR ADD Country Varchar(128)
UPDATE USR SET Country=''

Now I need

1. ALTER TABLE USR ADD CONSTRAINT CountryIsNotNull something
2. ALTER TABLE USR ADD CONSTRAINT CountryDefault default ''
+2  A: 

You should be able to google it however here is the syntax:

ALTER TABLE USR
ALTER COLUMN Country varchar(128) NOT NULL 
go
ALTER TABLE USR
ADD CONSTRAINT df_usr_conuntry_default DEFAULT '' for Country
go

You could have done the whole thing in one line though with the following:

alter table USR 
add Country varchar(128) not null default '' with values
Joshua Cauble
Thanks! In your second example, the word column needs to be removed.
cf_PhillipSenn
thanks, did not run it but the sql syntax checker actually let it through on my box. removed it.
Joshua Cauble