Query/tests/db_files/sqlite.sql

82 lines
2.1 KiB
MySQL
Raw Permalink Normal View History

2014-04-08 15:18:51 -04:00
-- sample data to test SQLite
CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "key" TEXT, "val" TEXT);
2014-04-08 15:38:18 -04:00
CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
CREATE TABLE IF NOT EXISTS "create_delete" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
2014-04-08 15:18:51 -04:00
-- TABLE TEST
DROP TABLE IF EXISTS TEST1;
CREATE TABLE TEST1 (
TEST_NAME TEXT NOT NULL,
TEST_ID INTEGER DEFAULT '0' NOT NULL,
TEST_DATE TEXT NOT NULL,
CONSTRAINT PK_TEST PRIMARY KEY (TEST_ID)
);
-- TABLE TEST2 with some CONSTRAINTs and an INDEX
DROP TABLE IF EXISTS TEST2;
CREATE TABLE TEST2 (
ID INTEGER NOT NULL,
FIELD1 INTEGER,
FIELD2 TEXT,
FIELD3 TEXT,
FIELD4 INTEGER,
FIELD5 INTEGER,
ID2 INTEGER NOT NULL,
CONSTRAINT PK_TEST2 PRIMARY KEY (ID2),
CONSTRAINT TEST2_FIELD1ID_IDX UNIQUE (ID, FIELD1),
CONSTRAINT TEST2_FIELD4_IDX UNIQUE (FIELD4)
);
CREATE INDEX TEST2_FIELD5_IDX ON TEST2 (FIELD5);
-- TABLE NUMBERS
DROP TABLE IF EXISTS NUMBERS;
CREATE TABLE NUMBERS (
NUMBER INTEGER DEFAULT 0 NOT NULL,
EN TEXT NOT NULL,
FR TEXT NOT NULL
);
-- TABLE NEWTABLE
DROP TABLE IF EXISTS NEWTABLE;
CREATE TABLE NEWTABLE (
ID INTEGER DEFAULT 0 NOT NULL,
SOMENAME TEXT,
SOMEDATE TEXT NOT NULL,
CONSTRAINT PKINDEX_IDX PRIMARY KEY (ID)
);
-- VIEW on TEST
DROP VIEW IF EXISTS "testview";
CREATE VIEW "testview" AS
SELECT *
FROM TEST1
WHERE TEST_NAME LIKE 't%';
-- VIEW on NUMBERS
DROP VIEW IF EXISTS "numbersview";
CREATE VIEW "numbersview" AS
SELECT *
FROM NUMBERS
WHERE NUMBER > 100;
-- TABLEs for testing CONSTRAINTs
DROP TABLE IF EXISTS "testconstraints";
CREATE TABLE "testconstraints" (
someid integer NOT NULL,
somename TEXT NOT NULL,
CONSTRAINT testconstraints_id_pk PRIMARY KEY (someid)
);
DROP TABLE IF EXISTS "testconstraints2";
CREATE TABLE "testconstraints2" (
ext_id integer NOT NULL,
modified text,
uniquefield text NOT NULL,
usraction integer NOT NULL,
CONSTRAINT testconstraints_id_fk FOREIGN KEY (ext_id)
REFERENCES testconstraints (someid)
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT unique_2_fields_idx UNIQUE (modified, usraction),
CONSTRAINT uniquefld_idx UNIQUE (uniquefield)
);