Saturday, February 25, 2012

Add field to multiple tables

How can I add one or two fields to about 50 tables without having to go into
each one seperately?Write a Transact-SQL script.
"scuba79" <scuba79@.discussions.microsoft.com> wrote in message
news:C6DDC84D-5D08-415A-8805-392465AA6041@.microsoft.com...
> How can I add one or two fields to about 50 tables without having to go
> into
> each one seperately?|||Brian,
Are you saying that is possible through a TSQL script to do this? If so, do
you have any examples that could assist me with this?
Thanks
Scuba79
"Brian Selzer" wrote:

> Write a Transact-SQL script.
> "scuba79" <scuba79@.discussions.microsoft.com> wrote in message
> news:C6DDC84D-5D08-415A-8805-392465AA6041@.microsoft.com...
>
>|||SELECT 'ALTER TABLE [' + LTRIM(RTRIM(TABLE_NAME)) + '] ADD Column1 INT NOT
NULL DEFAULT(0), Column2 CHAR(8) NOT NULL DEFAULT('''')' FROM
INFORMATION_SCHEMA.TABLES
"scuba79" <scuba79@.discussions.microsoft.com> wrote in message
news:EA1FEFB2-62B2-4B4B-9E9F-51404BA4E560@.microsoft.com...
> Brian,
> Are you saying that is possible through a TSQL script to do this? If so,
> do
> you have any examples that could assist me with this?
> Thanks
> Scuba79
> "Brian Selzer" wrote:
>|||Brian,
Thanks for the assistance, this is exactly what I needed to know.
Scuba79
"Brian Selzer" wrote:

> SELECT 'ALTER TABLE [' + LTRIM(RTRIM(TABLE_NAME)) + '] ADD Column1 INT NOT
> NULL DEFAULT(0), Column2 CHAR(8) NOT NULL DEFAULT('''')' FROM
> INFORMATION_SCHEMA.TABLES
>
> "scuba79" <scuba79@.discussions.microsoft.com> wrote in message
> news:EA1FEFB2-62B2-4B4B-9E9F-51404BA4E560@.microsoft.com...
>
>

No comments:

Post a Comment