Query/tests/db_files/mysql.sql

88 lines
2.1 KiB
MySQL
Raw Permalink Normal View History

2014-04-08 17:13:41 -04:00
-- sample data to test MySQL
2014-04-08 15:38:18 -04:00
-- TABLE TEST
2014-04-08 17:13:41 -04:00
DROP TABLE IF EXISTS TEST1;
CREATE TABLE TEST1 (
2014-04-08 15:38:18 -04:00
TEST_NAME CHAR(30) NOT NULL,
TEST_ID INTEGER DEFAULT '0' NOT NULL,
TEST_DATE TIMESTAMP NOT NULL
);
ALTER TABLE TEST1 ADD CONSTRAINT PK_TEST PRIMARY KEY (TEST_ID);
-- TABLE TEST2 with some CONSTRAINTs and an INDEX
2014-04-08 17:13:41 -04:00
DROP TABLE IF EXISTS TEST2;
CREATE TABLE TEST2 (
2014-04-08 15:38:18 -04:00
ID INTEGER NOT NULL,
FIELD1 INTEGER,
FIELD2 CHAR(15),
FIELD3 VARCHAR(50),
FIELD4 INTEGER,
FIELD5 INTEGER,
ID2 INTEGER NOT NULL
);
ALTER TABLE TEST2 ADD CONSTRAINT PK_TEST2 PRIMARY KEY (ID2);
ALTER TABLE TEST2 ADD CONSTRAINT TEST2_FIELD1ID_IDX UNIQUE (ID, FIELD1);
ALTER TABLE TEST2 ADD CONSTRAINT TEST2_FIELD4_IDX UNIQUE (FIELD4);
CREATE INDEX TEST2_FIELD5_IDX ON TEST2(FIELD5);
-- TABLE NUMBERS
DROP TABLE IF EXISTS NUMBERS;
CREATE TABLE NUMBERS (
2014-04-08 15:38:18 -04:00
NUMBER INTEGER DEFAULT '0' NOT NULL,
EN CHAR(100) NOT NULL,
FR CHAR(100) NOT NULL
);
-- TABLE NEWTABLE
2014-04-08 17:13:41 -04:00
DROP TABLE IF EXISTS NEWTABLE;
CREATE TABLE NEWTABLE (
2014-04-08 15:38:18 -04:00
ID INT DEFAULT 0 NOT NULL,
SOMENAME VARCHAR (12),
SOMEDATE TIMESTAMP NOT NULL
);
ALTER TABLE NEWTABLE ADD CONSTRAINT PKINDEX_IDX PRIMARY KEY (ID);
2014-04-08 17:13:41 -04:00
-- DROP SEQUENCE IF EXISTS NEWTABLE_SEQ CASCADE;
-- CREATE SEQUENCE NEWTABLE_SEQ INCREMENT 1 START 1;
2014-04-08 15:38:18 -04:00
-- VIEW on TEST
2014-04-08 17:13:41 -04:00
CREATE OR REPLACE VIEW `testview`(
2014-04-08 15:38:18 -04:00
TEST_NAME,
TEST_ID,
TEST_DATE
) AS
SELECT *
FROM TEST1
WHERE TEST_NAME LIKE 't%';
-- VIEW on NUMBERS
2014-04-08 17:13:41 -04:00
CREATE OR REPLACE VIEW `numbersview`(
2014-04-08 15:38:18 -04:00
NUMBER,
TRANS_EN,
TRANS_FR
) AS
SELECT *
FROM NUMBERS
WHERE NUMBER > 100;
-- TABLEs for testing CONSTRAINTs
2022-09-29 11:31:25 -04:00
CREATE TABLE IF NOT EXISTS testconstraints (
2014-04-08 15:38:18 -04:00
someid integer NOT NULL,
2014-04-08 17:13:41 -04:00
somename varchar(10) NOT NULL,
2014-04-08 15:38:18 -04:00
CONSTRAINT testconstraints_id_pk PRIMARY KEY (someid)
);
2022-09-29 11:31:25 -04:00
CREATE TABLE IF NOT EXISTS testconstraints2 (
2014-04-08 15:38:18 -04:00
ext_id integer NOT NULL,
modified date,
2014-04-08 17:13:41 -04:00
uniquefield varchar(10) NOT NULL,
2014-04-08 15:38:18 -04:00
usraction integer NOT NULL,
CONSTRAINT testconstraints_id_fk FOREIGN KEY (ext_id)
REFERENCES testconstraints (someid)
ON UPDATE CASCADE
ON DELETE CASCADE,
2014-04-08 15:38:18 -04:00
CONSTRAINT unique_2_fields_idx UNIQUE (modified, usraction),
CONSTRAINT uniquefld_idx UNIQUE (uniquefield)
);
2014-04-08 15:18:51 -04:00