SQL- Editing the 10 most recent rows in a table [duplicate] - sql

In SQL Server 2008 Management Studio, when I right click on a database table and choose Select Top 100 Rows, I can then e.g. easily add a ORDER BY statement to the SQL. That works fine.
But when I do choose Edit Top 200 Rows, I don't have the ability to alter the SQL (which makes it hard to find and edit a record just added in the 10,000 that are there.
I am quite sure I was able to do this in SQL Server 2000.
Is there any way in SMSS 2008 to alter the way the records are displayed when editing records?

If you right click on any result of "Edit Top 200 Rows" query in SSMS you will see the option "Pane -> SQL". It then shows the SQL Query that was run, which you can edit as you wish.
In SMSS 2012 and 2008, you can use Ctrl+3 to quickly get there.

You can also change the pop-up options themselves, to be more convenient for your normal use. Summary:
Run the SQL Management Studio Express 2008
Click the Tools -> Options
Select SQL Server Object Explorer . Now you should be able to see the options
Value for Edit Top Rows Command
Value for Select Top Rows Command
Give the Values 0 here to select/ Edit all the Records
Full Instructions with screenshots are here: http://m-elshazly.blogspot.com/2011/01/sql-server-2008-change-edit-top-200.html

Very quick and easy visual instructions to change this (and the select top 1000) for 2008 R2 through SSMS GUI
http://bradmarsh.net/index.php/2008/04/21/sql-2008-change-edit-top-200-rows/
Summary:
Go to Tools menu -> Options -> SQL Server Object Explorer
Expand SQL Server Object Explorer
Choose 'Commands'
For 'Value for Edit Top Rows' command, specify '0' to edit all rows

Follow the above image to edit rows from 200 to 100,000 Rows

Ctrl+3 in SQL Server 2012. Might work in 2008 too

in SQL 2017 You can do it more easily in the toolbar to the right just hit
the SQL button then its gonna apear the query with the top 200 you edit until the quantity that You want and Execute the query and Done! just Edit

Similar to David Hall's response, if you are a non-coder, it may be easiest to right-click within results, then choose Pane > Criteria. This allows you to adjust sort, add filters, etc... without adjusting SQL code.

The default to open/add rows to a table is Edit Top 200 Rows. If you have more than 200 rows, like me now, then you need to change the default setting. Here's what I did to change the edit default to 300:
Go to Tools in top nav
Select options, then SQL Service Object Explorer (on left)
On right side of panel, click into the field that contains 200 and change to 300 (or whatever number you wish)
Click OK and voila, you're all set!

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.

Why SQL Server 2008 Management Studio doesn't have option "Open table"

I used to have option to open table in SQL Server 2005 Management Studio, but don't have that anymore in the 2008 version. Does anybody know why this option has been removed? And, if this feature is no longer available in the 2008 version, what is the best alternative to use?
Now it's Edit Top 200 rows.
They did this cause people were opening huge tables without thinking.
If you want to see 2000 rows, you can edit the select query when you right click -> pane -> SQL.
Then in your sql statement you will see Top(200). you just have to change to the number of rows you need.
The option is still there, it's just been renamed. I believe the old version used to attempt to get every single record in the table. The revised SSMS will, by default, get only the first 200.
Right-click a table and select Edit Top 200 Rows as shown below:
its good to change it like-
tools-> options ->SQL server object explorer -> commands --in this we can edit for whichever rows..

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

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.

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 can I get Management Studio 2005 to copy the headers from result sets?

By default when you copy/paste data from a query window in SSMS it does not copy the column headings. How can I get these headers to be copied along with the data?
Open Tools menu
Open Options...
Expand Query Results
Expand SQL Server
Expand Results to Grid
Check Include column headers when copying or saving the results
Note that this will only work on the "New Query" types of windows -- not the "Open table" (editable) windows.
Results with headers was added in SSMS 2008. Ctrl-Shift-C works as well.
You can just right click the results, and select "Copy with headers"