Also, use the information_schema.columns
Brett
Main Topics
Browse All Topics(almost) All tables in my db have a column named Who, that is used to stored the update user's id. the data type is nvarchar(20). I want to change it to smallint in ALL tables.
I don;t have to worry about the data that is already present. i can delete the column and re-create it with the changed datatype.
I could do it manually for each table using ALTER TABLE statement. (DROP first then ADD).
1 - I was wondering if i can do this programatically using T-SQL.
2 - How good/bad idea is it to manually edit the 'syscolumns' table ?
I tried following statements but looks like i can not pass a variable to ALTER TABLE statment.
ALTER TABLE @TableName DROP Column Who
ALTER TABLE @TableName ADD Who smallint NULL
where @TableName is declared as nvarchar(255) and is filled from the sysobjects table's Name column for Type='U'.
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.
Business Accounts
Answer for Membership
by: arbertPosted on 2004-05-09 at 18:06:44ID: 11027753
NEVER edit the system tables--very bad idea.
You can use dynamic sql for what you want:
declare @sql varchar(1000)
select @sql='alter table ' + @tablename ' + ' drop column who'
exec (@sql)
Brett