Explore foreign key constraints
Foreign key constraints help you to keep order in your database mini-world. In your database, for instance, only professors belonging to Swiss universities should be allowed, as only Swiss universities are part of the universities table.
The foreign key on professors referencing universities you just created thus makes sure that only existing universities can be specified when inserting new data. Let's test this!
Bu egzersiz
Introduction to Relational Databases in SQL
kursunun bir parçasıdırEgzersiz talimatları
- Run the sample code and have a look at the error message.
- What's wrong? Correct the
university_idso that it actually reflects where Albert Einstein wrote his dissertation and became a professor – at the University of Zurich (UZH)!
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
-- Try to insert a new professor
INSERT INTO professors (firstname, lastname, university_id)
VALUES ('Albert', 'Einstein', 'MIT');