0
0
PostgreSQLquery~15 mins

Creating databases and connecting in PostgreSQL - Try It Yourself

Choose your learning style9 modes available
Creating databases and connecting
📖 Scenario: You are setting up a new project that requires its own database. You will create a PostgreSQL database and then connect to it to start working with your data.
🎯 Goal: Create a new PostgreSQL database named project_db and then connect to it using the psql command-line tool.
📋 What You'll Learn
Create a database named project_db
Connect to the project_db database using psql
Use exact commands as specified
💡 Why This Matters
🌍 Real World
Creating and connecting to databases is the first step in managing data for applications, websites, and data analysis projects.
💼 Career
Database creation and connection skills are essential for database administrators, backend developers, and data engineers.
Progress0 / 4 steps
1
Create the database
Write the SQL command to create a new database called project_db.
PostgreSQL
Need a hint?

Use the CREATE DATABASE statement followed by the database name.

2
Connect to the database
Write the psql command to connect to the database named project_db.
PostgreSQL
Need a hint?

Use the \c command in psql to connect to a database.

3
Verify the connection
Write the SQL command to show the current connected database name using SELECT current_database();.
PostgreSQL
Need a hint?

Use the SELECT current_database(); command to check which database you are connected to.

4
Complete the setup
Add a comment line that says -- Database setup complete to mark the end of your setup script.
PostgreSQL
Need a hint?

Add a comment line starting with -- to indicate the setup is done.