SQL constraints

SQL constraints

  • when making a table on SQL, you can make constraints on each columns.
  1. unique: you cannot save the same data on a table. It is the only data such as SSN, not duplicated.
  2. primary: this key has the attributes of Not Null and Unique.
  3. foreign: when connecting a table with another table, you can constrain another table from adding other data. if you break the foreign key of constraints, it also breaks the integrity.
  • Extra constraints
  1. not null: you cannot save the table without data.
  2. default: the values that you always have, it is the primary value (the primary key and primary value is different here!)
  • when having constraints, you can apply tables to use and analyze data better.