1

I have read only permission on a SQL Server 2005 database, and I'm looking to get a table schema locally to work with. With my current access it won't let me right click on the table and choose 'Create Table' to get the script for this.

Is there a way to generate the create table script from a select statement or by some other mechanism?

Thank you!

Mormegil
  • 7,955
  • 4
  • 42
  • 77
user53885
  • 3,809
  • 11
  • 33
  • 43
  • 1
    Would you be happy with a solution that just gave columns and datatypes? Actually how do you get on with the script here http://stackoverflow.com/questions/21547/in-sql-server-how-do-i-generate-a-create-table-statement-for-a-given-table/21551#21551 – Martin Smith Mar 26 '11 at 21:15

2 Answers2

2

It's a bit long but the script in Script Table Definitions using TSQL could be addapted to work without needing to create the stored procedure mentioned.

I am assuming you are working with SQL Server 2005

Brad
  • 11,934
  • 4
  • 45
  • 73
Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
2

You could create a linked server on your local machine. Then, you can use select ... into to copy the table, including data:

select  *
into    NewTableName
from    [LinkedServerName].[DatabaseName].dbo.TableName

This will not copy indexes or constraints. To exclude the data, use select top 0 *.

Andomar
  • 232,371
  • 49
  • 380
  • 404