Table Structure
A SQL Server table is made up of columns and rows. Each column defines the type of data that can be stored, while each row represents a complete record.
Understanding Table Structure
Consider the following Students table:
| StudentId | StudentName | Age | Course |
|---|---|---|---|
| 1 | Samadhan | 22 | Java |
| 2 | Samiksha | 21 | .NET |
| 3 | Pradnya | 23 | Python |
Table Structure Diagram
Students Table
│
├── Columns
│ ├── StudentId
│ ├── StudentName
│ ├── Age
│ └── Course
│
└── Rows
├── Record 1
├── Record 2
└── Record 3
Columns
A column represents a particular type of information in a table. Each column has a name and a data type.
| Column | Data Type | Description |
|---|---|---|
| StudentId | INT | Stores the student identifier. |
| StudentName | VARCHAR(100) | Stores the student name. |
| Age | INT | Stores the student's age. |
| Course | VARCHAR(50) | Stores the course name. |
Rows
A row represents one complete record in a table.
1 | Samadhan | 22 | Java
2 | Samiksh | 21 | .NET
3 | Pradnya | 23 | Python
In the above example, each line represents one student record.
Data Types in Table Structure
Every column should have an appropriate data type. The data type determines what kind of value can be stored in the column.
| Data Type | Example | Common Usage |
|---|---|---|
| INT | 100 | Numbers |
| VARCHAR | 'Rahul' | Text |
| DATE | '2026-10-02' | Date values |
| DECIMAL | 45000.50 | Precise numeric values |
| BIT | 1 / 0 | True / False type values |
Creating a Table Structure
The table structure is defined while creating the table.
CREATE TABLE Students
(
StudentId INT,
StudentName VARCHAR(100),
Age INT,
Course VARCHAR(50)
);
View Table Structure
The sp_help system stored procedure can be used to view information about a table.
EXEC sp_help 'Students';
View Columns Using INFORMATION_SCHEMA
We can also use INFORMATION_SCHEMA.COLUMNS to retrieve column information.
SELECT
COLUMN_NAME,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Students';
Example Output
| Column Name | Data Type | Length |
|---|---|---|
| StudentId | int | NULL |
| StudentName | varchar | 100 |
| Age | int | NULL |
| Course | varchar | 50 |
Table Structure Flow
Table
↓
Columns
↓
Column Name + Data Type
↓
Rows
↓
Records / Data
Important
A well-designed table structure should use meaningful column names and appropriate data types for the data being stored.
Summary
In this section, we learned about the structure of a SQL Server table, columns, rows, data types and different ways to view the structure of a table.