Creating Databases — Complete Guide
Creating Databases — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of SQL Server Tutorial on Toolliyo Academy.
On this page
SQL Server Tutorial · Lesson 6 of 100
Creating Databases
SQL basics → Queries → Advanced
SQL basics · 1 — SELECT · ~6 min · SQL — Foundations
What is this?
CREATE DATABASE makes a new database with its own tables, users, and files. USE switches your session into that database.
Why should you care?
Apps isolate environments — DataVerse_Dev vs DataVerse — so experiments never touch production.
See it live — copy this example
Run in SQL Server Management Studio (SSMS) or Azure Data Studio.
IF DB_ID(N'DataVerse') IS NULL
BEGIN
CREATE DATABASE DataVerse;
END
GO
USE DataVerse;
SELECT DB_NAME() AS CurrentDb;
What happened?
- The IF guard avoids errors if your database already exists.
- GO ends the batch so USE runs after create.
- DB_NAME() confirms you landed in DataVerse.
Practice next
- Run the script in SSMS connected to the instance.
- Refresh Object Explorer → Databases.
- Right-click your database → New Query and run SELECT DB_NAME();
- Add COLLATE Latin1_General_CI_AS to CREATE DATABASE.
- Query sys.databases for DataVerse recovery_model_desc.
Remember
CREATE DATABASE adds a new container for objects. Always USE the right database before CREATE TABLE. Keep labs separate from production names.
Per-environment databases
CI creates DataVerse_CI for automated tests nightly.
Outcome: Failed tests never corrupt the shared dev database.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!