0
0
PostgreSQLquery~5 mins

Creating databases and connecting in PostgreSQL - Quick Revision & Summary

Choose your learning style9 modes available
Recall & Review
beginner
What is the SQL command to create a new database in PostgreSQL?
The command is CREATE DATABASE database_name;. It creates a new empty database with the given name.
Click to reveal answer
beginner
How do you connect to a specific database using the psql command-line tool?
Use psql -d database_name or psql database_name to connect to that database.
Click to reveal answer
beginner
What is the default database you connect to when you start psql without specifying a database?
By default, psql connects to a database with the same name as your operating system user.
Click to reveal answer
intermediate
Can you create a database while connected to another database in PostgreSQL?
Yes, you can create a new database while connected to any existing database using the CREATE DATABASE command.
Click to reveal answer
beginner
What command do you use to list all databases in PostgreSQL using psql?
Use the meta-command \l or \list inside psql to see all databases.
Click to reveal answer
Which command creates a new database named 'shop' in PostgreSQL?
ACREATE DB shop;
BNEW DATABASE shop;
CMAKE DATABASE shop;
DCREATE DATABASE shop;
How do you connect to a database named 'sales' using psql?
Apsql -d sales
Bconnect sales
Cpsql sales_db
Dopen database sales
What does the command \l do inside psql?
ALists all tables
BLogs out from psql
CLists all databases
DLoads a SQL file
If you start psql without specifying a database, which database do you connect to?
AA database with your OS username
BThe 'postgres' database
CThe 'template1' database
DNo database, connection fails
Can you create a new database while connected to another database in PostgreSQL?
ANo, you must disconnect first
BYes, using CREATE DATABASE command
COnly if you have superuser rights
DOnly from the 'postgres' database
Explain how to create a new database and connect to it using PostgreSQL command line.
Think about the commands you type in the terminal.
You got /3 concepts.
    Describe how to list all databases in PostgreSQL and why this might be useful.
    It's a meta-command inside psql.
    You got /3 concepts.