tags:

views:

338

answers:

2

When we need the query of stored procedures we use 'Sp_Helptext procedurename'

Can something similar be done for tables?

+1  A: 

There does not appear to be a direct equivalent of sp_helptext that will work with tables.

The two methods that seem to be common on various message boards are:

  1. Use Information_Schema.Columns and concatenate the results into the create statement.
  2. Use SQL-DMO script

There is an article on the second method here

David Hall
A couple of examples of the first method can be seen at http://social.msdn.microsoft.com/Forums/en/transactsql/thread/28eeb603-1607-4b56-9461-3c0502cbec9c - it's some pretty hairy SQL though
Dan F
@Dan F lol - I guess you checked the first result for 'sp_helptext table' in google as well :)
David Hall
@David: Haha, yep, I had an inkling it'd be an easy google :-)
Dan F
A: 

Please use followig query

select * from information_Schema.columns where table_name = 'TableName'

Paresh