Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Get table create code

Author  Topic 

asafg
Starting Member

39 Posts

Posted - 2008-12-24 : 04:17:08
A month ago I looked for a way to get the code of a stored procedure:

Someone gave me the sp_helptext method to get the code:


sp_helptext storedProcedureName

It works like magic for stored procedure,functions and views...
but it does not work for tables.

I'd like be able to get the code that created a certain table:

getcode(table_name)
result: "create table tablename( a as int,b as int)"

* A select query is great as well - select code from sysTables (or something like that)

Is there another magic method like sp_helptext?

Thanks
Asaf

raky
Aged Yak Warrior

767 Posts

Posted - 2008-12-24 : 04:31:39


Follow the below path to get Table Script for an already created table

Go to Management studio --> Select Database -- > Select table --> Left Click on Table Name --> u will get some options--> In that select script table as --> create to--> New Query Editor Window..

Then u will get script for the table in a new query window..
Go to Top of Page

asafg
Starting Member

39 Posts

Posted - 2008-12-24 : 04:43:25
Thanks...
I was lazy to explain what I want the way you did...

but what I really want is to see this code in my c# application in a textbox...
so what I'll do is in pseudo:

define query (as string/text)
define answer (as string/text - or table)

answer = getResultFromDB(query)

textbox content = answer

so what I'm really after, is the query, and not the code(at least for now ;) )
Go to Top of Page
   

- Advertisement -