📜  Apache Derby-语法

📅  最后修改于: 2020-11-28 12:45:21             🧑  作者: Mango


本章为您提供了所有Apache Derby SQL语句的语法。

所有语句均以任何关键字开头,例如SELECT,INSERT,UPDATE,DELETE,ALTER,DROP,CREATE,USE,SHOW,而所有语句均以分号(;)结尾。

Apache Derby的SQL语句区分大小写,包括表名。

创建声明

CREATE TABLE table_name (
   column_name1 column_data_type1 constraint (optional),
   column_name2 column_data_type2 constraint (optional),
   column_name3 column_data_type3 constraint (optional)
);

滴台

DROP TABLE table_name;

INSERT语句

INSERT INTO table_name VALUES (column_name1, column_name2, ...);

SELECT陈述式

SELECT column_name, column_name, ... FROM table_name;

UPDATE语句

UPDATE table_name
   SET column_name = value, column_name = value, ...
   WHERE conditions;

删除声明

DELETE FROM table_name WHERE condition;

DESCRIBE声明

Describe table_name

SQL TRUNCATE TABLE语句

TRUNCATE TABLE table_name;

ALTER语句–添加列

ALTER TABLE table_name ADD COLUMN column_name column_type;

ALTER语句–添加约束

ALTER TABLE table_name ADD CONSTRAINT constraint_name constraint (column_name);

ALTER语句–删除列

ALTER TABLE table_name DROP COLUMN column_name;

ALTER语句–删除约束

ALTER TABLE table_name DROP CONSTRAINT constraint_name;

条款

SELECT * from table_name WHERE condition;
or,
DELETE from table_name WHERE condition;
or,
UPDATE table_name SET column_name = value WHERE condition;

按条款分组

SELECT column1, column2, . . . table_name GROUP BY column1, column2, . . .;

按条款订购

SELECT * FROM table_name ORDER BY column_name ASC|DESC.

有条款

SELECT column1, column2 . . . from table_name GROUP BY column having
condition;

创建索引

CTREATE INDEX index_name on table_name (column_name);

创建一个唯一索引

CREATE UNIQUE INDEX index_name on table_name (column_name);

创建一个复合索引

CREATE INDEX index_name on table_name (column_name1, column_name2);

显示索引

SHOW INDEXES FROM table_name;

下降索引

DROP INDEX index_name;