0

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.

7
  • What are you asking for? MyColumn int? Commented Nov 19, 2013 at 19:52
  • What type of script you want to create? Commented Nov 19, 2013 at 19:52
  • 1
    Do you mean the script to add a new column? Commented Nov 19, 2013 at 19:54
  • 1
    I don't think you are asking for what you think you are asking for. The scripts you generage can CREATE a table, veiw, function, or a stored procedure. You can't make just a column. That would then be a one column table. Commented Nov 19, 2013 at 19:54
  • @Zane i'm looking to generate a create script i just want a column of the table not the complete table script. Commented Nov 19, 2013 at 20:05

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

2 Comments

I'm not even sure that's what the OP is asking.
Just my best guess for what he's looking for. Not much to go on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.