In SQL Server, how do I generate a CREATE TABLE statement for a given table?

前端 未结 16 2424
离开以前
离开以前 2020-11-22 11:34

I\'ve spent a good amount of time coming up with solution to this problem, so in the spirit of this post, I\'m posting it here, since I think it might be useful to others. <

16条回答
  •  爱一瞬间的悲伤
    2020-11-22 11:44

    Credit due to @Blorgbeard for sharing his script. I'll certainly bookmark it in case I need it.

    Yes, you can "right click" on the table and script the CREATE TABLE script, but:

    • The a script will contain loads of cruft (interested in the extended properties anyone?)
    • If you have 200+ tables in your schema, it's going to take you half a day to script the lot by hand.

    With this script converted into a stored procedure, and combined with a wrapper script you would have a nice automated way to dump your table design into source control etc.

    The rest of your DB code (SP's, FK indexes, Triggers etc) would be under source control anyway ;)

提交回复
热议问题