IntelliJ IDEA: How to quickly open a DB table editor? - database

Scenario: I'm in IntelliJ IDEA DB console and looking at
SELECT * FROM TableXY;
I want to see the definition of the TableXY. One way of doing it is:
ctrl+click on the table name: Looks up the table in the Database window.
F4: Opens the table editor.
select the Text tab
The problem is that I'm on a DB with a lot of tables and the first step takes forever because IDEA loads the full list of tables.
Is there a way to jump to the table editor directly?

I am not sure if this is what you are looking for, but to quickly view the table definition you can use the Quick Documentation pop-up:
Place your cursor within the table name and hit CTRL+Q (or F1 on Mac). This will show you some information about the table, the first rows, and the table definition (output from SHOW CREATE TABLE).
You can also configure the Quick Documentation under Settings > Tools > Database (see Intellij IDEA on-line help).

Related

where is the option to load CSV into Snowflake? I'm not seeing it

I'm testing out a trial version of Snowflake. I created a table and want to load a local CSV called "food" but I don't see any "load" data option as shown in tutorial videos.
What am I missing? Do I need to use a PUT command somewhere?
Don't think Snowsight has that option in the UI. It's available in the classic UI though. Go to Databases tab, select a database. Go to Tables tab and select a table the option will be at the top
If the classic UI is limiting you or you are already using Snowsight and don't want to switch back, then here is another way to upload a CSV file.
A preliminary is that you have installed SnowSQL on your device (https://docs.snowflake.com/en/user-guide/snowsql-install-config.html).
Start SnowSQL and perform the following steps:
Use the database where to upload the file to. You need various privileges for creating a stage, a fileformat, and a table. E.g. USE MY_TEST_DB;
Create the fileformat you want to use for uploading your CSV file. E.g.
CREATE FILE FORMAT "MY_TEST_DB"."PUBLIC".MY_FILE_FORMAT TYPE = 'CSV';
If you don't configure the RECORD_DELIMITER, the FIELD_DELIMITER, and other stuff, Snowflake uses some defaults. I suggest you have a look at https://docs.snowflake.com/en/sql-reference/sql/create-file-format.html. Some of the auto detection stuff can make your life hard and sometimes it is better to disable it.
Create a stage using the previously created fileformat
CREATE STAGE MY_STAGE file_format = "MY_TEST_DB"."PUBLIC".MY_FILE_FORMAT;
Now you can put your file to this stage
PUT file://<file_path>/file.csv #MY_STAGE;
You can find documentation for configuring the stage at https://docs.snowflake.com/en/sql-reference/sql/create-stage.html
You can check the upload with
SELECT d.$1, ..., d.$N FROM #MY_STAGE/file.csv d;
Then, create your table.
CREATE TABLE MY_TABLE (col1 varchar, ..., colN varchar);
Personally, I prefer creating first a table with only varchar columns and then create a view or a table with the final types. I love the try_to_* functions in snowflake (e.g. https://docs.snowflake.com/en/sql-reference/functions/try_to_decimal.html).
Then, copy the content from your stage to your table. If you want to transform your data at this point, you have to use an inner select. If not then the following command is enough.
COPY INTO mycsvtable from #MY_STAGE/file.csv;
I suggest doing this without the inner SELECT because then the option ERROR_ON_COLUMN_COUNT_MISMATCH works.
Be aware that the schema of the table must match the format. As mentioned above, if you go with all columns as varchars first and then transform the columns of interest in a second step, you should be fine.
You can find documentation for copying the staged file into a table at https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html
If you can check the dropped lines as follows:
SELECT error, line, character, rejected_record FROM table(validate("MY_TEST_DB"."MY_SCHEMA"."MY_CSV_TABLE", job_id=>'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'))
Details can be found at https://docs.snowflake.com/en/sql-reference/functions/validate.html.
If you want to add those lines to your success table you can copy the the dropped lines to a new table and transform the data until the schema matches with the schema of the success table. Then, you can UNION both tables.
You see that it is pretty much to do for loading a simple CSV file to Snowflake. It becomes even more complicated when you take into account that every step can cause some specific failures and that your file might contain erroneous lines. This is why my team and I are working at Datameer to make these types of tasks easier. We aim for a simple drag and drop solution that does most of the work for you. We would be happy if you would try it out here: https://www.datameer.com/upload-csv-to-snowflake/

SQL Server Mgmt Studio shows "invalid column name" when listing columns?

I'm used to scripting in Python or Matlab, and my first couple hours with SQL have been infuriating. I would like to make a list of columns appear on the screen in any way, shape, or form; but when I use commands like
select *
from "2Second Log.dbo.TagTable.Columns"
I keep getting the error:
Invalid column name '[the first column in my table]'.
even though I never explicitly asked for [the first column in my table], it found it for me. How can you correctly identify the first column name, and then still claim it's invalid!? Babies will be strangled.
This db was generated by Allen Bradley's FactoryTalk software. What I would really like to do is produce an actual list of "TagName" strings...but I get the same error when I try that. If there were a way to actually double click the table and open it up and look at it (like in Matlab), that would be ideal.
Echoing juergen's suggestion in the comment above. It looks like you're running the query on the master database, not the 2Second Log database that actually has your table. (You can tell this by looking at the database in the dropdown in the top left of your screenshot). Two things you can do:
Change the dropdown in the top left to 2Second Log. This will target your query to a different database
Put your database name in brackets as suggested by juergen i.e. select * from [2Second Log].dbo.TagTable
As an side, if you're looking for a good SQL tutorial, I highly recommend the Mode SQL tutorial. It's a fantastic interactive platform to get your SQL feet wet.
always use brackets when names/field have spaces or dashes.
select * from [2Second Log].dbo.TagTable

How to add a dropdown to datasheet form in MS Access which is based off a SQL Server query

I have a form in MS Access (datasheet view) which is based on the output of a SQL Server query. Now this is used in a front end where the user needs to be able to select from a drop down the value for one of the columns, 'NAME'. I tried adding a combo box which is mapped to take distinct names from the SQL Server table to the datasheet form but the results were not as desired.
Kindly provide advice on how this can be possible. I did this before by using a lookup on a similar MS Access database, but in a multi-user environment, the database was corrupted and now I moved my back end to SQL Server.
Just got the answer to my question. here are the steps I followed.
a) Add a combo box to the datasheet form in design view like Johnny Bones suggested.
b) Create a drop down with values.
c) Point the Control Source property to the field in the SQL Server table which needs to be updated, in this case NAME.
d) And voila, your drop-down now shows the values in the table and you can include a drop down for the user.
Thank you for pointing me in the right direction Johnny.
In datasheet view, I think you'll need to set up the field in the table.
Open the table in Design View
Click on the specific field in question
At the bottom you will see 2 tabs; General and Lookup (I
apologize, my work doesn't allow me to upload pics, so I hope you
can visualize it)
On the Lookup tab, change the Display Control from Text Box to
Combo Box
At that point, the properties should look familiar if you've worked with Combo Boxes, and you can change them to suit your needs.

