CREATE TABLE [Category] (
[CategoryID] TEXT  PRIMARY KEY UNIQUE NOT NULL,
[CategoryName] TEXT  NOT NULL,
[ParentID] TEXT  NOT NULL,
[LabelID] INTEGER  NOT NULL
);



CREATE TABLE [Contact] (
[ContactID] TEXT PRIMARY KEY UNIQUE NOT NULL,
[CategoryID] TEXT  NOT NULL,
[LabelID] INTEGER  NOT NULL,
[bDelete] BOOLEAN DEFAULT '''0''' NOT NULL
);



CREATE TABLE [Fields] (
[FieldID] INTEGER  NOT NULL,
[ContactID] TEXT  NOT NULL,
[FieldType] INTEGER  NOT NULL,
[Value] TEXT  NULL,
PRIMARY KEY ([FieldID],[ContactID])
);



CREATE TABLE [Track] (
[TrackID] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[ContactID] TEXT  NOT NULL,
[Type] INTEGER  NOT NULL,
[Time] TIMESTAMP  NOT NULL
);



CREATE TABLE [DbInfo] (
[Version] TEXT  NOT NULL
);

INSERT INTO DbInfo (Version) VALUES ('1.00');


CREATE VIEW CardView AS 
Select Contact.LabelID, Contact.CategoryID, Contact.bDelete, Contact.ContactID, Fields.FieldType, Fields.FieldID, Fields.Value 
From Contact, Fields Where Contact.ContactID = Fields.ContactID;



