How to auto-complete all columns in "select * from table" in SQL Server Management Studio - tsql

Write this:
Select * From tablea
Want this:
Select c1, c2, c3 ... From tablea
SQL Server Management Studio provides intellisense to pick one column at a time. It takes a while for table with lots of columns.
I can use Script Table as =>Select To=> New Query Edit Window, and the copy/paste to my original script. however is there a less interruptive way?
I write SQL a lots, thanks for help!

Found this myself.
Type Select * From TableA in SSMS.
Exactly Select text Select * From TableA.
Use Ctrl+Shift+Q to pop up Query Designer window.
Click OK. "*" is replaced by "c1, c2, c3..."
Query Designer auto-populates all the columns. just open it & close. if you want only portion of columns, I found it is still easier to delete them on text editor than trying to use mouse to uncheck them on GUI.
Still hope to find a way to eliminate the Keyboard/mouse switch on step 4? seems there is no short-cut key for the OK button.
Update 2019-06-24
Above method does not work for table in SQL Azure. ApexSQL SQL formatter seems working well for me, it's free.
Update 2020-10-30
found a similar function in LINQPad, it allows me to auto-complete all properties in LINQ, See here

In SQL Server Management Studio if you expand the object explorer and then the node for the particular table in question then you can drag the columns node into the query window and this will type out all of the column names for you.
There are probably better ways to do this, but that's what I use.

Totally understand this answer is not specific to SSMS but in VSCode via the mssql extension:
Write this:
Select *
From TableX
Place cursor after the * and press Ctrl+Spacebar and option to insert all columns appears

If your object explorer is open then use drag & drop feature.
e.g. Northwind
Step 1: Expand the database by single click on plus icon or just double click on "Northwind"
Step 2: Expand tables "Tables"
Now you will see "Columns", "Keys", "Constraints" etc
Click on "Columns" to drag to your editor window.
You can try for other as well like "Keys", "Constraints".
But for "Indexes", did not work for me.
Hope you will find useful tips.

Related

SSMS - Terminology for Select & Edit

Terminology question. In SSMS, when you list the various tables and right click on one, you get the 'Select Top 1000 Rows' & 'Edit Top 200 Rows', and depending on which on you click, it will take you to an interface that looks similar to the other, but clearly works differently. Does Microsoft have a specific name for these two interfaces? I had wanted to look up some settings for these and realized I don't even know what they're called. I've always called them Select Mode and Edit Mode, but searching that hasn't yielded anything useful.
The "Select top 1000 Rows" takes you to a query editor with a prewritten query in the below fore and automatically runs it:
/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP (1000) <Column Name>
[,<Column Name> ...
,<Column Name>]
FROM <Database Name>.<Schema Name>.<Object Name>
The window at the bottom is the results pane.
The "Edit Top 200 Rows" launches a query designer, based on the a similar query to the above (but the database name is omitted and the schema might be). Forget you ever saw this, and never use it again. The "feature" is actually full of bugs, it lacks functionality and support for a lot of features (especially newer ones, like temporal tables), and has some interesting "quirks". If you need to "edit" your data then write the appropriate INSERT, UPDATE and DELETE statements to alter your data.

"SCRIPT TO..." option in Datagrip?

Decided to pick up Datagrip for my Postgres database.
I've worked with SSMS/MS SQL-Server a lot, and one of the nice things about SSMS is the option to select a table and then a menu option called "SCRIPT TO..." and it'll give another list of auto-generated select, update, delete, etc queries.
Does Datagrip have a similar function? I'm struggling to find it.
In DataGrip there is another concept of creating queries, editor-centered:
Live Templates. When you are in the editor you can quickly create any type of query. For example, for SELECT * FROM <table_name> just type sel and press Tab. Then choose the table. The same for INSERT (type ins). All live templates can be found in Preferences | Editor | Live Templates
Generate functionality: Alt+Ins or Cmd+N. It is not customizable but good to create objects.
Anyway, your point is fair and there is a feature request in DataGrips' tracker: https://youtrack.jetbrains.com/issue/DBE-2762. Please upvote and comment there.

SQL Developer 19.1 doesn't show the matching list of table names in worksheet editor

SQL Developer 19.1 - worksheet editor doesn't show matching list of table names from the schema. Eg. If I were to write a SQL query such as:
select * from TMP_EMPLOYEE_MASTER;
I am expecting SQL Developer to show me the table name after I have typed first few letters of the table name (eg. TMP_EM). But looks like SQL developer doesn't seem to be helping at all in highlighting the matching table names.
I know that this feature exists in SQL Developer. Just wondering why it isn't working
Edit 1:
I tried below options but still not working:
CTL+spacebar.
Change the entries in the preferences as mentioned in the screenshot. But this didn't help. The auto complete/suggestion for table name is not coming at all.
I'm guessing you have more than 10 tables that start with TMP
Increase the filter for Auto-Complete to something higher than 10 - or type more letters, or use Ctrl+Spacebar to 'force' the completion feature to fire.
That option is located in Tools - Preferences; search for "complet" and you'll see Code Editor: Completion Insight. Check both "SQL Worksheet" and "PL/SQL Editor" checkboxes, adjust popup speed if necessary.
Works for me ...

