![]() Therefore, every SQLite database connection has the main database and also temp database in case you deal with temporary database objects. In addition, you can access the temporary database that holds temporary tables and other database objects via the temp database. When you connect to a database, its name is main regardless of the database file name. Introduction to the SQLite ATTACH DATABASE statement In this tutorial, you have learned how to create a new table with various options using SQLite CREATE TABLE statement.Summary: in this tutorial, you will learn how to attach additional databases to the current database connection using the SQLite ATTACH DATABASE statement. Note that we will discuss in the FOREIGN KEY constraint in detail in the subsequent tutorial. ON DELETE CASCADE ON UPDATE NO ACTION Code language: SQL (Structured Query Language) ( sql ) ON DELETE CASCADE ON UPDATE NO ACTION Code language: SQL (Structured Query Language) ( sql ) FOREIGN KEY (group_id) Therefore, you use FOREIGN KEY constraint to define a foreign key for each column. ![]() In addition, the contact_id and group_id are the foreign keys. To add the table primary key constraint, you use this syntax: PRIMARY KEY (contact_id, group_id) Code language: SQL (Structured Query Language) ( sql ) The contact_groups table has a primary key that consists of two columns: contact_id and group_id. The following statement creates contact_groups table: CREATE TABLE contact_groups( The group_id column is the primary key column. The groups table is quite simple with two columns: group_id and name. The following statement creates the groups table: CREATE TABLE groups ( The email and phone are unique therefore we use the UNIQUE constraint for each column. It means that you must provide values when you insert or update rows in the contacts table. The first_name and last_name columns have TEXT storage class and these columns are NOT NULL. The contact_id is the primary key of the contacts table.īecause the primary key consists of one column, you can use the column constraint. ) Code language: SQL (Structured Query Language) ( sql ) The following statement creates the contacts table. The following database diagram illustrates tables: contacts groups, and contact_groups.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |