Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Adding a column to all the tables

Author  Topic 

akshayaarora
Starting Member

1 Post

Posted - 2005-08-03 : 16:36:52
How to add a column (one particular column) to all the existing user defined tables in a database in SQL Server 2000?

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-08-03 : 16:38:31
Loop through INFORMATION_SCHEMA.TABLES and use dynamic SQL to execute ALTER TABLE ADD ColumnName...

Tara
Go to Top of Page

Hunglech
Starting Member

16 Posts

Posted - 2005-08-04 : 03:58:11
SELECT 'ALTER TABLE ' + name + ' ADD ColumnName Type' FROM sysobjects WHERE type = 'U'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-04 : 04:09:19
It is better to avoid using system tables
As Tara said, use this

Select 'Alter table '+table_name+' add columname Type' from
information_Schema.tables where table_type='Base Table'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -