SQL Server 2012 how do I view data? - sql

I have several tables in my database and I am using the SQL Server Management Studio for the first time. I want to see the data. In an SQLite 3 or MySQL
I'd simply type SELECT * FROM tblName WHERE...
the output would be in my console.

In SSMS open a new query window (Ctrl + n), make sure the database is selected from the databases dropdown (Ctrl + d to focus to the list, then up/down arrows and Enter to select the DB), write the query and F5 to run.
You can use the mouse for all of the above (there is a toolbar button for new query window, and you can use the mouse for selecting the DB).
An alternative is to use the object browser to drill down to the database and table in question, right click on the table name and select the "Select top 1000 rows..." (or similar) option.

In SSMS, hit the 'new query' button, which should be right under the "file edit view..." menu.
You'll get a blank window where you can type the SQL, with the results showing up underneath.
You'll also get an extra toolbar to select the default table, unless you do a use yourdb; query as the first operation in the query window.

Couple of ideas:
With SSMS:
Connect to server > database > tables > Right click and select top 1000.
Click New Query and type
SELECT * FROM TABLE
Use osql or sqlcmd

To view data in SQL Server Studio
Run this command : select * from (your table name)

Related

Pentaho Report Designer - there is no field appears

I am using Pentaho Report Designer 7. The database connection is OK.
Now, I wonder why on the Data Tab on the right side. There is no fields from the query that I can click and drag it to the report?
It only show me the available Query names but NOT the fields that I can click and drag to the report.
If your query is working fine(if you have checked at database level),in that case two possibility.
Case 1: In old PRD version you have to specify limit clause then only fields will appear which is quit a strange thing but is the solution.
Example : select * from tablename limit 100000;
Case 2 : if issue is not getting resolved by doing case 1 then, you have to right click on the queryname and click on select query.
You can do a right click on the query and select that query. It should show you output fields of that query.

How do I give myself read permission for a local Access table?

I'm trying to see if my SQL statement (MS Access) does what it should in Visual Studio by creating a connection to it and then running the query in the Server Explorer.
I want to find out if there's any difference between these two queries:
SELECT duckbill_.id, duckbill_.pack_size, duckbill_.description, duckbill_.vendor_id, duckbill_.department, duckbill_.subdepartment, duckbill_.unit_cost, duckbill_.unit_list, duckbill_.open_qty, duckbill_.UPC_code,
duckbill_.UPC_pack_size, duckbill_.crv_id, duckbill__vendors.vendor_item
FROM duckbill_, duckbill__vendors
WHERE (duckbill_.vendor_id = duckbill__vendors.vendor_id)
and:
SELECT duckbill_.id, duckbill_.pack_size, duckbill_.description, duckbill_.vendor_id, duckbill_.department, duckbill_.subdepartment, duckbill_.unit_cost, duckbill_.unit_list, duckbill_.open_qty, duckbill_.UPC_code,
duckbill_.UPC_pack_size, duckbill_.crv_id, duckbill__vendors.vendor_item
FROM (duckbill_ LEFT OUTER JOIN
duckbill__vendors ON duckbill_.vendor_id = duckbill__vendors.vendor_id)
...but it won't even let me execute the query. I can connect to the database, but apparently not to the individual tables. I get this error:
*SQL Execution Error
<My SQL statement>
Error Message: Record(s) cannot be read; no read permission on 'duckbill_'.*
How can I solve that?
I still wanted to do this in Visual Studio's server explorer (or any other Jet query tool). Here's what I did to fix it:
Shift + double click the mdb file
Go to the Database Tools tab
Click Users and Permissions > User and Group Permissions
If no users show up here, you may first need to visit Users and Permissions > User and Group Accounts to create one.
Select the Admin user which I connect with
Under "Object Name:" click the top item, then shift click the last table to select them all
Click all permissions check boxes (or the read-only ones, if you prefer)
Apply; close Access.
Now Visual Studio's Server Explorer was able to connect and run queries under the "Admin" user.
I was able to find out what I need to do:
Won) In Windows Explorer, hold shift and 2-click the MDB you want to work with.
Too) In Access, select Objects | Queries, then "Create query in Design view"
3) Close the "Show table" dialog
Fore) Right-click in the pane and select "SQL View"
You now have a blank canvas on which to "do your damage"

Edit selected rows manually in SQL Server

