What does keyword CONSTRAINT do in this CREATE TABLE statement

后端 未结 2 1476
攒了一身酷
攒了一身酷 2021-02-06 02:41

I\'m learning how to use sqlite3 with python. The example in the text book I am following is a database where each Country record has a Region, Country, and Population.

相关标签:
2条回答
  • 2021-02-06 03:09

    Country_key is simply giving a name to the constraint. If you do not do this the name will be generated for you. This is useful when there are several constraints on the table and you need to drop one of them.

    As an example for dropping the constraint:

    ALTER TABLE PopByCountry DROP CONSTRAINT Country_Key
    
    0 讨论(0)
  • 2021-02-06 03:11

    If you omit CONSTRAINT Contry_Key from the statement, SQL server will generate a name for your PRIMARY KEY constraint for you (the PRIMARY KEY is a type of constraint).

    By specifically putting CONSTRAINT in the query you are essentially specifying a name for your primary key constraint.

    0 讨论(0)
提交回复
热议问题