Types of Constraint & Key Constraint | SQL- MySQL | Belayet Hossain
Belayet Hossain ??
Data Analyst @ZnZ ? Power BI, SQL, Excel, Python (ETL), MySQL, Oracle, DBeaver ? Find insight & Making Decision ? Ex-Head of Quality Dept & 09 Y With smartphone Manufacturing & Service ? Ex- RFL, VIVO, Symphony ? EEE
??????????????????????:
Constraints are "Restrictions, Conditions, or Business Rules" that are applied when storing data in a table. Constraints are applied to various columns during table creation.
?
???????? ???? ????????????????????:
?
→ ???????????? ??????????????????:
If a UNIQUE Constraint is applied to a column in a table, no duplicate values can be inserted into that column.
Unique constrains accept the NULL value.
The UNIQUE Constraint ensures that all values in a column or combination of columns are distinct.
?
→ ?????? ???????? ??????????????????:
If a NOT NULL Constraint is applied to a column in a table, no NULL values can be inserted into that column.
The NOT NULL Constraint is used to ensure that a column cannot have a NULL value. It enforces that a value must always be provided for the column when inserting or updating a record.
?
→ ?????????????? ????????????????????:
The DEFAULT Constraint is used to provide a default value for a column when no value is specified during the insertion of a record. It ensures that a column always has a value, even if the user does not explicitly supply one.
?
→ ?????????? ????????????????????:
The CHECK Constraint is used to enforce a condition on the values entered into a specific column. It ensures that the data in a column meets the specified criteria. If a row violates the condition, the database rejects the insertion or update.
?
领英推荐
?????? ???? ??????
A KEY in SQL is a set of one or more columns used to uniquely identify rows in a database table
?
→ ?????????????????? ?????? in SQL
A CANDIDATE KEY is a set of one or more columns in a table that can uniquely identify each row in the table. There can be multiple candidate keys in a table, and each of them can serve as the primary key. The PRIMARY KEY is chosen from the candidate keys, while the others are referred to as ALTERNATIVE KEYS.
→ ?????????? ?????? in SQL
A SUPER KEY is a set of one or more columns that can uniquely identify each row in a table. A super key can include additional attributes beyond what is necessary to uniquely identify a row. Thus, ALL CANDIDATE KEYS ARE SUPER KEYS, but not all super keys are candidate keys.
→ ?????????????????????? ?????? in SQL
An ALTERNATIVE KEY is any candidate key that is not selected as the PRIMARY KEY. Since the PRIMARY KEY is chosen from the candidate keys, the other candidate keys are referred to as ALTERNATIVE KEYS.
?
→ ?????????????? ??????:
The key through which we can uniquely identify each tuple/row of a table is called the PRIMARY KEY. Note: The value of a PRIMARY KEY must be unique and cannot contain NULL values.
A PRIMARY KEY is a column (or a set of columns) that uniquely identifies each row in a table. It ensures that each record in the table is distinct.
?
→ ?????????????? ??????:
If the PRIMARY KEY of one table is used as a Reference KEY in another table, then that key is called a FOREIGN KEY.
A FOREIGN KEY is a column (or a set of columns) in one table that uniquely identifies a row of another table. It is used to establish and enforce a link between the data in two tables.
--Business Analyst |skilled in Power BI, SQL and Advanced Excel| Data analysis and Visualization| Market Research
2 个月Very helpful