lava-oushudb-dt-sql-parser/test/parser/mysql/syntax/fixtures/createTable.sql
琉易 428d851913
feat: #190 improve mysql grammer (#196)
* refactor: generic rename to mysql

* refactor: g4 with mysql syntax

* test: mysql syntax

* refactor: remove useless keywords

* refactor: remove nonReserved keywords

* refactor: lint specificFunction

---------

Co-authored-by: liuyi <liuyi@dtstack.com>
2023-11-27 15:25:40 +08:00

120 lines
7.0 KiB
SQL

-- https://dev.mysql.com/doc/refman/8.0/en/create-table.html
CREATE TEMPORARY TABLE new_tbl SELECT * FROM orig_tbl LIMIT 0;
CREATE TABLE new_tbl LIKE orig_tbl;
CREATE TABLE new_tbl SELECT * FROM orig_tbl LIMIT 0;
CREATE TABLE new_tbl [AS] SELECT * FROM orig_tbl;
CREATE TABLE test (a INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (a), KEY(b)) ENGINE=InnoDB SELECT b,c FROM test2;
CREATE TABLE bar (m INT) SELECT n FROM foo;
CREATE TABLE artists_and_works SELECT artist.name, COUNT(work.artist_id) AS number_of_works FROM artist LEFT JOIN work ON artist.id = work.artist_id GROUP BY artist.id;
CREATE TABLE new_tbl AS SELECT * FROM orig_tbl;
CREATE TABLE t (c CHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin);
CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));
CREATE TABLE t1 (c1 INT) ENGINE_ATTRIBUTE='{"key":"value"}';
CREATE TABLE my_table (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
CREATE TABLE t1 (c1 INT STORAGE DISK, c2 INT STORAGE MEMORY) TABLESPACE ts_1 ENGINE NDB;
CREATE TABLE t1 (c1 INT STORAGE MEMORY, c2 INT STORAGE MEMORY) TABLESPACE ts_1 ENGINE NDB;
CREATE TABLE lookup (id INT, INDEX USING BTREE (id)) ENGINE = MEMORY;
CREATE TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 VARCHAR(100), c3 VARCHAR(100)) ENGINE=NDB COMMENT="NDB_TABLE=READ_BACKUP=0,PARTITION_BALANCE=FOR_RP_BY_NODE";
CREATE TABLE t1 (col1 INT, col2 CHAR(5)) PARTITION BY HASH(col1);
CREATE TABLE t1 (col1 INT, col2 CHAR(5), col3 DATETIME) PARTITION BY HASH (YEAR(col3));
CREATE TABLE tk (col1 INT, col2 CHAR(5), col3 DATE) PARTITION BY KEY(col3) PARTITIONS 4;
CREATE TABLE tk (col1 INT, col2 CHAR(5), col3 DATE) PARTITION BY LINEAR KEY(col3) PARTITIONS 5;
CREATE TABLE t1 (year_col INT, some_data INT) PARTITION BY RANGE (year_col) (
PARTITION p0 VALUES LESS THAN (1991),
PARTITION p1 VALUES LESS THAN (1995),
PARTITION p2 VALUES LESS THAN (1999),
PARTITION p3 VALUES LESS THAN (2002),
PARTITION p4 VALUES LESS THAN (2006),
PARTITION p5 VALUES LESS THAN MAXVALUE
);
CREATE TABLE rc (a INT NOT NULL, b INT NOT NULL) PARTITION BY RANGE COLUMNS(a,b) (
PARTITION p0 VALUES LESS THAN (10,5),
PARTITION p1 VALUES LESS THAN (20,10),
PARTITION p2 VALUES LESS THAN (50,MAXVALUE),
PARTITION p3 VALUES LESS THAN (65,MAXVALUE),
PARTITION p4 VALUES LESS THAN (MAXVALUE,MAXVALUE)
);
CREATE TABLE client_firms (id INT, name VARCHAR(35)) PARTITION BY LIST (id) (
PARTITION r0 VALUES IN (1, 5, 9, 13, 17, 21),
PARTITION r1 VALUES IN (2, 6, 10, 14, 18, 22),
PARTITION r2 VALUES IN (3, 7, 11, 15, 19, 23),
PARTITION r3 VALUES IN (4, 8, 12, 16, 20, 24)
);
CREATE TABLE lc (a INT NULL, b INT NULL) PARTITION BY LIST COLUMNS(a,b) (
PARTITION p0 VALUES IN( (0,0), (NULL,NULL) ),
PARTITION p1 VALUES IN( (0,1), (0,2), (0,3), (1,1), (1,2) ),
PARTITION p2 VALUES IN( (1,0), (2,0), (2,1), (3,0), (3,1) ),
PARTITION p3 VALUES IN( (1,3), (2,2), (2,3), (3,2), (3,3) )
);
CREATE TABLE th (id INT, name VARCHAR(30), adate DATE) PARTITION BY LIST(YEAR(adate)) (
PARTITION p1999 VALUES IN (1995, 1999, 2003)
DATA DIRECTORY = '/var/appdata/95/data'
INDEX DIRECTORY = '/var/appdata/95/idx',
PARTITION p2000 VALUES IN (1996, 2000, 2004)
DATA DIRECTORY = '/var/appdata/96/data'
INDEX DIRECTORY = '/var/appdata/96/idx',
PARTITION p2001 VALUES IN (1997, 2001, 2005)
DATA DIRECTORY = '/var/appdata/97/data'
INDEX DIRECTORY = '/var/appdata/97/idx',
PARTITION p2002 VALUES IN (1998, 2002, 2006)
DATA DIRECTORY = '/var/appdata/98/data'
INDEX DIRECTORY = '/var/appdata/98/idx'
);
CREATE TABLE t1 (s1 INT, s2 INT AS (EXP(s1)) STORED) PARTITION BY LIST (s2) (PARTITION p1 VALUES IN (1));
CREATE TABLE foo (a TINYINT NOT NULL) SELECT b+1 AS a FROM bar;
CREATE TABLE parent (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
CREATE TABLE child (id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE) ENGINE=INNODB;
CREATE TABLE product (category INT NOT NULL, id INT NOT NULL, price DECIMAL, PRIMARY KEY(category, id)) ENGINE=INNODB;
CREATE TABLE customer (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
CREATE TABLE product_order (no INT NOT NULL AUTO_INCREMENT, product_category INT NOT NULL, product_id INT NOT NULL, customer_id INT NOT NULL, PRIMARY KEY(no), INDEX (product_category, product_id), INDEX (customer_id), FOREIGN KEY (product_category, product_id) REFERENCES product(category, id) ON UPDATE CASCADE ON DELETE RESTRICT, FOREIGN KEY (customer_id) REFERENCES customer(id)) ENGINE=INNODB;
CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), c3 INT CHECK (c3 < 100), CONSTRAINT c1_nonzero CHECK (c1 <> 0), CHECK (c1 > c3));
CREATE TABLE t2 (c1 VARCHAR(10) CHARACTER SET binary, c2 TEXT CHARACTER SET binary, c3 ENUM('a','b','c') CHARACTER SET binary);
CREATE TABLE t3 (c1 VARBINARY(10), c2 BLOB, c3 ENUM('a','b','c') CHARACTER SET binary);
CREATE TABLE triangle (sidea DOUBLE, sideb DOUBLE, sidec DOUBLE AS (SQRT(sidea * sidea + sideb * sideb)));
CREATE VIEW v1 AS SELECT *, CONCAT(first_name,' ',last_name) AS full_name FROM t1;
CREATE TABLE t1 (first_name VARCHAR(10), last_name VARCHAR(10), full_name VARCHAR(255) AS (CONCAT(first_name,' ',last_name)));
CREATE TABLE t1 (c JSON, g INT GENERATED ALWAYS AS (c->"$.id"), INDEX i (g));
CREATE TABLE t2 (a BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, c JSON DEFAULT NULL, g INT GENERATED ALWAYS AS (c->"$.id") STORED, INDEX i (g)) ENGINE=NDB;
CREATE TABLE t1 (i INT, j DATE INVISIBLE) ENGINE = InnoDB;
CREATE TABLE t1 (col1 INT, col2 INT INVISIBLE);
CREATE TABLE t2 AS SELECT col1, col2 FROM t1;
CREATE TABLE t2 (col2 INT INVISIBLE) AS SELECT col1, col2 FROM t1;
CREATE TABLE auto_0 (c1 VARCHAR(50), c2 INT);
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b1 BLOB, b2 BLOB COMMENT 'NDB_COLUMN=BLOB_INLINE_SIZE=8000') ENGINE NDB;
CREATE TABLE test.t2 (p INT PRIMARY KEY, c1 BLOB, c2 BLOB COMMENT 'NDB_COLUMN=MAX_BLOB_PART_SIZE') ENGINE NDB;
CREATE TABLE test.t3 (p INT NOT NULL PRIMARY KEY, c1 JSON, c2 JSON COMMENT 'NDB_COLUMN=BLOB_INLINE_SIZE=5000,MAX_BLOB_PART_SIZE') ENGINE NDB;
CREATE TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 VARCHAR(100), c3 VARCHAR(100)) ENGINE=NDB
CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE ts1 ROW_FORMAT=REDUNDANT;
CREATE TABLE t2 (c1 INT PRIMARY KEY) TABLESPACE ts1 ROW_FORMAT=COMPACT;
CREATE TABLE t3 (c1 INT PRIMARY KEY) TABLESPACE ts1 ROW_FORMAT=DYNAMIC;
CREATE TABLE t4 (c1 INT PRIMARY KEY) TABLESPACE ts2 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
CREATE TABLE IF NOT EXISTS tbl_name (CONSTRAINT c2_positive CHECK (c2 > 0) NOT ENFORCED);
CREATE TABLE IF NOT EXISTS tbl_name (CONSTRAINT c2_positive CHECK (c2 > 0) ENFORCED);
CREATE TABLE IF NOT EXISTS tbl_name (CONSTRAINT c2_positive CHECK (c2 > 0));
CREATE TABLE IF NOT EXISTS tbl_name (CONSTRAINT CHECK (c2 > 0) NOT ENFORCED);
CREATE TABLE IF NOT EXISTS tbl_name (CONSTRAINT CHECK (c2 > 0) ENFORCED);
CREATE TABLE IF NOT EXISTS tbl_name (CONSTRAINT CHECK (c2 > 0));
CREATE TABLE IF NOT EXISTS tbl_name (CHECK (c2 > 0) ENFORCED);
CREATE TABLE IF NOT EXISTS tbl_name (CHECK (c2 > 0));