Freddy
Freddy

Reputation: 319

Generate a column script

I'm looking to generate a script of specific table column. How i can do that?

SQL Server 2012 allow to generate a script of a single table but not a single column.

Upvotes: 0

Views: 68

Answers (1)

David
David

Reputation: 1611

There's no built in functionality to do this. In order to accomplish something like this, you would need to make a script that would go through the system tables to retrieve the information for the column then generate an ALTER TABLE [] ADD [] statement.

I do something like this with temp tables so you can see an example of what that might look like. I would note the code sample provided here is partially complete and updated whenever I encounter a corner case it doesn't cover already.

http://bigdatabigdave.info/archive/2013/03/08/scripting-create-table-statements-from-temp-table-definitions/

Upvotes: 1

Related Questions