6

I create about 15 tables and create relationships and constraints among them using Wizard in SQL Server 2012 express

Now i want to see the query that is used to create those tables including relationships and constraints. Can u provide help?

Thank you.

Topman
  • 306
  • 1
  • 4
  • 14

3 Answers3

11
  1. Connect to your database using SQL Server Manager Studio
  2. Right-click the table or the view in the Object Explorer panel
  3. From the context menu choose Script Table as.../CREATE to.../< SomeDestination >
  4. Choose a destination (a file, the clip board, etc.)

Screenshot

This would give you access to the DDL SQL that can be used to create this table.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • I got the statement but i find it complex sir. It includes such as: `CREATE TABLE [dbo].[Author]( [AuthorId] [int] NOT NULL, [FirstName] [nvarchar](70) NOT NULL, [LastName] [nvarchar](35) NOT NULL, CONSTRAINT [PK_AUTHOR] PRIMARY KEY CLUSTERED ( [AuthorId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]` Can we get _simple statement_ than this 'cause i don't know anything about: PAD_INDEX, STATISTICS_NORECOMPUTE,etc. – Topman Apr 04 '15 at 09:51
  • @KnockKnock That's true - SQL Management Studio makes all DB's assumptions explicit in this statement, so that if you were to re-create the object in another database, the result would come out exactly the same. – Sergey Kalinichenko Apr 04 '15 at 09:53
2

There are two ways within SSMS to view the SQL statement (known as Data Definition Language, or DDL) used to create a table.

  1. Right-click the table and choose "Script Table as", "CREATE To" and choose your destination. This method is easiest if you just want to view the DDL for a single table quickly.
  2. Right-click the database and choose "Tasks", "Generate Scripts" and follow the prompts. This method will generate DDL for all tables and many other database objects depending on your selection.

Either method will show constraints, indexes and metadata.

dartonw
  • 300
  • 1
  • 6
0
  1. Right click on the table you want to get the details
  2. Script table as
  3. Create to
  4. New query editor window/ Clipboard

If you select Clipboard, then open a new query window and paste it there.

That's it.

Apart from that there is another thing you could do.

If you want to see all constraints, keys, references stuff just click on the table name in a query and Press Alt + F1 It will list down more technical details

oshan2csd
  • 393
  • 4
  • 11