show tables command in Mysql displays error - mysql-workbench

I first created a table, then I altered it. Just after alter command I am trying to view the tables by writing
show tables
command but it displays the error-
show is not valid at this position, expecting ADD, algorithm , ALTER,
Auto increment.......

Related

How to see a SQL table's comment in CLI?

Let say I have a schema world and a table city in a Postgres DB.
I can set a comment on the table (or view, function, index, ...) with the command below:
COMMENT ON TABLE world.city IS 'This is a test comment';
How can I see this comment in CLI (Not GUI)?
I tried using show command thinking it might help, but got a syntax error!
SHOW TABLE world.city;
ERROR: syntax error at or near "table"
LINE 1: show table world.city;
The same happened with show command on views!
\d+ world.city
From the documentation:
The command form \d+ is identical, except that more information is displayed: any comments associated with the columns of the table are shown, as is the presence of OIDs in the table, the view definition if the relation is a view, a non-default replica identity setting and the access method name if the relation has an access method.

Change a column participating in a view or rule

I am using a tool called giswater to model our water sewer and storm networks. The tools builds a database from a few simple inputs in a gui one of which is the SRID. the geometry columns are all xy and I want to make them all ZM aware. When I run the alter table command to update the geometry I get an error "Cannot alter column participating in a view or rule"
Anyway to force this change and ignore the error? I tried changing the view to not reference the column and I tried adding a new geometry column to switch the view to temporarily while I make the change. Apparently I cannot drop a column in a view or change it to another column. I also tried writing the schema to SQL then edited the sql lines for linestring and point to linestringzm and pointzm and using psql to run the file to update the schema; all I get is access denied using "psql -U postgres -d utility -1 -f \i Z:......\xyz_test.sql"
Also tried pg_restore.
Anyway to just force the change using pg_admin4? or other suggestions?
I am not familiar with the tool you are using but I would suggest checking all the objects (views and rules) referencing your table by using the below command.
SELECT DISTINCT so.name
FROM syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE sc.TEXT LIKE '%tablename%'
Then backing up these object and dropping them completely before attempting to alter the table.

How to ALTER a table in PostgreSQL database using pgAdmin III

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

PostgreSQL leaving headers blank while importing CSV

I'm trying to import a CSV file with column names "Zip Code", "2010 Population", "Land-Sq-Mi" and "Density per Sq Mile" into my test table, which is named derp--that's why I have the drop statement at the beginning, so I don't replicate any rows and can start clean in each iteration.
Code is as follows:
DROP TABLE derp;
CREATE TABLE public.derp("Zip Code" varchar, "2010 Population" integer, "Land-Sq-Mi" numeric, "Density Per Sq Mile" numeric);
COPY derp("Zip Code", "2010 Population", "Land-Sq-Mi", "Density Per Sq Mile")
FROM '/home/michael/PycharmProjects/cmsDataProject/Zipcode-ZCTA-Population-Density-And-Area-Unsorted.csv'
DELIMITER','
CSV HEADER;
This does a fine job of importing the actual data, but it leaves the column headers blank in the pgadmin III data view. I looked at the source file in Nano--the headers are there, and if they weren't the query would have thrown a syntax error telling me that there was no relation for the column I was trying to import into.
Any ideas about what I'm doing wrong?
Edit: I would like pgadmin III data view to display the header names, and possibly a way to verify that the columns are actually named even if they aren't being imported and not displayed. To reiterate, every row after the headers is intact and in view, just the header row is blank.
Edit 2: When I CREATE TABLE public.derp(); and then manually add the columns, they show correctly in the data view. Something about the multi-line query statement was causing the breakage.
So pgadmin is not showing the column names but it's showing the data?
If you open a table in pgadmin, then alter the table, but keep the table window open, it seems to lose the column names.
Close the window with the table. Click the tables icon in the pgadmin tree view and refresh the tables, and reopen the table window.

Oracle SQL Developer SQL Tab is blank

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.