How to use the undocumented stored procedure sp_msforeachtable to add a column to all tables in a database ?
There are two examples, in both I add a column to each tables except the spnet membership tables.
Example :
Add the “CreatedDate” column to all tables :
print ‘Add [CreatedDate] Column for each user table’
EXEC sp_msforeachtable
‘
– add column
exec(”
declare @tableName as nvarchar(max)
set @tableName = ””_?_””
IF (CHARINDEX(””aspnet_””,@tableName) = 0) — no aspnet membership
BEGIN
IF [...]