datagrip Cannot apply changes This table is read only. Cell editor changes cannot be applied

So simply the problem occurs when I want to edit selected rows and then apply it. I'm sure it worked some time ago. Tried redownload postgres driver in preferences(yeah, I use postgres) Anyone faced same issue? Anyone succeed?
PS. Running on 142.4861.1.
I found read only checkbox in connection preferences, it was not set, toggling didn't help, upgrading, reseting also didn't help.
In my case in version 2020.1 of DataGrip (SQL was run from the opened file, on unique table, so that select just worked as expected, but when I was trying to edit - error appeared: unresolved table reference): specifying schemes in request helped. So that SELECT * FROM users; was changed to SELECT * FROM schemadb.users; and that helped. Probably there is a bug. I've tried all the methods mentioned above.
Try synchronize database connection. It helped me in mysql connection.
What actually helped was toggling Auto-commit checkbox in console, after that everything runs flawlessly.
The only thing that actually worked for me, after trying everything above multiple times, was deleting each DB connection and remaking a new one from scratch.
This can be due to default settings, make it sure your your transaction Mode settings are as below
I had the same issue with datagrop 2020.2. I have followed all the method but for me, just delete the connection and create new connection (never trying to duplicate) just manual. It is works!
Set and clear Read-only in Data Source Properties helps me.
What worked for me was removing a field alias - going from this:
SELECT
l.MSKU Item_SKU,
l.Supplier,
l.ASIN,
l.title,
l.Buy_Price
FROM listings l
WHERE l.Buy_Price IS NULL
ORDER BY l.Supplier, l.listingID desc;
to this:
SELECT
l.MSKU,
l.Supplier,
l.ASIN,
l.title,
l.Buy_Price
FROM listings l
WHERE l.Buy_Price IS NULL
ORDER BY l.Supplier, l.listingID desc;
is all it took for me to be able to edit the results of the query
If your query is using field alias (renaming column instead of using actual column name) , then Datagrip set data results as read only.
Solution:
Rewrite query using field names as in the table and rerun query. Then you will be able to edit the rows.
Example
Rewrite this:
select id,interest_recalcualated_on, interest_recalculation_enabled alias from m_loan;
..to this:
select id,interest_recalcualated_on, interest_recalculation_enabled from m_loan;
Nothing worked. I had to update DataGrip from 2017.2 to 2018.3
I had to open the project by navigating to: /home/user/.DataGrip2017.2/config/projects/my_project/
All my scripts for this project as I did not want to import the config from the old version of Datagrip. So I'll probably need to downgrade, get the scripts and upgrade again.
I struck the same issue, not Postgres but MySql, PhpStorm 2019.1 when I had two schema available on the same db connection and my query: select * from users where full_name like '%handy%'; resulted in a result table that couldn't be edited even though the console reported it was querying the stage schema. A more specific query: select * from stage.users where full_name like '%handy%'; using the exact table name led to a results table that could be inline edited.
The only way I was able to get around this issue was to remove the database connection details for the given connection and recreate them from scratch. While this was happening to me on this specific connection, editing was working fine on other connections, which suggests the problem might be related to specific parameters around the connection in question.
For me, when I changed back my Select query to * (wild char to select all the columns), from specific columns, the edit and save started to working again. This is strange! May be worth reporting a bug to intellij. I'm using DataGrip 2020.1 on macOs Catalina 10.15.3
I thought I had the same problem but just realized I needed to submit changes (with a button or command + enter) for them to be applied.
This answer is 4 years late though. Maybe the bug was already fixed haha, but this may help someone else.
The problem for me was the obvious (well obvious after identifying it) - using a MySQL keyword as a field name (yes I know its not a good idea but thats how it is sometimes). So this caused the error
select id,name,value from mytable;
The correct way to write this of course is using backticks so:
select id,name,`value` from mytable;
and this solved it for me.
seems like DataGrip doesn't allow to change data in the ui table if you select specific columns with joins.
so if you select table1.column1, table2.column2 from <table1> inner join <table2> and try to change the value in column1, you will receive This table is read only warning
only if you do select * from <table>, you can edit the cell values
try this
In the IDE settings (Ctrl+Alt+S), go to Database | General.
Select the Open results in new tab checkbox and click OK.
Re-run your query, and you'll be able to edit and commit the changes in the new tabs.

SQL Server Management Studio GROUP BY clause SHORTCUT

Is there is a shortcut or tool or something in T-SQL in SQL Server Management Studio that will allow you to automatically create a GROUP BY clause?
I put this as a comment ... but it is actually a solution.
Copy and paste all of your values which aren't in an aggregation function?
I find that the SELECT list contains my GROUP BY columns usually. Or vice versa so I copy, paste. And/or the ORDER BY.
Also, if you drag from Object Explorer Columns node for a table it puts a CSV list of columns in for you. This is a useful shortcut.
This is without using 3rd party tools like SSMS Tools Pack or Red Gate SQL Prompt