Create Database — SQL Technical Interview Questions & Answers

Create Database

Create Database

  • CREATE DATABASE college; makes an empty cupboard. Nothing is in it yet — no tables. Names are usually lowercase, no spaces. Then USE college; so the next CREATE TABLE goes inside it.
  • CREATE DATABASE IF NOT EXISTS college; is safer in scripts — it won’t error if the DB already exists. SHOW DATABASES; lists them. You should see college in that list after you create it.
  • One project, one database, is the student habit. Don’t put students and a shopping cart in the same DB unless it is the same app.
  • Trap: CREATE DATABASE then forgetting USE — tables land in another database and you think they ‘vanished’.
  • On the example next to this theory: CREATE DATABASE makes a schema; USE selects it for following statements.

Technical Interview Tip: CREATE DATABASE college; USE college; SHOW DATABASES;

Code Examples for Create Database

Create Database — sample query

-- Database admin (MySQL syntax; run on MySQL server)
-- CREATE DATABASE shop;
-- USE shop;
-- SHOW DATABASES;
SELECT 'Use CREATE/USE/SHOW on MySQL server' AS tip;

CREATE DATABASE makes a schema; USE selects it for following statements.

How to Explain Create Database to an Interviewer

What does CREATE DATABASE do?

Makes an empty database No tables yet

What next?

USE college; Then CREATE TABLE