Skip to main content

保留字

V-SQL是对应3个数据库使用的,为了保证可以跨数据库使用,所以3个数据库的关键字、保留字都不可以写成查询的别名或者表的字段名。建表时,最好检查下保留字是否有冲突。如果遇到无法处理时,可通过使用别名处理。

1. 保留字案例

1.1 保留字作为字段名

select status as fstatus from table
# “status”是留字,不可以写成表的字段名。修改为:
select fstatus from table
select statusType from table

1.2 保留字作为表名

select  * from order order by id asc
# “order”是保留字,不可以作为表名。 可以修改为复数形式“orders”:
select * from orders order by id asc

注意:在支持SQL的编辑器中保留字是有颜色的,可以通过这点来快速区分保留字。

2. 保留字汇总表

数据库保留字
名称中不能出现这些字符空格,'!','"‘,''','#','$','%','&','(‘,')','*','+',
',','-','.','/',':',';','<‘,'=‘,'>‘,'?','@'
ORACLE的保留字ALL, ALTER, AND, ANY, AS, ASC, BETWEEN, BY,CHAR, CHECK, CLUSTER, COMPRESS, CONNECT, CREATE, DATE, DECIMAL, DEFAULT, DELETE,DESC, DISTINCT, DROP, ELSE, EXCLUSIVE, EXISTS, FLOAT, FOR, FROM, GRANT, GROUP,HAVING, IDENTIFIED, IN, INDEX, INSERT, INTEGER, INTERSECT, INTO, IS, LIKE, LOCK,LONG, MINUS, MODE, NOCOMPRESS, NOT, NOWAIT, NULL, NUMBER, OF, ON, OPTION, OR,ORDER, PCTFREE, PRIOR, PUBLIC, RAW, RENAME, RESOURCE, REVOKE, SELECT, SET, SHARE,SIZE, SMALLINT, START, SYNONYM, TABLE, THEN, TO, TRIGGER, UNION, UNIQUE, UPDATE,VALUES, VARCHAR, VARCHAR2, VIEW, WHERE, WITH
MSSQL的保留字ACTION, ADD, AGGREGATE, ALL, ALTER, AFTER, AND, AS,ASC, AVG, AVG_ROW_LENGTH, AUTO_INCREMENT, BETWEEN, BIGINT, BIT, BINARY, BLOB, BOOL,BOTH, BY, CASCADE, CASE, CHAR, CHARACTER, CHANGE, CHECK, CHECKSUM, COLUMN, COLUMNS,COMMENT, CONSTRAINT, CREATE, CROSS, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, DATA,DATABASE, DATABASES, DATE, DATETIME, DAY, DAY_HOUR, DAY_MINUTE, DAY_SECOND, DAYOFMONTH,DAYOFWEEK, DAYOFYEAR, DEC, DECIMAL, DEFAULT, DELAYED, DELAY_KEY_WRITE, DELETE, DESC,DESCRIBE, DISTINCT, DISTINCTROW, DOUBLE, DROP, END, ELSE, ESCAPE, ESCAPED, ENCLOSED,ENUM, EXPLAIN, EXISTS, FIELDS, FILE, FIRST, FLOAT, FLOAT4, FLOAT8, FLUSH, FOREIGN,FROM, FOR, FULL, FUNCTION, GLOBAL, GRANT, GRANTS, GROUP, HAVING, HEAP, HIGH_PRIORITY,HOUR, HOUR_MINUTE, HOUR_SECOND, HOSTS, IDENTIFIED, IGNORE, IN, INDEX, INFILE, INNER,INSERT, INSERT_ID, INT, INTEGER, INTERVAL, INT1, INT2, INT3, INT4, INT8, INTO, IF,IS, ISAM, JOIN, KEY, KEYS, KILL, LAST_INSERT_ID, LEADING, LEFT, LENGTH, LIKE,LINES, LIMIT, LOAD, LOCAL, LOCK, LOGS, LONG, LONGBLOB, LONGTEXT, LOW_PRIORITY, MAX,MAX_ROWS, MATCH, MEDIUMBLOB, MEDIUMTEXT, MEDIUMINT, MIDDLEINT, MIN_ROWS, MINUTE,MINUTE_SECOND, MODIFY, MONTH, MONTHNAME, MYISAM, NATURAL, NUMERIC, NO, NOT, NULL, ON,OPTIMIZE, OPTION, OPTIONALLY, OR, ORDER, OUTER, OUTFILE, PACK_KEYS, PARTIAL, PASSWORD, PRECISION, PRIMARY, PROCEDURE, PROCESS, PROCESSLIST, PRIVILEGES, READ, REAL, REFERENCES,RELOAD, REGEXP, RENAME, REPLACE, RESTRICT, RETURNS, REVOKE, RLIKE, ROW, ROWS, SECOND,SELECT, SET, SHOW, SHUTDOWN, SMALLINT, SONAME, SQL_BIG_TABLES, SQL_BIG_SELECTS,SQL_LOW_PRIORITY_UPDATES, SQL_LOG_OFF, SQL_LOG_UPDATE, SQL_SELECT_LIMIT, SQL_SMALL_RESULT,SQL_BIG_RESULT, SQL_WARNINGS, STRAIGHT_JOIN, STARTING, STATUS, STRING, TABLE, TABLES,TEMPORARY, TERMINATED, TEXT, THEN, TIME, TIMESTAMP, TINYBLOB, TINYTEXT, TINYINT,TRAILING, TO, TYPE, USE, USING, UNIQUE, UNLOCK, UNSIGNED, UPDATE, USAGE, VALUES,VARCHAR, VARIABLES, VARYING, VARBINARY, WITH, WRITE, WHEN, WHERE, YEAR, YEAR_MONTH,ZEROFILL
VSQL中的保留字LOG, CONCAT, SUBSTRING, TRIM, CAST, RIGHT, CHARS,TODAY, CURTIME, NOW, DAYNAME, FORMATDATE, QUARTER, DATEADD, DATEDIFF, TRUNC, WEEK,UUID, MOD, CHARINDEX, CEILING, ISNULL, REPEAT, RAND, ISNUMERIC, ABS, SIN, COS, TAN,SQRT, EXP, MIN, COUNT, REVERSE, ASCII, PI, FLOOR, ROUND, DAYNAME, DATEADD,DATEDIFF, LTRIM, RTRIM, CASEWHEN, ROWNUM, TODATE, SUM, UPPER, LOWER, SIGN, POWER,LENGTH, LEFT, DAYOFMONTH, MONTHNAME, DAYOFWEEK, YEAR, DAYOFYEAR, HOUR, MINUTE, SECOND,MONTH, MAX, REPLACE, AVG
DB2中暂时没有