Groups | Blog | Home
all groups > sql server mseq > october 2003 >

sql server mseq : ALTER TABLE changing DEFAULT value



Dale
10/2/2003 11:54:50 AM
Hello,

I am frustrated. I have searched numerous websites
without the correct answer. I have a column:
FlgOne varchar(5) not null default 'inx'

I want to change the default of 'inx' to 'ppb'

ALTER TABLE invoices ALTER COLUMN FlgOne DEFAULT 'ppb'
does not work. What is the correct syntax to set the
default of a column that has already been defined?

Regards,
Vishal Parkar
10/3/2003 3:41:11 PM
Default is a constraint you will have to drop it before assigning new default to a column.

Ex:
CREATE TABLE test1233 (b varchar(500))
--create a new default
ALTER TABLE test1233 ADD CONSTRAINT def_b1 DEFAULT 'vishal' FOR b
--inserting default values
insert into test1233 default values
--check the rows
select * from test1233
--drop old default constraint
alter table test1233 drop constraint def_b1
Note:
to know existing default constraint name on the table run following command.

sp_helpconstraint <table>

--create new default constraint
ALTER TABLE test1233 ADD CONSTRAINT def_b1 DEFAULT 'vikram' FOR b
--insert new default values
insert into test1233 default values



--
- Vishal

AddThis Social Bookmark Button