SQL Identity Column: Auto-Generating Unique Values for Your Tables

Опубликовано: 27 Февраль 2026
на канале: Analytics Hub
58
4

Discover how to use the SQL Identity column to automatically generate unique values for your table rows. In this video, we create a Medical Records table with an Identity column, insert data, and see how SQL manages unique identifiers for each record. Ideal for anyone looking to streamline their database management and ensure unique values effortlessly."

drop table if exists Medical_Records;
CREATE TABLE Medical_Records
(
id INT IDENTITY PRIMARY KEY,
problem VARCHAR(200),
date_of_examination DATE,
patient_id VARCHAR(15),
doctor_id VARCHAR(15),
FOREIGN KEY (doctor_id) REFERENCES doctors(id)
);

select * from Medical_Records;

insert into Medical_Records values ('Food Poisoning', convert(date,'10-01-2023',105), 'P1', 'D2');
insert into Medical_Records values ( 'Fever and Flu', convert(date,'11-01-2023',105), 'P6', 'D6');
insert into Medical_Records values ( 'Back Spasm', convert(date,'15-01-2023',105), 'P7', 'D6');
insert into Medical_Records values ( 'Headache', convert(date,'20-01-2023',105), 'P0', 'D7');

SQL for Beginners: A Complete Introduction to SQL Basics!
   • SQL for Beginners: A Complete Introduction...  

Master SQL Commands: DDL, Data Types & Constraints Explained!
   • Master SQL Commands: DDL, Data Types & Con...  

Mastering SQL Constraints: Primary Key, Unique Key, Not Null, and CHECK Explained!
   • Mastering SQL Constraints: Primary Key, Un...  

Understanding SQL Foreign Keys: Building Relationships Between Tables
   • Understanding SQL Foreign Keys: Building R...  

SQL Identity Column: Auto-Generating Unique Values for Your Tables
   • SQL Identity Column: Auto-Generating Uniqu...  

SQL DML & DDL Commands Explained | Insert, Update, Delete, Truncate, Drop
   • SQL DML & DDL Commands Explained | Insert,...  

Master Basic SQL Queries & Operators | Part 1: Fetch, Filter & Count
   • Master Basic SQL Queries & Operators | Par...  

SQL Functions and Queries: Aggregate, CAST, REPLACE, ROUND, GETDATE
   • SQL Functions and Queries: Aggregate, CAST...  

Mastering SQL INNER JOIN: Essential Queries & Examples
   • Mastering SQL INNER JOIN: Essential Querie...  

SQL Group By Explained with Examples | Master Aggregate Queries
   • SQL Group By Explained with Examples | Mas...  

Mastering SQL: Group By, Having, CASE, Order By, Join, Top, and Limit
   • Mastering SQL: Group By, Having, CASE, Ord...  

Introduction to SQL Normalization: 1NF (First Normal Form) - Part 1
   • Introduction to SQL Normalization: 1NF (Fi...  

Understanding SQL Normalization: 2NF (Second Normal Form) - Part 2
   • Understanding SQL Normalization: 2NF (Seco...  

Mastering SQL Normalization: 3NF (Third Normal Form) Explained - Part 3
   • Mastering SQL Normalization: 3NF (Third No...  

Master SQL Subqueries: Scalar, Multi-Row, and Correlated Subqueries Explained
   • Master SQL Subqueries: Scalar, Multi-Row, ...  

SQL Tutorial: Remove Duplicate Data Efficiently | Common Interview Question
   • SQL Tutorial: Remove Duplicate Data Effici...  

SQL Joins Explained: Master INNER, LEFT, RIGHT, FULL, CROSS & SELF Joins with Examples
   • SQL Joins Explained: Master INNER, LEFT, R...  

Master SQL Joins: Self Joins, Outer Joins, and More!
   • Master SQL Joins: Self Joins, Outer Joins,...  

SQL Queries Using CTE: Profitability & Monthly Sales Differences
   • SQL Queries Using CTE: Profitability & Mon...  

Calculate User Popularity Percentage with SQL CTEs
   • Calculate User Popularity Percentage with ...  

SQL Window Functions Explained: ROW_NUMBER, RANK & DENSE_RANK
   • SQL Window Functions Explained: ROW_NUMBER...  

SQL Window Functions Explained: LEAD & LAG with Real Examples!
   • SQL Window Functions Explained: LEAD & LAG...  

Master SQL Window Functions: FIRST_VALUE, LAST_VALUE, and More!
   • Master SQL Window Functions: FIRST_VALUE, ...  

Easily Delete Duplicate Rows in SQL Server with ROW_NUMBER()
   • Easily Delete Duplicate Rows in SQL Server...  

Understanding Recursive CTEs in SQL: A Simple Guide
   • Understanding Recursive CTEs in SQL: A Sim...  

Master SQL PIVOT: Transform Rows into Columns
   • Master SQL PIVOT: Transform Rows into Columns