Practical-93

Practical – 93 : MY SQLમાં ડેટા ઈન્ટીગ્રીટીના નિયમ લાગુ કરવા

What is Integrity Constraints ?

Integrity constraints in SQL are rules enforced on database tables to maintain data accuracy, consistency, and validity, such as ensuring unique primary keys and valid foreign key relationships.

Types of Integrity Constraints ?

    • PRIMARY KEY: Uniquely identifies each record in a table.
    • NOT NULL: Ensures a column cannot contain NULL values.
    • UNIQUE: Ensures that all values in a column or group of columns are unique.
    • DEFAULT: Provides a default value for a column when none is specified.
    • CHECK: Ensures that all values in a column satisfy a specific condition.
    • FOREIGN KEY: Establishes relationships between tables by referencing a primary key in another table.

1 – Domain Constraint

MySQL માં, ” domain constraints ” નો અર્થ એ છે કે કોલમની અંદર ડેટાની માન્યતાને સુનિશ્ચિત કરવી, જે તે મૂલ્યોને મર્યાદિત કરી શકે છે. જ્યારે MySQL પાસે અન્ય ડેટાબેઝ સિસ્ટમ્સની જેમ સ્પષ્ટ “ડોમેન્સ” નથી, તે જ કાર્યક્ષમતા વિવિધ અવરોધ પ્રકારો દ્વારા પ્રાપ્ત કરી શકાય છે, જેમાં NOT NULL, CHECK, UNIQUE, DEFAULT અને ENUMનો સમાવેશ થાય છે. આ અવરોધો માન્ય મૂલ્યોને વ્યાખ્યાયિત કરે છે અને ખાતરી કરે છે કે ડેટા ચોક્કસ નિયમોનું પાલન કરે છે, આમ ડેટા અખંડિતતા જાળવી રાખે છે.

2 – Entity Constraint

An entity constraint describes, in terms of entity objects and attributes, the database-level relationships between tables and columns. You select the entity object’s attributes and define the constraint in terms of database integrity constraints such as primary, foreign, check, or unique

3 – Referential Constraint

Referential constraints can be defined in the CREATE TABLE statement or the ALTER TABLE statement. Referential constraints are enforced by the database manager during the execution of INSERT, UPDATE, DELETE, ALTER TABLE, MERGE, ADD CONSTRAINT, and SET INTEGRITY statements.

4 – User Defined Constraint

A user-defined table constraint is a type of matrix that is used to describe the combinations of attribute values that are defined by attribute types. For example, if you produce speakers, you can include columns for the cabinet finish and the front grill in the user-defined table constraint.