September 16, 2011 at 10:35 am
I have 15 tables that need the same column i.e. the column is identical in its and i have to do this via a sql script
Can i add all these columns to multiple tables with a single alter, and then update them with the same value. Please if anyone can point me anywhere that would be awesome.
September 16, 2011 at 10:57 am
You can do it with a single script but not a single alter.
Each table affected will need to have an alter statement.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
September 16, 2011 at 11:18 am
Thanks Jason
as i sort of knew it was hihgly unlikely but i just wanted to see if someone had an idea
thanks again
September 16, 2011 at 11:26 am
you can wrap the commands for all 15 alters in a single transaction though...so you can make sure it's all or nothing.
SET XACT_ABORT ON --bailout and rollback on any error in a transaction
BEGIN TRAN
ALTER TABLE Orders ADD CreatedDate datetime default getdate()
ALTER TABLE Orders2 ADD CreatedDate datetime default getdate()
--etc
COMMIT TRAN
Lowell
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply