標籤:style blog color java ar strong 資料 div sp
建立表
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語句