I am learning how to use sqlite3 with python. An example in the training course below is a database in which each country has a region, a country, and a population.
The book says:
The following snippet uses the CONSTRAINT keyword to indicate that no two entries in the table are ever created that will have the same value for the region and country:
>>> cur.execute(''' CREATE TABLE PopByCountry( Region TEXT NOT NULL, Country TEXT NOT NULL, Population INTEGER NOT NULL, CONSTRAINT Country_Key PRIMARY KEY (Region, Country)) ''')
Please could you explain what CONSTRAINT Country_Key does here. If I delete it, the PRIMARY KEY expression in itself seems to guarantee that each country has a unique name for this region.
python sql
sql beginner
source share