show Create commands for table in SQL Management Studio (2008) - sql

I've just started with SQL Management Studio and I am wondering if I can show create commands for already existing tables, I've been able to do that in Oracle SQL Developer.. I've tried to ask uncle google but maybe used just wrong search command.. Anyway.. could someone give me quick hint as I stuck with this for like 25 minutes?
Thanks

In Object Explorer, expand your server/database, expand Tables, right-click the table in question, and choose Script Table as > CREATE To > New Query Editor Window.
If you want to script multiple tables, you can turn on Object Explorer Details (F7 or from the View menu), highlight "Tables" on the left, then use Shift+ or Ctrl+ to select multiple tables in the right pane (just like you would select multiple files in Windows Explorer). Then you can do the same thing, right-click, Script Table as > ...

If you want to generate script for one table, right click a table and select "Script table as", you get all sorts of options including creating the create script of the table.
If you want to generate scripts for more than one table, you have option
to generate for many at once. Just follow the wizard instructions.

Related

Is there an SQL editor for the data itself?

I'm looking for an SQL (MSSQL) tool that will allow me to edit/insert/etc. data without the need to type sql statements. I want to simply enter data into a grid. I can't find this functionality in SSMS. Is there any tool that does that (preferably by MS)?
Table Editor
If you right-click on a table in SSMS and click edit, you can edit the data in there directly.
Query Designer
If you select a row or cell in the table editor, you have access to the Query Designer menu on the tool bar. By clicking on the pane menu, it will open a sub-menu that will give you access to the SQL, Criteria and a Diagram. This will allow you to design queries visually.
SSMS does let you do it, although it's not a great tool by any stretch. If you right click on a table and go to Edit Top 100 rows, you can get the grid. If you want to be able to edit any number of rows, go to Tools -> Options -> SQL Server Object Explorer -> Commands and change both values in the Table and View options to 0, which means unlimited.
You can also edit the query that is used to generate the grid. In the toolbar, there's a button that says SQL and the hovertext is "Show SQL Pane". You can then edit the SQL to include/exclude columns or add conditions. This may help with large tables. You can also use this method to overcome the row number limit if you didn't change the defaults as in the above paragraph.
Right click the table in SSMS and click Edit Top 200 Rows:.
Using MS SQL Managment Studio you can right click on a table and select Edit. This will let you edit existing rows and add new rows by just typing into the 'grid'.
try this. may be this can help
http://www.toadworld.com/platforms/sql-server/w/wiki/10392.editing-an-sql-server-table-in-excel.aspx
A real easy thing to do is to use Access as a front end to SQL Server. It would take only a few minutes to create an ODBC connection from Access to SQL Server and you can quickly use Access's grids and forms to enter data.

Dropping and recreating database, along with tables

I have a database whose structure I'm happy with, but which has a fair amount of dummy data in it. I would like to drop and recreate the database while at the same time wiping out the tables, but retain the table structures and relationships.
When I right-click on the database and choose to script 'drop and create' statements they're for the database itself, but no mention of the tables within-- unless I'm missing something.
Is it possible to generate a script that drops/creates a database and the tables within? I can individually select each table and script out their drop/create statements and order things so it will work, but are there other ways of doing this in one swoop?
I have a localized version of Sql Server 2008 R2, so some of my instructions could be imprecise.
I hope that there are no big differences.
Right click on your database and select Tasks and then Generate Scripts
Leave the first option selected (Build script for all db and objects) and select next
On the second page click Advanced
Select the option to Build Script for DROP & CREATE
Select the option to Use only the Schema (not Schema and Data)
Check the other options you would like to use.
Finally choose your save options and click Next until SSMS creates the script
Instead of that you should do this. That way you can select different tables or stored procedure to script for. See MSDN How to: Generate a Script (SQL Server Management Studio) on how to do it step-by-step.
Right click on DB_Name -> select tasks -> Generate Scripts

How to generate select or insert script of table using SSDT in Visual Studio