Edit data from result grid

I would like to edit data directly from result grid in ssms. eg:
When I execute SELECT TOP 10 * FROM some_table, I want to edit data directly from result grid.
I don't want to open some_table and edit from there.
I know that result grid is read-only, but maybe someone written addin for it.
You can't edit the data from within the result grid. You'd have to go via the "open table" route if you want to edit the data manually instead of using UPDATE/INSERT SQL statements.
Is there a reason you specifically want to use the result grid instead?
You can specify a query when you go via open table to limit the results if that's your reason? There's a "Show SQL Pane" button in the top toolbar you need to select (square box with "SQL" written in it).
I have very large database (70+ GB) with so many tables.
I'm using Red Gate's SQL refactor for intellisense and few other things.
It's so boring to type in update sql statements every time I need to change single field.
It also takes some time to find that table in the Object explorer.
Intellisense doesn't work when I use "Show SQL Pane".
I'm new to SQL Server and have used the Oracle product 'PL/SQL developer' by All Round Automations at a previous job... It would allow you to do a SELECT in the query window and then simply add "FOR UPDATE" to the end of your refined SQL SELECT and 'ta-da' you can now edit the results in a nice grid. No need to Open Table View, click the SQL button, paste in the SQL you you have been working on and then hit execute ;)
EMS SQL Manager for SQL Server allows to update data directly inside a results grid.
This tool is boring for typing new requests (poor intellisense and error management) but fine for this. I always have the two tools opened.
If you right click on the table and choose edit top 200 records, it produces a result screen with an query.
Add to this your query and then you can edit the records in the result screen.
Also you can change the 200 to a number you want (2000).
The "results" pane is not just results.
Results in text
Assorted time and IO statistics
Estimated and actual execution plans
Row counts, Error messages, PRINT output
etc
This is why they are separate.
Feel free to write your own add-in :-) Or here
SQL Server ISN'T Access!
When you run a query and get the results - thats exactly what you are doing, reading the data, not opening the table for editing. Can you imagine the necessary transactional control around allowing the results window to be edited? The locking would probably grind SQL to a halt - I hope no-one ever writes that kind of add-in!

Linking MS Excel to MS Access queries

I have an Access database that I use to to run a bunch of aggregate TOP 5 queries. The end game of this particular function is ppt presentations with charts. So to automate this a bit, I created an excel spreadsheet with a bunch of pre-made charts in it. The I linked/data imported the query results into the excel spreadsheet, and set the cell ranges to match the source ranges for the charts. Finally I set the spreadsheet to enable auto refresh upon every "file open", and presto, I run the queries in access with a button press, then open the excel file, and the data refreshes, and they are my charts. I then use some VB to copy paste all active charts into ppt, but that is another matter.
Okay so here is the snag I hit. I needed to do the exact same procedure with another spreadsheet from another ag query. Before the process I was using was just clicking data > import external data > import data and then choosing the file of the database, and then it would populate a list of tables and queries to choose from. Only now, it will not show any queries in that populated list; only tables!?!
any ideas? btw MSO 2003
I can't reproduce that Justin. In the dialog that shows the tables, scroll over to the right and check the TYPE column. Queries will have a type of VIEW and tables of TABLE. Verify that they all say TABLE.
Next, try using Data - Import External Data - New Database Query instead of 'Import Data'. Select the Access driver and the Access mdb. This will bring up a different dialog, but should show both tables and queries. See if that shows only tables or shows both.
I presume this is a security feature that has been introduced?
Try selecting any table then select Data>Import External Data>Edit Query
Then select SQL as the command type and either enter the query SQL or just select from a query i.e.:
select * from qryCat;
Hope this helps
thanks Mark

Resources