注意事項:
1.默認自增用0,null, default
2.多個字段英文逗號表示
3.vachar用雙引號
4.所有的符號用英文表示
一.創建表
創建表
creat table 表名(
id int unsigened priary key auto_increment,
name varchar(10),
)
添加字段:alter table 表名 add 列名 int
二.簡單查詢
查詢全部:select *from 表名
查詢列:select 字段名,from 表名
去重查詢:select DISTINCT 字段名 from 表名
起別名:
1.給字段起別名:select name as 姓名 from 表名
2.給表起別名:select name as 姓名 from 表名 as 學生表
三.基礎增刪改查
如果表存在就刪除,不存在就報錯:drop table 表名
如果表存在則刪除,如果不存在不會報錯:drop table if exists 表名
新增一條數據:insert into 表名 values (,'',..)
增加指定的字段:insert into 表名(name) values(''),('')
刪除指定數據:delete from 表名 where id=1
刪除表中全部數據:delete from 表名
修改全部數據:update 表名 set 字段名=值
修改指定數據:update 表名 set 列名='',列名=值 where id=值