Skip to contentমূল লেখায় যান

Topic 15 · Courseটপিক 15 · Course

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 সেগুলো নেয় বা ফেরত দেয়। তারপর বেছে নিন মুছলে কী হবে।

2 min2 মিনিট8 steps8টি ধাপ
  • Rows: students / enrollmentsরো: students / enrollments0 / 0
  • Rows rejectedপ্রত্যাখ্যাত রো0
FOREIGN KEYFOREIGN KEYappঅ্যাপstudentsstudents0 rows0 রোenrollmentsenrollments0 rows0 রোNOT NULLNOT NULLreadyপ্রস্তুতUNIQUEUNIQUEreadyপ্রস্তুতCHECKCHECKreadyপ্রস্তুতFOREIGN KEYFOREIGN KEYreadyপ্রস্তুত

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:

সহজ 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 ডেটাবেস হলো একটি রিলেশনাল ডেটাবেস। এটি ডেটা রাখে রিলেশনে। "রিলেশন" হলো টেবিলের গাণিতিক নাম 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.

ConstraintWhat it does
NOT NULLThe column must not hold the null value Source 3সোর্স 3
UNIQUEThe values of a column, or of a group of columns, are unique among all rows Source 3সোর্স 3
PRIMARY KEYThe unique identifier of a row: values are unique and not null Source 3সোর্স 3
FOREIGN KEYThe values must match a row in another table Source 3সোর্স 3
CHECKA 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.

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.

সহজ 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.

বাংলা ব্যাখ্যা

Technical অংশের উদাহরণে students আর enrollments নামে দুটি টেবিল বানানো হয়েছে। তারপর সেগুলোর উপর চারটি মৌলিক স্টেটমেন্ট চালানো হয়েছে। টেবিল দুটি টিউটোরিয়ালের নিজস্ব উদাহরণ।

  • SELECT ডেটা পড়ে। এতে থাকে একটি সিলেক্ট লিস্ট, একটি টেবিল লিস্ট আর ঐচ্ছিক WHERE Source 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.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. 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_id 99-এর জন্য একটি এনরোলমেন্ট, যে স্টুডেন্ট নেই, ফেইল করে, ফরেন কী-র কারণে।

প্রতিবার ডেটাবেস এরর দেয়। অ্যাপকে একটি স্পষ্ট মেসেজ দেখাতে হবে।

NULL স্কোর আলাদা একটি ঘটনা। এক্সপ্রেশন সত্য বা নাল হলে CHECK পাস করে। তাই শুধু CHECK নাল আটকায় না Source 3সোর্স 3। কোন কলামে NOT NULL আছে, তা টেস্টারকে জানতে হবে।

Common mistakes

সহজ English

বাংলা ব্যাখ্যা

  • রো-র ক্রমের উপর ভরসা করা। 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 SELECT for 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 WHERE first. In a test script, write the WHERE of an UPDATE or DELETE before the rest, and run it as a SELECT first.

সহজ 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 SELECT for 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 WHERE first. In a test script, write the WHERE of an UPDATE or DELETE before the rest. Run it as a SELECT first.

বাংলা ব্যাখ্যা

এই টেস্টের ধারণাগুলো টিউটোরিয়ালের নিজস্ব পরামর্শ।

  • প্রতিটি নিয়ম একবার ভাঙুন। প্রতিটি NOT NULL, UNIQUE, CHECK আর ফরেন কী-র জন্য এমন ডেটা পাঠান, যা সেটি ভাঙে। অ্যাপে এরর যাচাই করুন, আর যাচাই করুন যে কোনো রো লেখা হয়নি।
  • শুধু স্ক্রিন নয়, রো-টি দেখুন। ফর্ম সাবমিট করার পর সেই রো-র জন্য একটি SELECT চালান এবং প্রতিটি কলাম মিলিয়ে দেখুন।
  • ডিলিটের নিয়ম টেস্ট করুন। চাইল্ড রেকর্ড আছে এমন একটি প্যারেন্ট রেকর্ড মুছুন। যাচাই করুন যে ফরেন কী যা বলে অ্যাপ তা-ই করে: ব্লক, ক্যাসকেড, বা সেট নাল।
  • আগে WHERE লিখুন। টেস্ট স্ক্রিপ্টে UPDATE বা DELETE-এর WHERE বাকি অংশের আগে লিখুন। আগে এটিকে একটি SELECT হিসেবে চালান।

Key words

WordMeaning
TableA named collection of rows Source 1সোর্স 1
RowOne record of a table, with the same columns as the other rows Source 1সোর্স 1
ColumnA named field with a data type Source 1সোর্স 1
Primary keyThe unique, not-null identifier of the rows of a table Source 3সোর্স 3
Foreign keyA column whose values must match a row of another table Source 3সোর্স 3
ConstraintA rule on the data. A value that breaks it raises an error Source 3সোর্স 3
Referential integrityThe link between two tables stays correct Source 3সোর্স 3

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    2.2. Concepts

    PostgreSQL Documentation · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  2. [2]
    5.1. Table Basics

    PostgreSQL Documentation · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  3. [3]
    5.5. Constraints

    PostgreSQL Documentation · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  4. [4]
    2.5. Querying a Table

    PostgreSQL Documentation · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  5. [5]
    INSERT

    PostgreSQL Documentation · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  6. [6]
    UPDATE

    PostgreSQL Documentation · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  7. [7]
    DELETE

    PostgreSQL Documentation · accessed 2026-10-22দেখা হয়েছে: 2026-10-22