I have a database in which some editing operations have to be done manually on some rows. I have the SQL Server Management Studio Express. In SSMS, to edit the rows, normally the option is:
Select DB > Table > Right Click > Edit top 200 rows
But, the problem here is that I only have to edit some selected rows. I am able to retrieve these selected rows by the following query:
/****** Script for SelectTopNRows command from SSMS ******/
SELECT *
FROM [test].[dbo].[Sheet1] WHERE Item1 IS NULL OR Item2 IS NULL
Now, I have to perform some edit operations (moving some data from some columns to others) which can't be performed with a query because of no single observable pattern for editting. So, the question remains, how can I get these rows in edit mode to do my task?
Click edit rows on the table and then open the sql tab of that query and add your predicate there. And that's how you can edit filtered records.
As you said, go for
Select DB > Table > Right Click > Edit top 200 rows
Now the window opens with the top 200 query and the results editable.
Now change the query to the one with your where clause and hit F5
Using LinqPad (https://www.linqpad.net/) you can direct edit previous run select query. It also has many other features like running Linq or C# codes.
After you have your 200 rows displayed for editing, you can also click on the "SQL" icon which will now be available above the Object Explorer. This is another way to have the SQL displayed which you can now edit as needed in order to change the desired rows.
To expand on other answers, once you open the SQL pane and have edited the SQL, you can click Ctrl-R or click the "Execute SQL" button to actually execute the SQL

How to edit data in result grid in SQL Server Management Studio

I want to edit some row values once I get a query output in the result grid.
Its true that we can right click the table and say open table to get an editable table output, but what I want is editable query output, only certain rows matching for my criteria, and edit them in the result grid.
Can this possible inside Microsoft SQL server Management Studio Express?
Yes, This is possible. Right click on the table and Click on Edit Top 200 Rows as show in image below
Then click anywhere inside the result grid, to enable SQL Icon "Show Sql Pane". This will open sql editor for the table you opted to edit, here you can write your own sql query and then you can directly edit the result set of the query.
You can do something similar to what you want. Right click on a table and select "edit top 200 rows" (if you are on SQL Server 2008) or "open table" in SQL Server 2005. Once you get there, there is a button on the top that says "SQL"; when you click on it, it lets you write an SQL statement and you can edit the results of it if you click a cell you want to change.
The way you can do this is by:
turning your select query into a view
right click on the view and choose Edit All Rows (you will get a grid of values you can edit - even if the values are from different tables).
You can also add Insert/Update triggers to your view that will allow you to grab the values from your view fields and then use T-SQL to manage updates to multiple tables.
SSMS - Right Click Results of Edit 200 | Option | Pane | SQL - edit the statement.
The given answers are still valid. No change in SSMS (SQL Server 2016) has been made on that regard.
You can also use the criteria pane, after doing the "Edit Top 200 Rows".
Show criteria pane
Enter some criterion
Edit data directly in the results grid
Additionally, the number of rows for those commands can be customized in your SSMS options.
No. There is no way you can edit the result grid. The result grid is mainly for displaying purposes of the query you executed.
This for the reason that anybody can execute complex queries. Hopefully for the next release they will include this kind of functionality.
I Hope that answer your question.
UPDATE
as you can see correct solution in Learning answer,
In SQL server management 2014 you can
1.click on "Edit Top 200 Rows"
and then
2.clicking on "Show SQL Pane (ctrl+3)"
and
3.removing TOP (200) from select query
Refer to Shen Lance answer there is not a way to edit Result of select query. and the other answers is only for normal select and only for 200 records.
Just choose "Edit Top 200 rows", press Ctrl + 3 in the edit grid region (or click "Show SQL Pane") and edit the query...
But please note that this will work only for the query that doesn't contain "join"
Yes you can edit joined results. (at least in SSMS 2008 R2) After you edit any of the result values in the View that uses joins, you'll need to execute the query again to refresh the results.
You also need to make sure SSMS is configured to allow "Edit All Rows" ... to do this in SSMS - Tools | Options | SQL Server Object Explorer | Commands ... expand the Table and View Options ... put a value of 0 in "Value for Edit Top n Rows command" ... can do this for the select also.
Yves A Martin's response is 100% correct!
Rob
First of all right click the tale select 'Edit All Rows', select 'Query Designer -> Pane -> SQL ', after that you can edit the query output in the grid.
If you need to frequently perform in-cell edits on SQL databases, HeidiSQL works a treat, couldn't be simpler to use, and is free / open source (donations accepted).
Originally written for MySQL, it can now handle SQL Server, and has experimental (as of Aug 2014) PostgreSQL support as well.
Right click on any table in your dB of interest or any database in the server using master if there are joins or using multiple dBs. Select "edit top 200 rows". Select the "SQL" button in the task bar. Copy and paste your code over the existing code and run again. Now you can edit your query's result set. Sherry ;-)
If the query is written as a view, you can edit the view and update values. Updating values is not possible for all views. It is possible only for specific views. See Modifying Data Through View MSDN Link for more information. You can create view for the query and edit the 200 rows as given below:
To be clear: The option "Value for Edit Top Rows command" has nothing to do with the fact if a result set is editable or not. It is just a way to limit the result set.
Editing the result set of a query based on one and only one table is obviously always possible.
The result set of a query based on more than one table is under following condition possible:
You can edit the fields in the result set at once if they belong to one and only one based table in the query! If the fields are Primary Key, then you have to fulfill refresh/"Execute SQL" (Ctrl+R) after each row update, in order to be able to edit a row next time. If the fields are not Primary Key, then you do not need to fulfill refresh/"Execute SQL" (Ctrl+R).
I have tested it on SQL Server 2008 - 2016!

Copy SQL 2005 view result column headers?

Is there a way to copy View output column headers along with the data? There is a setting in Options to include column headers with query results, but that only works with "New Query" and Stored Procedure output.
Looks like SSMS 2008 has this functionality built in to the contextual menu when you right click on results, but I only have 2005.
Am I out of luck?
Thanks for any help.
It works if you SELECT * FROM VIEW_NAME in a regular query window. If you Open a view like you Open a table to show data, it won't copy the columns - that's a different, editable grid.
Tools, Options, Query Results, SQL Server, Results to Grid. There's an option in there for it.