Skip to main content

SQL: create and use bank database

Short answer

Use CREATE DATABASE bank; then SHOW DATABASES; to list databases, then USE bank; to select it. MySQL replies Database changed after USE.

Consider database schema: Account (acc_no, branch_name, balance) Branch (branch_name, branch_city, assets) Customer (customer_name, customer_street, customer_city) Loan (loan_no, branch_name, amount) Depositor (customer_name, acc_no) Borrower (customer_name, loan_no) Create database and list existing databases. Use database bank for above schema.

The statements below use MySQL syntax.

Create the database

CREATE DATABASE bank;

List existing databases

SHOW DATABASES;

Sample output:

+--------------------+
| Database           |
+--------------------+
| bank               |
| information_schema |
| mysql              |
+--------------------+

Use the database

USE bank;

MySQL replies Database changed. Every table created after this statement is stored inside bank.

Notes

  • CREATE DATABASE IF NOT EXISTS bank; avoids an error if bank already exists.
  • In PostgreSQL the same steps are CREATE DATABASE bank;, \l to list and \c bank to connect. In SQL Server they are CREATE DATABASE bank;, SELECT name FROM sys.databases; and USE bank;.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Database Management System chapter 3 questions →