Showing posts with label ALTER COLUMN. Show all posts
Showing posts with label ALTER COLUMN. Show all posts

Friday, December 20, 2013

Generate script for ALTER DB column Data for all tables available in DB

Run Below query to generate script:

SELECT
'ALTER TABLE ' + TABLE_NAME + ' ALTER COLUMN Createdby varchar(50) ;' +
'ALTER TABLE ' + TABLE_NAME + ' ALTER COLUMN Updatedby varchar(50) ;' AS Script
FROM INFORMATION_SCHEMA.TABLES

Take care of following items:

  • Above query generate scripts for all the tables which were created in that database, deleted tables are also included in it.
  • If tables contains that field or not it will generate script for that table also. Manually you have to remove that table script to run the generated scripts.
  • CreatedBy and UpdatedBy is the field name of the tables which I want to update.
  • Above query generates script for 2 fields, if you want to increase or decrease you have to update above query as per your requirement.