TGViewer
Data Analytics Data Analytics @sqlspecialist ยท 111K subscribers
Post #2375 7.01K
โœ… SQL Constraints ๐Ÿ“Š๐Ÿ›ก๏ธ

Constraints are the rules that keep your database clean & accurate.

๐Ÿ”น 1. PRIMARY KEY
โžค Uniquely identifies each row in a table
โžค Cannot be NULL or duplicated
CREATE TABLE users (
user_id INT PRIMARY KEY,
name VARCHAR(50)
);
๐Ÿ”น 2. FOREIGN KEY
โžค Links to a primary key in another table
โžค Ensures data consistency across tables
CREATE TABLE orders (
order_id INT PRIMARY KEY,
user_id INT,
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
๐Ÿ”น 3. UNIQUE
โžค Ensures all values in a column are different
CREATE TABLE employees (
id INT PRIMARY KEY,
email VARCHAR(100) UNIQUE
);
๐Ÿ”น 4. NOT NULL
โžค Column cannot have NULL (empty) values
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL
);
๐Ÿ”น 5. CHECK
โžค Limits the values that can be entered
CREATE TABLE students (
id INT PRIMARY KEY,
age INT CHECK (age >= 18)
);
๐Ÿ”น 6. DEFAULT
โžค Automatically sets a default value
CREATE TABLE orders (
id INT PRIMARY KEY,
status VARCHAR(20) DEFAULT 'Pending'
);
๐ŸŽฏ Why Constraints Matter:
โœ”๏ธ No duplicates
โœ”๏ธ No missing data
โœ”๏ธ Valid and consistent values
โœ”๏ธ Reliable database performance

SQL Roadmap: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v/1394

๐Ÿ‘ Tap โค๏ธ for more!
  • โค 17
  • ๐Ÿ‘ 3
More from @sqlspecialist
  1. Oct 13, 2026๐Ÿ“Š Data Analyst Interview Series โ€” Part 9 Guys, let's continue our Data Analyst Interviewโ€ฆ
  2. Oct 13, 2026๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! Explorโ€ฆ
  3. Oct 12, 20268๏ธโƒฃ You receive a dataset with inconsistent date formats. How would you clean it? Sample Aโ€ฆ
  4. Oct 12, 2026๐Ÿ“Š Data Analyst Interview Series โ€” Part 7 Guys, let's continue our Data Analyst Interviewโ€ฆ
  5. Oct 12, 2026๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ? Want to builโ€ฆ
  6. Oct 9, 2026โ€œHere, the data is sorted by the second column in descending order and the first five rowsโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’