Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to drop all columns in all databases starting with... AND how to drop the default constraint

$
0
0

I am trying to drop some columns from all tables in a database.  I can generate multiple scripts on all databases (see below) but how can I now execute them automatically without copying and pasting and executing the generated script multiple times?  AND the second issue will be dropping any default constraints.  Anyone have a script that can do both?  thanks.


EDIT: Corrected script which no longer gives me constraint error

EXEC sp_MSforeachdb 'USE ?
Select ''USE ? ALTER TABLE [dbo].[''+TABLE_NAME +''] DROP COLUMN ''+COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE COLUMN_NAME Like ''myField[3-9]%''
'


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>