SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to get Create script of an existing table


How to get Create script of an existing table

Author
Message
parsi_divya
parsi_divya
Valued Member
Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)

Group: General Forum Members
Points: 58 Visits: 24
Hi,

Is there any function which gives the table creation script.

something like below
create table <table>
(
id number,
name varchar(100))

Please help me.

I have found some approaches in google, where we need to create our function to achieve this
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=120447

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/generate-sql-script.aspx

Is there any predefined function which got introduced by MS SQL server itself


Thanks in advance
anthony.green
anthony.green
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23150 Visits: 6519
Easiest way is

In SSMS, expand database, expand tables, right click table, expand script table as, expand create to, click new query editor window.



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Lowell
Lowell
SSC Guru
SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)

Group: General Forum Members
Points: 68152 Visits: 40898
if you've gotta do it via TSQL, instead of stepping out via SMO to get it , i've spent a lot of time refining a few stored procedures to do that via TSQL.

sp_GetDDLa_Latest.txt returns a multi row table with the definitiion of any table, temp table, proc function or trigger.
sp_GetDDL_Latest.txt returns a single varchar(max) with the definitiion of any table, temp table, proc function or trigger.

both methods serve differnet functions; the first makes it REALLY readable.
the second is great when you want to stuff a CREATE TABLe definition into a field when auditing your scripts.

Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search