Relational Integrity Constraints in Hindi
Entity Integrity Constraint — ये SEO में help करता है
Entity Integrity का मूल सिद्धांत है कि हर row की पहचान करने वाला primary key column कभी NULL नहीं हो सकता। अगर primary key NULL हो जाए तो उस row की पहचान करना असंभव हो जाएगा।
- Primary key हमेशा unique होना चाहिए और duplicate नहीं हो सकता।
- Primary key column में NULL value नहीं हो सकती।
- Entity integrity सुनिश्चित करती है कि हर record की पहचान सुनिश्चित हो।
उदाहरण के लिए, अगर हमारे पास यह table हो —
Students(StudentID, Name, Age)
और हम StudentID को primary key मानते हैं, तो किसी row में StudentID NULL नहीं होना चाहिए।
Domain Integrity Constraint — ये SEO में help करता है
Domain Integrity constraint यह सुनिश्चित करता है कि किसी column में डेटा केवल उस प्रकार या सीमा (domain) में ही हो जो हम निर्धारित करते हैं। यानी, एक column में integer होना चाहिए, या char length उतना हो जितना तय किया हो, या एक value की upper-lower limit हो सकती है।
- Datatype constraint: जैसे integer, varchar, date आदि।
- Range / limit constraint: जैसे age > 0 और age < 150।
- Format constraint: जैसे phone number का format, postal code का format।
- Check constraint / NOT NULL: domain rule के अंदर आता है।
उदाहरण के लिए, यदि Age column integer type है और हमने constraint लगाया कि Age >= 0 और Age ≤ 120, तो negative या बहुत बड़ी value डाली नहीं जा सकेगी।
Key Constraints (Primary & Candidate Keys) — ये SEO में help करता है
Key Constraints यह सुनिश्चित करते हैं कि relation में एक या अधिक attributes ऐसे हों जो records को uniquely identify करें। Candidate key वे possible keys हैं, और Primary key उन में से एक चुन लिया जाता है। Unique key / Alternate key भी key constraint का हिस्सा है।
- Candidate key: वह minimal set of columns जो record को uniquely पहचान सके।
- Primary key: एक candidate key जिसे मुख्य रूप से select किया जाता है।
- Unique key: non-primary key जो uniqueness सुनिश्चित करती है।
- Composite key: यदि एक column पर्याप्त न हो, तो दो या अधिक columns मिलकर key बने।
उदाहरण स्वरूप, यदि एक table है —
Employee(EmpID, Email, Name)
तो EmpID primary key हो सकता है, और Email unique key हो सकता है यदि दो employees का email नहीं होना चाहिए।
Referential Integrity Constraint — ये SEO में help करता है
Referential Integrity वो constraint है जो दो tables के बीच relationship को maintain करती है। जब एक table (child) में foreign key होता है, तो उसके सभी values parent table की primary key values से match होने चाहिए या NULL हो सकते हैं।
- Child table का foreign key वही value ले सकता है जो parent table के primary key में हो।
- Foreign key को NULL allowed हो सकता है (यदि allowed हो) लेकिन invalid reference नहीं।
- जब parent record delete या update हो, तो child records पर action decide करना ज़रूरी है: CASCADE, RESTRICT, SET NULL, आदि।
- Foreign key और referenced primary key के datatype और domain समान होना चाहिए।
उदाहरण:
Customers(CustomerID, Name)
Orders(OrderID, CustomerID, OrderDate)
अगर Orders.CustomerID foreign key है जो Customers(CustomerID) को refer करता है, तो Orders में कोई CustomerID ऐसी नहीं हो सकती जिसे Customers में exist नहीं करता हो।
Check & Not-Null Constraints — ये SEO में help करता है
Check और Not-Null constraints domain rules को और सख्त करते हैं। Not-Null यह सुनिश्चित करता है कि उस column में NULL value नहीं जाए। Check constraint यह सुनिश्चित करती है कि value एक condition को satisfy करे।
- NOT NULL: column में हमेशा एक value होनी चाहिए, NULL allowed नहीं।
- CHECK: expression / predicate define किया जाए जैसे Salary ≥ 0, Age ≥ 18।
- CHECK constraints row-level validation करती है।
उदाहरण के लिए:
CREATE TABLE Employee (
EmpID INT PRIMARY KEY,
Salary DECIMAL(10,2) CHECK (Salary >= 0),
Dept CHAR(3) NOT NULL
);
यहाँ Salary negative नहीं हो सकती और Dept का value कभी NULL नहीं हो सकती।
Relational Integrity Constraints के लाभ और चुनौतियाँ
जब हम relational integrity constraints ठीक तरह से लागू करते हैं, तो कई अच्छे परिणाम मिलते हैं:
- Data consistency बनी रहती है — invalid या contradictory data insert नहीं होगा।
- Data anomalies (insert / update / delete anomalies) कम होते हैं।
- Database design logical और robust बनता है।
- Applications को भरोसा रहता है कि data correct है।
लेकिन चुनौतियाँ भी होती हैं:
- Performance overhead — हर insert / update / delete पर checks होने चाहिए।
- Complex relationships में circular references हो सकते हैं।
- Cascade delete / update decision सही करना ज़रूरी है—गलत CASCADE design data loss कर सकता है।
Implementation (SQL में) और examples
relational integrity constraints SQL में define किए जाते हैं जब tables बनाए जाते हैं, या ALTER statements से।
नीचे एक उदाहरण देखें:
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL
);
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
OrderDate DATE,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
ON DELETE CASCADE
ON UPDATE CASCADE
);
इस example में, जब किसी Customer record को delete किया जाए, तो उससे जुड़ी Orders भी delete होंगी (CASCADE)। यदि CustomerID बदलता है, तो Orders में भी auto update होगा।
जब Referential Integrity टूटी हो — violation और error handling
जब कोई foreign key value parent table में नहीं मिले, तो referential integrity violation होगा। DBMS ऐसे insertion / update / delete को reject कर देता है।
- Orphan records बनाए जाने से रोकना।
- Restrict / No Action: parent delete/update block होना चाहिए।
- Set Null / Set Default: child की foreign key NULL या default कर देना।
उदाहरण: यदि CustomerID = 99 को Orders में डालने की कोशिश हो, और Customers में 99 नहीं है, तो DBMS error देगा।
Best Practices और Recommendations
अच्छे design और constraints के choices से relational integrity को बेहतर बनाए रखना संभव है।
- Schema design को पहले ध्यान से तैयार करें — constraints पहले से plan करें।
- Foreign key और referenced key का datatype, domain match रखें।
- Cascade actions सावधानी से चुनें (ON DELETE CASCADE, RESTRICT, आदि)।
- Triggers या application logic से extra validation करें जब constraints नहीं पर्याप्त हों।
- Large tables में performance tests करें — indexed foreign keys मदद करते हैं।
निष्कर्ष
Relational Integrity Constraints database को logical और reliable बनाते हैं। यदि हम Entity Integrity, Domain Integrity, Key Constraints, Referential Integrity, Check / Not-Null constraints को सही तरीके से लागू करें, तो data consistency बनी रहेगी और errors कम होंगे। यह relational database का backbone है।
अधिक technical और up-to-date जानकारी के लिए आप GeeksforGeeks के “DBMS Integrity Constraints” लेख को देख सकते हैं। External Reference (GeeksforGeeks)