Here is an example of sqlite database foreign key definition on create table statement
FOREIGN KEY (UserId) REFERENCES User(_id)
CREATE TABLE User( _id INTEGER PRIMARY KEY AUTOINCREMENT, UserName VARCHAR(50), PassWord VARCHAR(50), CreateDate DATETIME DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE Transaction( _id INTEGER PRIMARY KEY AUTOINCREMENT, Name VARCHAR(50), UserId INTEGER, Type INTEGER, CreateDate DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (UserId) REFERENCES User(_id) );
Be First to Comment