Sobes.tech
Junior — Middle

How can a restriction be implemented in an existing database table?

sobes.tech AI

Answer from AI

To add a constraint to an existing database table, the ALTER TABLE command is usually used. Depending on the type of constraint, the syntax may vary. For example, to add a uniqueness constraint:

ALTER TABLE table_name
ADD CONSTRAINT constraint_name UNIQUE (column_name);

To add a foreign key:

ALTER TABLE table_name
ADD CONSTRAINT fk_constraint_name FOREIGN KEY (column_name) REFERENCES other_table(other_column);

It is important to note that some DBMSs may have restrictions on altering tables with data, and it may be necessary to verify existing data for compliance with the new constraint beforehand.

How can a restriction be implemented in an existing… - sobes.tech