SQLITE and foreign key

I am looking at some database tables which are defined like this:

This is the first table-

CREATE TABLE Point 
(

    Position integer unique not null,  
    Name text not null,                
);

And second table is like this:

CREATE TABLE namesPerPoint 
(

    PointKey integer not null,            -- unique ROWID in points table
    name text unique not null
);

Now, my question is how will sqlite db know that PointKey references rowid in Positions table. Its just mentioned here in comment, for user convenience. If I myself have to do it, I will do using FOREIGN KEY constraint. So, is this syntax correct? But this is a part of big successfully running system and all tables are defined like this only. So, I am assuming I am missing something.

Thanks

Answers


No, unless you create a foreign key constraint. but first, you need to turn on the foreign key support

sqlite> PRAGMA foreign_keys = ON;

add a primary key to the main table

CREATE TABLE Point 
(

    Position integer PRIMARY KEY,  
    Name text not null,                
);

then to add foreign key

CREATE TABLE namesPerPoint 
(
    PointKey integer not null,            -- unique ROWID in points table
    name text unique not null,
    FOREIGN KEY (PointKey) REFERENCES Point(Position)
);

PRIMARY KEY

Source: SQLite Foreign Key Support


Need Your Help

How to send a .gif file over a serial port connection using C in Linux

c linux serial-port

I would like to send a .gif file over a serial port connection using C in Linux.

Program Segmentation Faults on return 0/fclose/free. I think I have memory leaks but can't find them. Please help!

c file-io memory-leaks segmentation-fault huffman-coding

I am trying to write a Huffman encoding program to compress a text file. Upon completetion, the program will terminate at the return statement, or when I attempt to close a file I was reading from. I

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.