首页 > 代码库 > 【java开发系列】—— 常用SQL语句

【java开发系列】—— 常用SQL语句

创建表

create table emp(id decimal,name char(10),age decimal)

 

删除表

DROP TABLE EMP

 

插入默认值

CREATE TABLE EMP(  Id decimal NOT NULL,  Name char(10) NOT NULL,  Age decimal NOT NULL DEFAULT 18)

 

添加列

ALTER TABLE EMP ADD COLUMN Comments char(50) NOT NULL DEFAULT COMMENTS

 

删除列

ALTER TABLE EMP DROP COLUMN Comments

 

修改列

ALTER TABLE EMP MODIFY COLUMN Comments char(30)

 

创建索引

CREATE INDEX Name_index ON EMP (Name)

 

查询数据

SELECT Name FROM EMP

 

查询不重复的数据

SELECT DISTINCT Name FROM EMP

 

对查询结果排序

SELECT Name FROM EMP ORDER BY Name

 

条件查询

SELECT Name FROM EMP WHERE Age < 20SELECT Name FROM EMP WHERE Age BETWEEN 20 AND 30

 

插入数据

INSERT INTO EMP VALUES(123,xingoo,18)

 

修改数据

UPDATE EMP SET Name=xingoo1111 WHERE Name=xingoo

 

删除数据

DELETE FROM EMP WHERE Age<20

 

求平均数

SELECT AVG(Age) FROM EMP

 

查询条数

SELECT COUNT(DISTINCT Name) FROM EMPSELECT COUNT(*) FROM EMP

 

【java开发系列】—— 常用SQL语句