Saturday, February 25, 2012

alter column for every tables

I got one same tables in 10 database, and I need to amend one field from
'null' to 'not null'
Can I do it by script ' Please helpAgnes
Do the table have data?
If you don't
CREATE TABLE #Test (col1 INT NULL)
--No data
ALTER TABLE #Test ALTER COLUMN col1 INT NOT NULL
If you do have a data
CREATE TABLE t(c1 int null)
insert t values(1)
SELECT c1 INTO tA FROM t
SELECT ISNULL(c1, 0) AS c1 INTO tB FROM t
EXEC sp_help tA
EXEC sp_help tB
Note
USE database_name;
EXEC sp_rename ...
Unfortunately, sp_rename doesn't allow you to specify the database name,
rather it will run in the context of the "current" database.
"Agnes" <agnes@.dynamictech.com.hk> wrote in message
news:eLUNghRMGHA.3896@.TK2MSFTNGP15.phx.gbl...
>I got one same tables in 10 database, and I need to amend one field from
>'null' to 'not null'
> Can I do it by script ' Please help
>

No comments:

Post a Comment