ALTER TABLE BOMFE ALTER COLUMN [MFD] [bit] NULL DEFAULT (0)
doesn't work either
Main Topics
Browse All TopicsCan someone give me the syntax to add a default value to a column?
Somehow it doesn't want this
ALTER TABLE BOM ALTER COLUMN MFD DEFAULT 0 )
table is BOM, column is MFD (bit field) and the default value must get is 0
I have to loop through a hundred tables time 3 databases so I realy need the SQL to do this. Can't do it manually.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Actually, you cannot ALTER the DEFAULT value, only ADD a column with a DEFAULT value, or change the data type settings.
THis means that you need either of these workarounds:
1) redefine column
# add a new column (dummy name) with the correct default
# udate the table, copying the actual column to the new column
# drop the old column
# add the new column (old name) with the correct default
# update the table, copying the dummy column to the final column.
# drop the dummy column
Downside of this: If there are any indexes, foreign keys, views, triggers etc, they will either make that not work or need to be recompiled after this procedures in order to be consistent (you could run into "funny" situations if you don't)
2) redefine the table
similar as above, but you copy over the whole table to a new table
Downside of this: you need to know the whole table structure, and also need to recompile any triggers, procedures & views after this... even more disadvantage is that if you have large tables, this will take even much longer...
Sorry to say, but this is a "limitation" of SQL Server...
CHeers
use <your_catalog>
-- drop the constraint
alter table test1 drop constraint DF_test1
-- change columnType
alter table test1 alter column col5 int not null
-- add constraint and default value
alter table test1 add constraint [df_test1] default (1) for col5
-- note: not all conversions are allowed; check SQL Server Books Online -> CAST and CONVERT
-- like: from datetime to int
Business Accounts
Answer for Membership
by: lauszPosted on 2003-09-02 at 05:52:18ID: 9266797
May be you can create an stopred procedure an do this---
alter table adding a new field with your defaullt ,
then updating the old field by the new one
last, drop the old field...
an with the stored procedure you can use parameters (database, table, old field and new field )
Is only an idea!!!