What are constraints in DDL
In Data Definition Language (DDL), constraints are rules applied to database columns or tables to ensure data integrity and consistency. Key types of constraints include:
1. **Primary Key:** Ensures each row in a table is uniquely identified by one or more columns. No duplicate or null values are allowed.
2. **Foreign Key:** Establishes a link between columns in different tables. It ensures that values in a column (or a set of columns) match values in the primary key of another table, maintaining referential integrity.
3. **Unique:** Guarantees that all values in a column (or a set of columns) are unique across the table, preventing duplicate entries.
4. **Not Null:** Ensures that a column cannot have null values, requiring that each row must contain a value for that column.
5. **Check:** Defines a condition that must be met for the data to be inserted or updated in a column. For example, a check constraint might ensure that a numeric column only contains positive values.
Constraints are essential for maintaining data quality and enforcing business rules within a database.