SQL Server Management Studio GROUP BY clause SHORTCUT - tsql

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

Related

"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 ...

Kentico Import Toolkit 8.1

I am currently using the Kentico Import Toolkit to create documents in the tree.
At this point, I have imported around 100 documents using the toolkit, and they are all located at the correct place in the tree. Now the issue/concern that I had was, as I have imported these documents, my spreadsheet has been updated, so extra fields and data were added, so how do I go about importing this extra data into the currently existing documents? Also just bear in mind I don't want other fields or data to be affected by this, as some of the documents were updated with some other content by the content editors using CMS Desk, which isn't available in the spreadsheet.
Import toolkit is not the right tool to achieve this task. Even if you select "Import new and overwrite existing pages" it'll overwrite most of your columns. Actually it only preserves system and id columns from the existing documents - all other columns get overwritten.
Either you can write a piece of custom code or you can try following:
Open SSMS and navigate to the coupled table of your page type (something like CONTENT_MyDocType). This is where your custom columns are stored.
Right click -> Edit top 200 rows
Click "Show SQL Pane"
Adjust the columns, ORDER BY and WHERE clause to match your excel file, re-run the query
Select desired rows in your excel file and copy them to clipboard
Paste the data in the SSMS
rocky is right, Import Toolkit is meant for importing complete objects, not partial/continuous update.
You could map the fields that you know are not changed in the spreadsheet to a SQL query selecting the value from the target database.
To achieve this, just insert #<target> at the beginning of the SQL select statement you will be mapping the field to.
It will be rather laborious though and it also requires certain knowledge about the nature of the spreadsheet changes.

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

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.

Generating all 'data dictionary' reports under each 'object' in postgres

I have a database with about 50 something tables. I would like to run the report "Data Dictionary" on each table.
Ideally, I would like them all to be in one report, for example, in PGAdminIII, if I right click select "Tables" I will get a report of all the 'objects' and under each one a data dictionary report.
Is there an automatic way of doing this, or an plugin that I can install to postgres? Or is there something analogous to this?
If I understand correctly, you're referring to the ability to right mouse click on a table in PgAdminIII and select Reports > Data Dictionary report?
I'm not aware of any way to do that from PgAdminIII. You could look into using a different tool such as SchemaSpy. Another option (as alluded to by #kgrittn) is to use psql \d with the \H flag to generate html output. My solution (since SchemaSpy didn't do what I needed, and I needed the same output for both Postgres and Oracle) was to roll my own using perl, DBD::Pg and Template::Toolkit.
Update: Added GitHub link.
I wrote a fairly simple Postgres data dictionary generator in Python that spans all schemas and tables within a specified database. If it doesn't have exactly what you want it would be fairly easy to modify.
https://github.com/kylejmcintyre/pypostgreports