Friday, February 5, 2010

Use a DEFAULT for several columns

Sometimes you need to set a default value for multiple columns. Why don't you create a DEFAULT and bind it to them instead of setting default value one by one.
CREATE TABLE tblTest1(Status varchar(10));
CREATE TABLE tblTest2(Status varchar(10));
CREATE DEFAULT dfStatus AS 'Active';
-- Bind default
EXEC sp_bindefault N'dfStatus', N'tblTest1.Status';
EXEC sp_bindefault N'dfStatus', N'tblTest2.Status';
-- Unind default
EXEC sp_unbindefault N'tblTest1.Status';
EXEC sp_unbindefault N'tblTest2.Status';

No comments:

Post a Comment

Oracle Query