When creating a database table in jupyter, we specify restrictions on data types in the columns of the table, but for some reason we can still add other data types. For example, the st_gr column should contain only numbers, but nothing will stop us from adding a line (code below) Why? How to fix?
%%sql sqlite://
CREATE TABLE students(
st_id INTEGER PRIMARY KEY AUTOINCREMENT,
fname VARCHAR(15) NOT NULL,
lname VARCHAR(15) NOT NULL,
st_gr NUMERIC
)
%%sql sqlite://
INSERT INTO students (fname, lname, st_gr) VALUES('Barack', 'Obama', 'text not num')
CodePudding user response:
If you are using sqlite version > 3.37.0, look into using STRICT tables.
If not, perhaps check constraints? software verification? a different database?
CodePudding user response:
SQLite uses dynamic type system. Declared column type only indicates the preferred value type, unless the table is strict.