How do I find the source code to a table in pgadmin? - postgresql

I have a simple question. When you create a table/query from Pgadmin, how do you find the source code ( not sure if these are the correct words) you used?
I have looked under schema and can't find anything.
Attached is a photo. Thank you

Select the object on the left tree view and go to the SQL tab on the right to see the DDL.

Related

Can't see entire SQL table in terminal

I am learning postgreSQL and created a table using mock data (from a random data generator). When I run the SELECT * FROM {table} command, I can only see the top part of the table. It seems to cut off at a certain point and then restart from the beginning. Is this a terminal setting or is there something else I am doing wrong?
Thank you for your help!
I actually just got it figured out, for some reason my default was changed to bash instead of zsh. Now it is working where I can scroll and see the entire table. Thank you all!

Results given by stored procedure aren't editable

I would love to have a stored procedure which returns a selection which is editable in phpadmin. For example, something as simple as
SELECT * FROM students
written from the console will allow you to edit the records as far as each row is unique (table with a primary key). However, that same statement within a procedure won't allow it!
The point is that I have a selection that I will be using quite often and it's a bit more complex than the one above. If I copy it and paste it on the console, it's fine, but not so when run from a procedure!
I would appreciate any ideas to work around this limitation.
Thank you in advance!
Thanks to those who read my question. I just figured out that a very simple way to solve this issue is to create a table with my output selection. Then, from the console, I can select and edit whatever I need from that temporary table.
Thanks for your time!

How do you change a table's schema?

We have a MySQL Workbench project with two tabs (two schemas/two databases).
If we create a table in the first tab, it's attached to the schema
magikweb_dev_igcweb.
If we create a table in the second tab, it's attached to the schema
magikweb_dev_igcweb_archive.
If we copy-paste/duplicate a table from the first tab to the second tab, the resulting table remains in the first schema. How can you change a table's schema?
Each schema is linked with a specific database, so when we use the "Synchronize Model..." feature, it links all the tables properly.
Use the model tab. You can cut out a table from one schema tab and insert it into another.
The cut-and-paste method described in another answer works well for tables with no foreign keys, and for a reasonable number of tables.
An alternative that preserves foreign keys is to export the model as a SQL script, edit it, and then import the new script into a new model.
Using MySQL Workbench v6.3:
File -> Export -> Forward Engineer SQL Script
Carefully edit SQL script. Replace references to one schema with the other, for the tables you want to move. Do this both for CREATE TABLE commands and foreign key references.
File -> New Model
File -> Import -> Reverse Engineer SQL Script
Unfortunately you will then need to recreate any diagrams. But that can be straightforward if you have the original diagram as reference (take a screenshot or export it to PNG or PDF.)
Follow this simple steps (never miss step 4 and 5) :
Open Model Tab
Choose source schema. In my case, I want to copy table users from schema abc_develop_v1 to schema abc_develop_v2 then paste to diagram . So I choose schema abc_develop_v1, right-click table users then Copy 'users'
Go to the targeted schema. In my case is schema abc_develop_v2, right-click then Paste 'users'
Next, copy table users from schema abc_develop_v2. Right-click table users then Copy 'users'
Go to your diagram and Paste 'users'.
That's all. Your table is ready in your diagram with the right schema :-)
Notes: You can double check by double-click on the table in your diagram, and look at the right corner. It will show the Schema name.
I found a less painful way to do this.
Save and backup your diagram and your schema.
Display schema's name before table's names in diagram. This will make the next step easier.
Right-click on the tables which are on the wrong schema, and select "Copy SQL to clipboard". Paste the script in a new SQL window. Repeat for each table you want to migrate.
Edit the script to change the schema name. Watch for any miss in entries, the wrong schema might be a reference at any line. Mine was mydb, which I don't remember creating. Execute the script. Now you have the tables on the right schema.
Synchronize your model. Be sure to check "Update the model" for each missing table, otherwise, the tables will be deleted from the schema :)
Drag'n'drop the newly created tables into the diagram. Then remove the ones which are using the wrong schema. Tip: tables that are not in diagram won't display a dot next to their name.
Optionally, you can delete the faulty schema from the model so this never happens again. Be sure to know what you're doing first!

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.

MySQL Workbench: How to show the columns of view table?

The table with blue header is normal mysql table, while the one with yellow header is view table. I used reversed engineering to import these tables into mysql workbench and trying to place relationship among them using existing columns, but I can't expand and see the columns of view table.
It is the limitation of mysql workbench, or actually it is possible to expand the view table? If it is able to expand, can someone please guide me on this?
Thanks!!
This is currently a limitatiion and, to my surprise, not something that people requested in the past. If you like you can open a feature request at http://bugs.mysql.com to get this implemented.