数据操作:(insert into

1、增加数据:

Insert into 表名 (字段名) values (数据列表);

Insert into 表名 (字段名) values (字段列表1),(字段列表2....

Insert into 表名 set 字段1=1.........

注释:数据出现空缺或未指定部分字段,则使用默认值NULL

不使用默认值 (字段列表 not null

自定义默认值 (字段列表 not null dfault ‘默认值’)

 

插入主键:

not null auto_increment primary key 未指定初始值的自动增量主键

Not null identity1,1) primary key  指定初始值的自动增量主键

Not null unique primary key 非增量主键

 

2、使用select从其他表调用数据:

Insert into 表名 select * from 其他表 where ...order by.....limit......

注释:取代部分对应类型一定要相同。


3、替换数据:

Replace into ......(和插入相同)

区别:

Insert   直接插入。

Replace 先判断表中的主键或唯一索引字段是否有和插入数据相应的值一样的数据,他就变成修改。(先删除旧数据再插入新数据)

 

4、查询数据:

Select * from 表名 ;(查询表中所有数据)


5、查询条件:

Select * from 表名 where 条件;


6、修改数据:

Update 表名 set 字段名=新值,....where 条件 order by ....... Limit ....

注释:不加条件则修改所有,慎重使用。


7、删除数据:

Delete from 表名 where ..... Order by ..... limit .....

注释:不加条件则删除所有,慎重使用。

 

列操作为DDL语言不是SQL语言。