SQL Server Tables and Data Types for Beginners

Tables are where relational data is stored. A table is made of columns that describe the data and rows that contain individual records.

Create a Simple Table

CREATE TABLE Students
(
    StudentID INT NOT NULL,
    StudentName NVARCHAR(100) NOT NULL,
    Age INT,
    EnrollmentDate DATE
);

Common SQL Server Data Types

  • INT for whole numbers.
  • DECIMAL(p,s) for exact decimal values such as prices.
  • NVARCHAR(n) for variable-length Unicode text.
  • DATE for calendar dates.
  • DATETIME2 for date and time values with higher precision.
  • BIT for Boolean-style values such as 0 and 1.

Primary Key

A primary key identifies each row uniquely.

CREATE TABLE Students
(
    StudentID INT PRIMARY KEY,
    StudentName NVARCHAR(100) NOT NULL,
    Age INT,
    EnrollmentDate DATE
);

Identity Columns

SQL Server can generate sequential numeric values automatically with IDENTITY:

StudentID INT IDENTITY(1,1) PRIMARY KEY

The first value is 1 and the increment is 1 in this example.

NULL and NOT NULL

NOT NULL means a value is required for the column. A nullable column can contain NULL, which represents an unknown or missing value.

Inspect the Table

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE';

Learning Tip

Choose data types based on the meaning and expected range of the data. Avoid storing numbers, dates, or Boolean values as text when a suitable native type exists.

What to Learn Next

Once the table exists, the next step is adding rows and learning INSERT, UPDATE, and DELETE.

Continue with INSERT, UPDATE, and DELETE in SQL Server 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...