Friday, February 15, 2013

Interacting With SQL Databases

LIST ALL DATABASES WITH A USER
psql -l -U <username>

LOGIN TO A DATABASE AS USER
psql -d <database> -U <username>
or
psql -d <database> -U <username> -W
or
psql -d <database> -U <username> -h localhost

POSTGRES DATABASE COMMANDS
For initial help, simpy type
help;
To get SQL help, type  \h
For psql help, type \?

\d will show all the relations in a database
\l will show all the databases available

To see something listed in a table, simply run
SELECT * FROM <TABLE>

DESCRIBE <TABLE> will show what fields the table has

http://www.stuartellis.eu/articles/postgresql-setup/

SPECIAL TRICKS FOR SQLITE
To show all the tables in a DB
.tables
or
SELECT * FROM sqlite_master;

To show fields in a table, use
pragma table_info(<TABLE>);

No comments:

Post a Comment