SQL Databases
Think of a school register. Each student has one line, and every line has the same columns: name, class, email. A SQL database is a very strict register, and it refuses a line that breaks its rules.
6 min read6 মিনিটে পড়া যায় · 8 sections8টি সেকশন · 7 sources7টি সোর্স · updated Oct 2026আপডেট: Oct 2026
Constraints refuse bad rowsকনস্ট্রেইন্ট খারাপ রো ফেরত দেয়
Insert rows and watch NOT NULL, UNIQUE, CHECK and FOREIGN KEY accept or reject them. Then pick what a delete does.রো ঢোকান আর দেখুন NOT NULL, UNIQUE, CHECK ও FOREIGN KEY সেগুলো নেয় বা ফেরত দেয়। তারপর বেছে নিন মুছলে কী হবে।
You’ll learnআপনি শিখবেন
- What NOT NULL refusesNOT NULL কী ফেরত দেয়
- What UNIQUE refusesUNIQUE কী ফেরত দেয়
- How CHECK and FOREIGN KEY reject a rowCHECK ও FOREIGN KEY কীভাবে রো ফেরত দেয়
- What each delete rule doesমোছার প্রতিটা নিয়ম কী করে
In plain words
A SQL database is a relational database: it stores data in relations, and "relation" is the math word for table Source 1সোর্স 1. A table is a named collection of rows. Every row has the same named columns, and each column has a data type Source 1সোর্স 1. The set of columns is fixed, but the number of rows grows and shrinks with the data Source 2সোর্স 2.
The data type limits what a column accepts. A number column refuses arbitrary text Source 2সোর্স 2. To make a table, you give CREATE TABLE a name, the column names, and a type for each column. DROP TABLE removes it Source 2সোর্স 2.
Two facts surprise new testers:
- SQL does not promise any row order. Rows come back in an unspecified order unless you ask for sorting Source 2সোর্স 2.
- SQL does not give rows an identity by itself, so two rows can be fully identical Source 2সোর্স 2. Keys fix this.
সহজ English
A SQL database is a relational database. It stores data in relations. "Relation" is the math word for table Source 1সোর্স 1. A table is a named collection of rows. Every row has the same named columns. Each column has a data type Source 1সোর্স 1. The set of columns is fixed. The number of rows grows and shrinks with the data Source 2সোর্স 2.
The data type limits what a column accepts. A number column refuses arbitrary text Source 2সোর্স 2. To make a table, give CREATE TABLE a name, the column names, and a type for each column. DROP TABLE removes the table Source 2সোর্স 2.
Two facts surprise new testers:
- SQL does not promise any row order. Rows come back in an unspecified order unless you ask for sorting Source 2সোর্স 2.
- SQL does not give rows an identity by itself. So two rows can be fully identical Source 2সোর্স 2. Keys fix this.
বাংলা ব্যাখ্যা
SQL ডেটাবেস হলো একটি রিলেশনাল ডেটাবেস। এটি ডেটা রাখে রিলেশনে। "রিলেশন" হলো টেবিলের গাণিতিক নাম Source 1সোর্স 1। টেবিল হলো রো-এর একটি নামযুক্ত সংগ্রহ। প্রতিটি রো-তে একই নামের কলাম থাকে। প্রতিটি কলামের একটি ডেটা টাইপ আছে Source 1সোর্স 1। কলামের সেট স্থির। কিন্তু রো-র সংখ্যা ডেটা অনুযায়ী বাড়ে আর কমে Source 2সোর্স 2।
ডেটা টাইপ ঠিক করে দেয় একটি কলাম কী গ্রহণ করবে। একটি সংখ্যার কলাম যেকোনো টেক্সট প্রত্যাখ্যান করে Source 2সোর্স 2। টেবিল বানাতে CREATE TABLE-কে একটি নাম, কলামের নাম আর প্রতিটি কলামের একটি টাইপ দিন। DROP TABLE টেবিল মুছে ফেলে Source 2সোর্স 2।
দুটি তথ্য নতুন টেস্টারদের অবাক করে:
- SQL কোনো রো-র ক্রমের প্রতিশ্রুতি দেয় না। আপনি সর্ট করতে না বললে রো অনির্দিষ্ট ক্রমে ফিরে আসে Source 2সোর্স 2।
- SQL নিজে থেকে রো-কে কোনো পরিচয় দেয় না। তাই দুটি রো সম্পূর্ণ একই হতে পারে Source 2সোর্স 2। কী (key) এটি ঠিক করে।
Keys and constraints
A data type is often too coarse a rule. A constraint is a stronger rule. If a value would break a constraint, the database raises an error, even when the value comes from a default Source 3সোর্স 3.
| Constraint | What it does |
|---|---|
NOT NULL | The column must not hold the null value Source 3সোর্স 3 |
UNIQUE | The values of a column, or of a group of columns, are unique among all rows Source 3সোর্স 3 |
PRIMARY KEY | The unique identifier of a row: values are unique and not null Source 3সোর্স 3 |
FOREIGN KEY | The values must match a row in another table Source 3সোর্স 3 |
CHECK | A true-or-false expression that the value must satisfy Source 3সোর্স 3 |
A table has at most one primary key. PostgreSQL does not force you to declare one, but the manual says it is usually best Source 3সোর্স 3. A primary key can use more than one column Source 3সোর্স 3.
A foreign key keeps the link between two tables correct. This is called referential integrity Source 3সোর্স 3. With a foreign key, an order cannot name a product that is missing from the products table, unless the column is null Source 3সোর্স 3. The table with the foreign key is the referencing table, and the other one is the referenced table Source 3সোর্স 3.
You choose what happens when someone deletes a referenced row. The default, NO ACTION, usually gives an error. RESTRICT blocks the delete. CASCADE also deletes the rows that point to it. SET NULL and SET DEFAULT change the pointing column instead Source 3সোর্স 3.
সহজ English
A data type is often too coarse a rule. A constraint is a stronger rule. If a value would break a constraint, the database raises an error. This holds even when the value comes from a default Source 3সোর্স 3.
NOT NULL: the column must not hold the null value Source 3সোর্স 3.UNIQUE: the values of a column, or of a group of columns, are unique among all rows Source 3সোর্স 3.PRIMARY KEY: the unique identifier of a row. The values are unique and not null Source 3সোর্স 3.FOREIGN KEY: the values must match a row in another table Source 3সোর্স 3.CHECK: a true-or-false expression that the value must satisfy Source 3সোর্স 3.
A table has at most one primary key. PostgreSQL does not force you to declare one, but the manual says it is usually best Source 3সোর্স 3. A primary key can use more than one column Source 3সোর্স 3.
A foreign key keeps the link between two tables correct. This is called referential integrity Source 3সোর্স 3. With a foreign key, an order cannot name a product that is missing from the products table, unless the column is null Source 3সোর্স 3. The table with the foreign key is the referencing table. The other table is the referenced table Source 3সোর্স 3.
You choose what happens when someone deletes a referenced row. The default, NO ACTION, usually gives an error. RESTRICT blocks the delete. CASCADE also deletes the rows that point to it. SET NULL and SET DEFAULT change the pointing column instead Source 3সোর্স 3.
বাংলা ব্যাখ্যা
একটি ডেটা টাইপ প্রায়ই খুব মোটা নিয়ম। কনস্ট্রেইন্ট (constraint) হলো আরও শক্ত নিয়ম। কোনো ভ্যালু কনস্ট্রেইন্ট ভাঙলে ডেটাবেস এরর দেয়। ভ্যালু ডিফল্ট থেকে এলেও এটি সত্য Source 3সোর্স 3।
NOT NULL: কলাম নাল ভ্যালু ধারণ করতে পারবে না Source 3সোর্স 3।UNIQUE: একটি কলামের, বা একদল কলামের, ভ্যালু সব রো-র মধ্যে ইউনিক Source 3সোর্স 3।PRIMARY KEY: একটি রো-র ইউনিক আইডেন্টিফায়ার। ভ্যালু ইউনিক এবং নাল নয় Source 3সোর্স 3।FOREIGN KEY: ভ্যালু অবশ্যই অন্য টেবিলের একটি রো-র সঙ্গে মিলতে হবে Source 3সোর্স 3।CHECK: একটি সত্য-অথবা-মিথ্যা এক্সপ্রেশন, যা ভ্যালুকে অবশ্যই পূরণ করতে হবে Source 3সোর্স 3।
একটি টেবিলে সর্বোচ্চ একটি প্রাইমারি কী থাকে। PostgreSQL আপনাকে একটি ঘোষণা করতে বাধ্য করে না, তবে ম্যানুয়াল বলে সাধারণত এটিই ভালো Source 3সোর্স 3। একটি প্রাইমারি কী একাধিক কলাম ব্যবহার করতে পারে Source 3সোর্স 3।
ফরেন কী (foreign key) দুই টেবিলের মধ্যকার যোগ ঠিক রাখে। একে বলে রেফারেন্সিয়াল ইন্টেগ্রিটি (referential integrity) Source 3সোর্স 3। ফরেন কী থাকলে কলাম নাল না হলে একটি অর্ডার এমন প্রোডাক্টের নাম দিতে পারে না, যা প্রোডাক্ট টেবিলে নেই Source 3সোর্স 3। যে টেবিলে ফরেন কী আছে সেটি রেফারেন্সিং টেবিল। অন্যটি রেফারেন্সড টেবিল Source 3সোর্স 3।
কেউ রেফারেন্সড রো মুছে দিলে কী হবে, তা আপনি বেছে নেন। ডিফল্ট NO ACTION সাধারণত এরর দেয়। RESTRICT মোছা আটকে দেয়। CASCADE তার দিকে নির্দেশ করা রো-গুলোও মুছে দেয়। SET NULL আর SET DEFAULT তার বদলে নির্দেশ-করা কলাম বদলে দেয় Source 3সোর্স 3।
The four basic statements
CREATE TABLE students (
student_id integer PRIMARY KEY,
email text NOT NULL UNIQUE,
name text NOT NULL
);
CREATE TABLE enrollments (
enrollment_id integer PRIMARY KEY,
student_id integer NOT NULL REFERENCES students,
course text NOT NULL,
score integer CHECK (score BETWEEN 0 AND 100)
);
INSERT INTO students (student_id, email, name)
VALUES (1, 'ada@example.com', 'Ada');
SELECT name, email FROM students WHERE student_id = 1;
UPDATE students SET name = 'Ada L.' WHERE student_id = 1;
DELETE FROM enrollments WHERE enrollment_id = 7;The tables above are the tutorial's own example.
- SELECT reads data. It has a select list, a table list, and an optional
WHERESource 4সোর্স 4.*means all columns Source 4সোর্স 4.WHEREkeeps only the rows where its expression is true, and you can combine tests withAND,OR, andNOTSource 4সোর্স 4.ORDER BYsorts the result. If the sort is not fully given, rows with equal values can come in either order Source 4সোর্স 4. - INSERT adds rows. A column that you leave out gets its default value, or null if it has none Source 5সোর্স 5. You can list the columns in any order, and the values match them left to right Source 5সোর্স 5.
- UPDATE changes the listed columns in every row that meets the condition. The other columns keep their values Source 6সোর্স 6. Only rows for which the condition is true change Source 6সোর্স 6.
- DELETE removes the rows that meet the condition Source 7সোর্স 7. Without a
WHERE, it removes all rows and leaves an empty table Source 7সোর্স 7.
সহজ English
The example in the Technical text makes two tables, students and enrollments. It then runs the four basic statements on them. The tables are the tutorial's own example.
- SELECT reads data. It has a select list, a table list, and an optional
WHERESource 4সোর্স 4.*means all columns Source 4সোর্স 4.WHEREkeeps only the rows where its expression is true. You can combine tests withAND,OR, andNOTSource 4সোর্স 4.ORDER BYsorts the result. If the sort is not fully given, rows with equal values can come in either order Source 4সোর্স 4. - INSERT adds rows. A column that you leave out gets its default value, or null if it has none Source 5সোর্স 5. You can list the columns in any order. The values match them from left to right Source 5সোর্স 5.
- UPDATE changes the listed columns in every row that meets the condition. The other columns keep their values Source 6সোর্স 6. Only rows for which the condition is true change Source 6সোর্স 6.
- DELETE removes the rows that meet the condition Source 7সোর্স 7. Without a
WHERE, it removes all rows and leaves an empty table Source 7সোর্স 7.
বাংলা ব্যাখ্যা
Technical অংশের উদাহরণে students আর enrollments নামে দুটি টেবিল বানানো হয়েছে। তারপর সেগুলোর উপর চারটি মৌলিক স্টেটমেন্ট চালানো হয়েছে। টেবিল দুটি টিউটোরিয়ালের নিজস্ব উদাহরণ।
- SELECT ডেটা পড়ে। এতে থাকে একটি সিলেক্ট লিস্ট, একটি টেবিল লিস্ট আর ঐচ্ছিক
WHERESource 4সোর্স 4।*মানে সব কলাম Source 4সোর্স 4।WHEREশুধু সেই রো-গুলো রাখে, যেখানে তার এক্সপ্রেশন সত্য। আপনিAND,ORআরNOTদিয়ে শর্ত জুড়তে পারেন Source 4সোর্স 4।ORDER BYফলাফল সর্ট করে। সর্ট পুরোপুরি না দেওয়া হলে সমান ভ্যালুর রো যেকোনো ক্রমে আসতে পারে Source 4সোর্স 4। - INSERT রো যোগ করে। যে কলাম আপনি বাদ দেন, সে তার ডিফল্ট ভ্যালু পায়, বা ডিফল্ট না থাকলে নাল পায় Source 5সোর্স 5। আপনি কলাম যেকোনো ক্রমে লিখতে পারেন। ভ্যালুগুলো বাঁ থেকে ডানে সেগুলোর সঙ্গে মেলে Source 5সোর্স 5।
- UPDATE শর্ত পূরণকারী প্রতিটি রো-তে তালিকাভুক্ত কলাম বদলায়। অন্য কলামের ভ্যালু আগের মতোই থাকে Source 6সোর্স 6। শুধু যেসব রো-র জন্য শর্ত সত্য, সেগুলোই বদলায় Source 6সোর্স 6।
- DELETE শর্ত পূরণকারী রো মুছে ফেলে Source 7সোর্স 7।
WHEREছাড়া এটি সব রো মুছে ফেলে এবং একটি খালি টেবিল রেখে যায় Source 7সোর্স 7।
When you need it
Most apps keep their important records in a SQL database: users, orders, payments, bookings. A tester uses SQL to prepare test data and to check that an action in the app wrote the right rows.
সহজ English
Most apps keep their important records in a SQL database. Examples are users, orders, payments, and bookings. A tester uses SQL to prepare test data. A tester also uses SQL to check that an action in the app wrote the right rows.
বাংলা ব্যাখ্যা
বেশিরভাগ অ্যাপ তাদের গুরুত্বপূর্ণ রেকর্ড একটি SQL ডেটাবেসে রাখে। যেমন ইউজার, অর্ডার, পেমেন্ট আর বুকিং। টেস্টার টেস্ট ডেটা তৈরি করতে SQL ব্যবহার করে। অ্যাপের কোনো অ্যাকশন সঠিক রো লিখেছে কি না, তা যাচাই করতেও টেস্টার SQL ব্যবহার করে।
A real-life example
A learning platform uses the two tables above. Ada enrolls in a course and gets score 85.
The tester tries three bad actions. A second student with ada@example.com fails, because of UNIQUE. A score of 120 fails, because of CHECK. An enrollment for student_id 99, who does not exist, fails, because of the foreign key. Each time the database raises an error, and the app must show a clear message.
A score of NULL is a different case. A CHECK passes when the expression is true or null, so the check alone does not stop nulls Source 3সোর্স 3. The tester must know which columns carry NOT NULL.
সহজ English
A learning platform uses the two tables above. Ada enrolls in a course and gets score 85.
The tester tries three bad actions.
- A second student with
ada@example.comfails, because ofUNIQUE. - A score of 120 fails, because of
CHECK. - An enrollment for
student_id99, who does not exist, fails, because of the foreign key.
Each time the database raises an error. The app must show a clear message.
A score of NULL is a different case. A CHECK passes when the expression is true or null. So the check alone does not stop nulls Source 3সোর্স 3. The tester must know which columns carry NOT NULL.
বাংলা ব্যাখ্যা
একটি লার্নিং প্ল্যাটফর্ম উপরের দুটি টেবিল ব্যবহার করে। Ada একটি কোর্সে এনরোল করে এবং স্কোর 85 পায়।
টেস্টার তিনটি খারাপ অ্যাকশন চেষ্টা করে।
ada@example.comসহ দ্বিতীয় একজন স্টুডেন্ট ফেইল করে,UNIQUE-এর কারণে।- 120 স্কোর ফেইল করে,
CHECK-এর কারণে। student_id99-এর জন্য একটি এনরোলমেন্ট, যে স্টুডেন্ট নেই, ফেইল করে, ফরেন কী-র কারণে।
প্রতিবার ডেটাবেস এরর দেয়। অ্যাপকে একটি স্পষ্ট মেসেজ দেখাতে হবে।
NULL স্কোর আলাদা একটি ঘটনা। এক্সপ্রেশন সত্য বা নাল হলে CHECK পাস করে। তাই শুধু CHECK নাল আটকায় না Source 3সোর্স 3। কোন কলামে NOT NULL আছে, তা টেস্টারকে জানতে হবে।
Common mistakes
- Trusting row order. Without
ORDER BYthe order is not defined Source 2সোর্স 2. - Thinking
CHECKblocks nulls. It does not. UseNOT NULLfor that Source 3সোর্স 3. - Expecting
UNIQUEto stop two nulls. By default two nulls are not equal, so rows with a null can repeat. The standard leaves this default to each database, so other systems can differ Source 3সোর্স 3. - Forgetting
WHEREon aDELETE. All rows go Source 7সোর্স 7. For clearing a whole table,TRUNCATEis the faster way Source 7সোর্স 7.
সহজ English
- Trusting row order. Without
ORDER BYthe order is not defined Source 2সোর্স 2. - Thinking
CHECKblocks nulls. It does not. UseNOT NULLfor that Source 3সোর্স 3. - Expecting
UNIQUEto stop two nulls. By default two nulls are not equal. So rows with a null can repeat. The standard leaves this default to each database, so other systems can differ Source 3সোর্স 3. - Forgetting
WHEREon aDELETE. All rows go Source 7সোর্স 7. To clear a whole table,TRUNCATEis the faster way Source 7সোর্স 7.
বাংলা ব্যাখ্যা
- রো-র ক্রমের উপর ভরসা করা।
ORDER BYছাড়া ক্রম নির্ধারিত নয় Source 2সোর্স 2। - ভাবা যে
CHECKনাল আটকায়। সে আটকায় না। সেজন্যNOT NULLব্যবহার করুন Source 3সোর্স 3। - আশা করা যে
UNIQUEদুটি নাল আটকাবে। ডিফল্টে দুটি নাল সমান নয়। তাই নাল-যুক্ত রো পুনরাবৃত্ত হতে পারে। স্ট্যান্ডার্ড এই ডিফল্ট প্রতিটি ডেটাবেসের হাতে ছেড়ে দেয়, তাই অন্য সিস্টেম আলাদা হতে পারে Source 3সোর্স 3। DELETE-এWHEREভুলে যাওয়া। সব রো চলে যায় Source 7সোর্স 7। পুরো টেবিল খালি করতেTRUNCATEদ্রুততর উপায় Source 7সোর্স 7।
What a tester can check
Tutorial advice
These test ideas are the tutorial's own advice.
- Break each rule once. For each
NOT NULL,UNIQUE,CHECK, and foreign key, send data that breaks it. Check the error in the app and that no row was written. - Check the row, not only the screen. After a form submit, run a
SELECTfor that row and compare each column. - Test the delete rules. Delete a parent record that has children. Check that the app does what the foreign key says: block, cascade, or set null.
- Write
WHEREfirst. In a test script, write theWHEREof anUPDATEorDELETEbefore the rest, and run it as aSELECTfirst.
সহজ English
These test ideas are the tutorial's own advice.
- Break each rule once. For each
NOT NULL,UNIQUE,CHECK, and foreign key, send data that breaks it. Check the error in the app and that no row was written. - Check the row, not only the screen. After a form submit, run a
SELECTfor that row and compare each column. - Test the delete rules. Delete a parent record that has children. Check that the app does what the foreign key says: block, cascade, or set null.
- Write
WHEREfirst. In a test script, write theWHEREof anUPDATEorDELETEbefore the rest. Run it as aSELECTfirst.
বাংলা ব্যাখ্যা
এই টেস্টের ধারণাগুলো টিউটোরিয়ালের নিজস্ব পরামর্শ।
- প্রতিটি নিয়ম একবার ভাঙুন। প্রতিটি
NOT NULL,UNIQUE,CHECKআর ফরেন কী-র জন্য এমন ডেটা পাঠান, যা সেটি ভাঙে। অ্যাপে এরর যাচাই করুন, আর যাচাই করুন যে কোনো রো লেখা হয়নি। - শুধু স্ক্রিন নয়, রো-টি দেখুন। ফর্ম সাবমিট করার পর সেই রো-র জন্য একটি
SELECTচালান এবং প্রতিটি কলাম মিলিয়ে দেখুন। - ডিলিটের নিয়ম টেস্ট করুন। চাইল্ড রেকর্ড আছে এমন একটি প্যারেন্ট রেকর্ড মুছুন। যাচাই করুন যে ফরেন কী যা বলে অ্যাপ তা-ই করে: ব্লক, ক্যাসকেড, বা সেট নাল।
- আগে
WHEREলিখুন। টেস্ট স্ক্রিপ্টেUPDATEবাDELETE-এরWHEREবাকি অংশের আগে লিখুন। আগে এটিকে একটিSELECTহিসেবে চালান।
Key words
| Word | Meaning |
|---|---|
| Table | A named collection of rows Source 1সোর্স 1 |
| Row | One record of a table, with the same columns as the other rows Source 1সোর্স 1 |
| Column | A named field with a data type Source 1সোর্স 1 |
| Primary key | The unique, not-null identifier of the rows of a table Source 3সোর্স 3 |
| Foreign key | A column whose values must match a row of another table Source 3সোর্স 3 |
| Constraint | A rule on the data. A value that breaks it raises an error Source 3সোর্স 3 |
| Referential integrity | The link between two tables stays correct Source 3সোর্স 3 |