SQLite foreign Key

Source: Internet
Author: User
Tags sqlite manager

Database Tools: SQLite Manager (V0.7.7)

SQLite version: v3.6.19+


SQLite Manager does not open the foreign key by default.

So how do you use it to create a table with a foreign key?


First, open the foreign key support 1. Open "On-connect SQL tab"

"Tools", "Open on-connect SQL Tab"




2. In the "On-connect SQL tab" Input command

PRAGMA Foreign_keys=on;



3. Check if foreign key support is turned on

Click on the "DB Settings" tab to view



The "on" in the figure indicates that the foreign key function has been turned on


II. Building Tables by format

CREATE TABLE child_table_name (field_1 integer PRIMARY KEY, field_2 TEXT, Foreign_key_field Integer, Foreign KEY (foreign_ Key_field) REFERENCES Parent_table_name (Parent_key_field));


Note that: In the construction of the table, be sure to add the foreign key in the field, otherwise it will be an error.



Artist.sql

CREATE TABLE artist (  ArtistID    INTEGER PRIMARY KEY,   artistname  TEXT);

Track.sql

CREATE TABLE Track (  trackid     Integer,   trackname   TEXT,   trackartist Integer,  FOREIGN KEY ( trackartist) REFERENCES artist (ArtistID));




Reference article: 1. SQLite Foreign Key support 2. Foreign Keys in SQLite Manager 3. On Connect SQL Tab for SQLite Manager 4. Execute SQL Tab


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.