Last post May 13, 2011 04:57 PM by imauld
Jun 26, 2008 04:35 PM|marchnw|LINK
Is there a way to set all the columns in a table to a default value. I have several tables with about 500 columns each. Each column needs to have the default value set to 0. I've done two of the tables already but figured there might be an easier way than
manually setting each column. Besides I might learn something new. Thanks
Jun 26, 2008 05:04 PM|budugu|LINK
To specify the default value in a SQL statement , DEFAULT keyword will be used
Check this SQL...
CREATE TABLE Employees(
State char(2) DEFAULT 'NJ',
PostalCode int default 2000,
Country varchar(26) default 'Australia');
Make sure you click "Mark as Answer" for any post which has helped you.
Jun 26, 2008 05:10 PM|marchnw|LINK
Ok. That's what I thought. The tables have already been scripted and I didn't want to have to write "default (0)," 500 times.
Good old Ctrl-V makes it a little better.
Jun 26, 2008 05:15 PM|LockH|LINK
Find/Replace is a great invention.
Needs two or three passes,
change "int" to "int default 0"
change ")" to ") default 0"
May 13, 2011 04:57 PM|imauld|LINK
If I already have a table is it possible to edit it to have a default value by using a similar SQL query?