1

When I right click on the table name I click on select top 1000 rows and it gives me this script

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 1000 [response_id]
      ,[submitter]
      ,[submitterdept]
      ,[employee]
      ,[employeedept]
      ,[rating1]
      ,[rating2]
      ,[rating3]
      ,[rating4]
      ,[rating5]
      ,[commentpositive]
      ,[commentnegative]
      ,[star]
      ,[commentdate]
      ,[status]
      ,[approvedby]
      ,[approveddate]
      ,[execoffice_status]
      ,[execoffice_approvedby]
      ,[execoffice_date]
  FROM [Intranet].[dbo].[CSEReduxResponses]

How do I see the script of the table? There is nothing I have tried when I right click on the table that i can see the script.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3408399
  • 109
  • 1
  • 2
  • 12

3 Answers3

3

Here's one way:

  • Open SSMS
  • Open Object Explorer (hit F8)
  • Connect to a SQL instance
  • Open "Databases"
  • Open the desired database
  • Open "Tables"
  • Right-click on the desire table
  • In the menu, select "Script table as"
  • In the sub-menu, select "Create to"
  • In the sub-sub-menu, select "New Query Editor Window"

This will generate a create script and lod it into its own query window.

Here's more detail than you wanted:

  • From the SSMS menu, select Tools / Options
  • In the dialog window, select "SQL Server Object Explorer"
  • Select "Scripting"

Each of the items in the right-hand pane will control an aspect of how and what objects will be scripted by Object Explorer.

Philip Kelley
  • 39,426
  • 11
  • 57
  • 92
2

Go to your SSMS Righ click the Table and follow the path show as below

enter image description here

This will create the script of your table.

M.Ali
  • 67,945
  • 13
  • 101
  • 127
  • Thank you. Very different from what Im use to. – user3408399 Apr 08 '14 at 20:57
  • Not a problem glad to help :) – M.Ali Apr 08 '14 at 20:58
  • If i wanted to add a new column to table can I write in in the script and 'execute'? – user3408399 Apr 08 '14 at 21:00
  • This create script is good if you want to create this table in another database as this will try to create another table with the same name and you cannot have two table with the same name in a database. If you want to add a column then you need to use T-Sql Command for that, Using `ALTER TABLE` command, Read this question for more information on this [`Add a Column to an Existing Table`](http://stackoverflow.com/questions/92082/add-a-column-with-a-default-value-to-an-existing-table-in-sql-server) – M.Ali Apr 08 '14 at 21:03
0

Your results window isn't sized to where you can see the output. Look towards the bottom of your window, you should see results and messages. Drag it up to display your results. If your results window is completely hidden you can go to "Window" ---> Show Results Pane.

  • I can see the output and what is in the table. (Im not use to working with this software, im use to Toad Oracle). Shouldn't there be something that shows me the script, like 'CREATE TABLE...' when it was first created? – user3408399 Apr 08 '14 at 20:52
  • 1
    I'm not sure, but what it sounds like to me is that you may be looking for more of a stored procedure. In a stored procedure or Transact-SQL you would see the CREATE. When you use server management studio, a majority of the time you are probably just performing a SELECT statement. – user3512749 Apr 08 '14 at 21:00