Jan 3, 2012

Sql query to add a new column of all tables of given database in sql server


Sql query or script to add a new colunms in the all tables of given or specified database in sql server

EXECUTE sp_MSforeachtable  @command1 = N'ALTER TABLE ? ADD dtCreated DATETIME NOT NULL DEFAULT GETDATE()'

This query will add a new column dtCreated of data type data type in all the tables of current working database.

Note: sp_MSforeachtable is system stored procedure

1 comment:

  1. Abdul Haseeb10/11/2013

    Marvellous,

    Thank you so much

    ReplyDelete