Introduction
In this lesson, you will learn about how to specify referential and user-level constraints in SQLite.
Creating Tables
create table lessons (
lname text not null,
llength integer not null
);
Let’s add a few rows of data to the table so we can see how SQLite assigns a row id.
insert into lessons values
('Intro C++', 90),
('Intro Java', 90),
('SQL Joins', 60)
Conclusion
Errata
None collected yet. Let us know.
LS0tDQp0aXRsZTogIkludGVncml0eSBDb25zdHJhaW50cyBpbiBTUUxpdGUiDQpwYXJhbXM6DQogIGNhdGVnb3J5OiA3MA0KICBudW1iZXI6IDgwOA0KICB0aW1lOiAzMA0KICBsZXZlbDogYmVnaW5uZXINCiAgdGFnczogInNxbGl0ZSxjcmVhdGUgdGFibGUsYXV0byBpbmNyZW1lbnQiDQogIGRlc2NyaXB0aW9uOiAiRXhwbGFpbnMgaG93IFNRTGl0ZSBlbmZvcmNlcyBmb3JlaWduIGtleSBhbmQgdXNlciBkZWZpbmVkDQogICAgICAgICAgICAgICAgY29uc3RyYWludHMuIg0KZGF0ZTogIjxzbWFsbD5gciBTeXMuRGF0ZSgpYDwvc21hbGw+Ig0KYXV0aG9yOiAiPHNtYWxsPk1hcnRpbiBTY2hlZGxiYXVlcjwvc21hbGw+Ig0KZW1haWw6ICJtLnNjaGVkbGJhdWVyQG5ldS5lZHUiDQphZmZpbGl0YXRpb246ICJOb3J0aGVhc3Rlcm4gVW5pdmVyc2l0eSINCm91dHB1dDogDQogIGJvb2tkb3duOjpodG1sX2RvY3VtZW50MjoNCiAgICB0b2M6IHRydWUNCiAgICB0b2NfZmxvYXQ6IHRydWUNCiAgICBjb2xsYXBzZWQ6IGZhbHNlDQogICAgbnVtYmVyX3NlY3Rpb25zOiBmYWxzZQ0KICAgIGNvZGVfZG93bmxvYWQ6IHRydWUNCiAgICB0aGVtZTogc3BhY2VsYWINCiAgICBoaWdobGlnaHQ6IHRhbmdvDQotLS0NCg0KLS0tDQp0aXRsZTogIjxzbWFsbD5gciBwYXJhbXMkY2F0ZWdvcnlgLmByIHBhcmFtcyRudW1iZXJgPC9zbW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