Create a SQL Server Database for Beginners

A database is a container for related data and database objects. In SQL Server, you will commonly work with databases that contain tables, views, stored procedures, functions, and other objects.

Create a Database

CREATE DATABASE SchoolDB;

The statement creates a database named SchoolDB.

Switch to the Database

USE SchoolDB;

USE changes the database context for the current query window.

Check the Current Database

SELECT DB_NAME() AS CurrentDatabase;

List Databases

SELECT name
FROM sys.databases
ORDER BY name;

System catalog views such as sys.databases expose metadata about databases on the SQL Server instance.

Delete a Test Database

Only run this against a database you are certain you no longer need:

DROP DATABASE SchoolDB;

Important Safety Tip

Use a dedicated practice database while learning. Avoid running DROP DATABASE or other destructive statements against production databases.

What to Learn Next

After creating a database, learn how to create tables, define columns, choose data types, and add constraints.

Continue with SQL Server Tables and Data Types for Beginners or return to the SQL Server Tutorials hub.

đŸ’Ŧ Comments

Sign in with Google to publish immediately, or comment anonymously and wait for approval.

Loading comments...