Is it possible to generate select or insert script of one table using SSDT in Visual Studio 2013?
I came across this entry hoping it would answer this question: how do I script out the data in a table? I've used SSMS in the past to generate the INSERT statements that would load the data back into a table.
These are the steps in VS 2013/SSDT 2014:
Using the SQL Server Object Explorer pane, right click on the table name, choose View Data.
At the top of the data pane is label Max Rows with combo box, choose All.
Click on scroll/script icon to right of box and it will produce script of insert statements.
The next icon to the right will send the statements straight to file.

How do I export a table's data into INSERT statements?

How can I export a table from a SQL Server 2000 database to a .sql file as a bunch of INSERT INTO statements?
One of the fields in the table is a Text datatype and holds HTML so doing this by hand would be rather time-consuming.
I have access to SQL Server Management Studio 2008 to access the SQL Server 2000 database.
Updating since this Q&A was at the top of the search results when I was looking for the answer.
In MSSQL 2008 R2:
Right Click on database: Tasks -> Generate Scripts...
The Generate and Publish Scripts dialog will pop up. The Intro page is worthless. Click "Next"
Choose "Select Specific database objects" and then select the Table(s) you want to get Inserts for. Click Next and the dialog will advance to the "Set Scripting Options".
Click on Advanced and you should see:
Scroll down the list of Options until you find "Types of data to script". Click on that row and choose "Data Only" from the pull-down. Click "OK". Choose your Save options and click "Next" a few times.
Note - The output also includes the following after every 100 inserts.
GO
print 'Processed 200 total records'
Check out the SSMS Tool Pack - it's a great, FREE add-on for SQL Server Management Studio which does a lot of things - among other it can generate INSERT statements from a given table.
I have been using this stored procedure for a long time: sp_generate_inserts: the 2000 version and the 2005 (and up) version.
You use it like this:
sp_generate_inserts 'thetablename'
or if you want to filter:
sp_generate_inserts 'thetablename', #from='from ... where ... order by ...'
The sp will return inserts statements as query results. Don't forget to modify setting: increase the maximum number of characters displayed in each column (tools - options - query results).
If you can use other DB management apps the quickest way would be using a tool like SqlDbx which has a built-in "Export as inserts (SQL)" function (just execute a query like SELECT * FROM Table and then use the contextual menu from the result grid).
If you need to stick to SQL Management Studio then you could use a stored procedure like this one:
http://vyaskn.tripod.com/code/generate_inserts.txt
It generates a set of results with the SQL INSERT statement for each row of the target table. Then you can exports the results to a file, or just copy them to the clipboard and paste in the query window (it works fine even with several megabytes of data).

How to create automatically a table populate script from current data in SQL Server?

Is there a tool that allows me to create a sql populate script for a table using its current data?
Old question, but I got to the question before figuring out a way to solve the problem. So I'm just posting the method here in case it might help anyone else.
In SSMS:
Right click on db -> "Tasks" -> "Generate Scripts..."
Click "Next" and, at "Choose Objects" step, select the specific table
Click "Next" and, at "Set Scription Options" step, click "Advanced"
Set value for "Type of data to script", depending on what you need
Continue to finish
Check out the SSMS Addins (for both SSMS 2005 and 2008):
alt text http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=SSMSAddins&DownloadId=48526
One of the tools included in the "DataScripter" which will script out INSERT statements for the table(s) you want to.
Maybe this is just enough for you: http://snipplr.com/view/12003/generate-insert-statements/
You could look at purchasing the Data Generator by Red-Gate which can create random sets of data based on your database schema.
Note: I'm not sure if the tool will generate data based on your current data though
You can do it with Database Publishing Wizard. Here is a tutorial: Generate Script with Data from Database – Database Publishing Wizard
Another way to do it, even more convenient for developers, is within Visual Studio 2015 or 2017 (possibly earlier versions too):
Main menu 'View' -> 'SQL Server Object Explorer'
In the tree view connect to the Database of choice and select a table
Right click on the table and select 'View Data' menu item
In the [Data] window click on a 'Script' or 'Script to File' button