I've been using SQL Server Management Studio (SSMS) for the last 8 years, and I keep on stumbling upon a problem. When I right click on a Table, and select SELECT TOP 2000 ROWS, the query editor opens up a new file with the query inside. This is nice and all for a quick review of the table.
The problem I have is the default database is changed from the actual database to the master database. I have sysadmin rights.
The query that gets generated by SSMS, then has the databse, schema, and table in brackets, i.e. [DB].[dbo].[TableName]
Is there a way to set the default database on the SELECT TOP 2000 ROWS command, to NOT go and set the default database to 'master' ?
The other workaround is to click on the table, and then do a 'New Query', which will keep the current database, and then I have to type in 'SELECT * FROM TableName'
In SSMS go to Security > Logins - choose your login, then right-click and choose Properties - at the bottom of the tab is an option called "Default Database" - this is what you want to change.
Related
DataGrip is connected to a PostgreSQL database running on localhost.
DROP TABLE users returns 'table does not exist'
Dropping the table via the context menu -> drop works just fine, checked on another table (which had the same problems). In preview, exactly the same SQL I'm trying to run in the console is shown.
public.users yields the same results.
herokulocal.public.users yields "cross-database references are not implemented"
Other queries, such as select * from pg_catalog.pg_tables; work just fine.
Additionally, users is not visible in the results yielded by select * from pg_catalog.pg_tables;.
Given that the exact same query generated by WebStorm for context menu -> drop does not work in the console, it makes me think my console's running in some different context. Please note I'm a database layman.
What possibly could be wrong here?
I connected with a wrong database - postgres instead of herokulocal.
As the title already says:
I am trying to make a SELECT statement in the "view/edit data" mode in pgadmin 4, but the query window is disabled. How can I enable it? (I am the owner of all the database, the schema and table and have all privileges for all of them)
You cannot edit the query in VIEW DATA mode.
If you want to write custom SELECT/SQL code then use Query tool option.
You need to set a primary key on the table to be able to add items to the table in "View/Edit Data" mode.
If you want to be able to modify the sql query instead of view/edit data go to Scripts -> Select Script
In a MySQL database I can change a table structure with an ALTER statement but how to do that in PostgreSQL with pgAdmin III? In pgAdmin III every time I drop the table and again run the updated create query of that table. Is is possible to ALTER the table in the PostgreSQL database using pgAdmin III?
Server -> Database -> Schema -> Table -> Right Click On Table -> Properties...
Step1 :
Step2 :
Step3 :
Last step is Save your changes...
In pgAdmin III you basically have two options to alter a table structure:
In the hierarchy to the left, navigate to the table and use the context menu (right-click with the mouse) to access the properties of the table. In the pop-up dialog you can make the changes. You can also drill down in the hierarchy to the individual columns and make changes to column names, data types, column constraints, etc.
After you connect to the database, you see a SQL button in the top button bar. Clicking that opens up a SQL console and you can type in an ALTER statement using standard SQL syntax.
Note that pgAdmin III does not refresh the tree hierarchy on the left of the screen after making changes through the SQL console, you have to do that manually. Right click on a node and click "Refresh" to update the information in that node and everything under that node. (So if you made changes to a single table, r-click on the table name, if multiple tables are affected r-click on the schema name, etc.)
I've searched through all of the responses on SQL Developer and I haven't found a response that matches this question. I need to be able to see the SQL for a table/view etc by clicking on the sql tab, but for now it simply shows me a blank screen. Has anyone else solved this? It works fine in toad and I can see the code but we have a new server and I can't connect to it with toad. Any help would be nice.
When i connect to SQL Developer and type alter the session set current_schema=xyz then i am connect as if i was that user.
When i open the branche other users, and navigate to a table of user xyz, and click table A_TABLE, then i see the definition of that table in the columns tab and i have several other tabs, such as data to show the data in the table. So far so good.
But when i navigate to the SQL tab (on the far right of the tabs) i would expect to see the DLL of the table, but this tab stays empty. (this is also posted in another thread, but no good solution)
Is there a way to get this working ?
Probably tab in the backend looks in user_tables and user_tab_columns to generatie the DLL.
And since i did an alter session, the table are probably in the all_tables view.
It works fine when i log in and click my own tables, but not that of other users.
Same think with view definitions.
Also right clicking on the object and choose quick DLL results in empty file/worksheet of clipboard.
In short, can the tab SQL only work for schema owners of dba's or can it also work when using alter session set current_schema = xyz
Not sure exactly what you mean, but:
1. Can you connect to your db using Sqldev? Can you expand the list of schema objects and see your tables?
2. If so then when you open a sql worksheet, yes it is blank., this is where you type your sql statement and execute it. Type the FROM clause first, then go back and add the select clause and sql dev will show a drop down list of columns for the tables you can select from w/o typing the col names.
3. If you want to see you table data, simply double click the table in the tree browser on the left.
You can also build queries graphically though drag and drop.
But, normal behavior of the SQL worksheet window is to display blank, so not sure exactly what you expecting to happen.
If you select a view and right click and select Export DDL and Select Save to Worksheet, then the DDL is pasted into a worksheet: Example:
CREATE TABLE "HR"."COUNTRIES"
( "COUNTRY_ID" CHAR(2 BYTE) CONSTRAINT "COUNTRY_ID_NN" NOT NULL ENABLE,
"COUNTRY_NAME" VARCHAR2(40 BYTE),
"REGION_ID" NUMBER,
CONSTRAINT "COUNTRY_C_ID_PK" PRIMARY KEY ("COUNTRY_ID") ENABLE,
CONSTRAINT "COUNTR_REG_FK" FOREIGN KEY ("REGION_ID")
REFERENCES "HR"."REGIONS" ("REGION_ID") ENABLE
) ORGANIZATION INDEX NOCOMPRESS PCTFREE 10 INITRANS 2 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
PCTTHRESHOLD 50;
SQL DDL statements show the 'code' to create the schema object.
This question is about the gui application (DB2 Control Center), not about sql statements
At my work, we develop an application that supports sql server, oracle and db2. Therefore we use the gui applications of all three of them at varying capacity.
The problem is when I edit a record and I want to insert a null value. For sql server (sql management studio), ctrl+0 does the trick. For oracle (sqldeveloper) it doesn't matter because empty strings are essentially nulls.
Does anyone know how I can do that with the Control Center for db2? currently I resort to executing statements via the command editor as a workaround, but it is such a waste of time.
If you leave the field blank, it'll insert a NULL.
In more depth, if I double-click the table name, I get a window containing the first 100 records in that table. Then, I click the 'Add Row' button, and a new empty row shows up at the bottom of the listing. I fill in the mandatory fields, leaving the nullable fields blank, then click the 'Commit' button to commit that insert. Fields that are left blank are inserted as nulls.