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?
✗ Incorrect
The correct syntax to create a database is
CREATE DATABASE database_name;.How do you connect to a database named 'sales' using psql?
✗ Incorrect
Use
psql -d sales or psql sales to connect to the 'sales' database.What does the command
\l do inside psql?✗ Incorrect
The
\l command lists all databases available in the PostgreSQL server.If you start psql without specifying a database, which database do you connect to?
✗ Incorrect
psql tries to connect to a database named after your operating system username by default.
Can you create a new database while connected to another database in PostgreSQL?
✗ Incorrect
You can create a new database from any existing database connection using
CREATE 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.