Due to a 'longstanding coding oversight', primary keys can be NULL in SQLite. Primary keys become foreign keys in other tables, when creating relations among tables. Primary keys are important when designing the database tables. There can be more UNIQUE columns, but only one primary key in a table. The PRIMARY KEY constraint uniquely identifies each record in a database table. Here, AGE column is set to UNIQUE, so that you cannot have two records with the same age − Exampleįor example, the following SQLite statement creates a new table called COMPANY and adds five columns. In the COMPANY table, for example, you might want to prevent two or more people from having an identical age. The UNIQUE Constraint prevents two records from having identical values in a particular column. Here, SALARY column is set to 5000.00 by default, thus in case INSERT INTO statement does not provide a value for this column, then by default, this column would be set to 5000.00. The DEFAULT constraint provides a default value to a column when the INSERT INTO statement does not provide a specific value. Exampleįor example, the following SQLite statement creates a new table called COMPANY and adds five columns, three of which, ID and NAME and AGE, specifies not to accept NULLs. If you do not want a column to have a NULL value, then you need to define such constraint on this column specifying that NULL is now not allowed for that column.Ī NULL is not the same as no data, rather, it represents unknown data. PRIMARY Key − Uniquely identifies each row/record in a database table.ĬHECK Constraint − Ensures that all values in a column satisfies certain conditions.īy default, a column can hold NULL values. UNIQUE Constraint − Ensures that all values in a column are different. NOT NULL Constraint − Ensures that a column cannot have NULL value.ĭEFAULT Constraint − Provides a default value for a column when none is specified. Column level constraints are applied only to one column, whereas table level constraints are applied to the whole table.įollowing are commonly used constraints available in SQLite. This ensures the accuracy and reliability of the data in the database.Ĭonstraints could be column level or table level. These are used to limit the type of data that can go into a table. Constraints are the rules enforced on a data columns on table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |