經典SQL語句大全

1、創建數據庫: create database 數據庫名

經典SQL語句大全

如:create database student;

2、連接到一個已經存在的數據庫: use 數據庫名

如:use student;

3、刪除數據庫:drop database 數據庫名

如: drop database student;

4、創建表:create table 表名列名列的數據類型列的約束])

如:create table stuInfo(stuId int primary key,stuName var20) not null)

5、刪除表: 表名

如: stuInfo;

6、修改表:alter table

給表添加新列: alter table 表名 add 列名列的數據類型

添加多列,中間用逗號隔開

如:alter table stuInfo add stuGender var10)

修改某列的數據類型:alter table 表名 modify 列名新數據類型

如:alter table stuInfo modify stuGender int

修改列名:alter table 表名 change 老列名新列名數據類型

如:alter table stuInfo change stuName stuAddress var30)

刪除列:alter table 表名 drop 列名

如: alter table stuInfo drop stuGender

7、將創建的表的'語句反向導出: show create table 表名

8、查詢表的所有內容:select * from 表名

查詢表的部分內容: select 列名列表 from 表名

9、查詢表結構:show columns from 表名

10、插入單行數據: into 表名列名列表) values(值列表)

11、插入多行數據:作用相當於將數據從一個表複製到另一個表

into 表名 (列名列表) select

如將stuInfo表中的所有的學生姓名複製到students表中的stuName列中: into students(stuName) select stuName from stuInfo

12、刪除數據: from 表名 where過濾條件

如刪除stuID爲4的人的數據: from stuInfo where stuId=4