插入单行的记录:基本的SQL语句为-insert into <表明>(<列明列表>) values (<值列表>);插入多行记录时中间用逗号隔开。
还有一种插入方式就是插入其他表的数据时,我们可以使用:insert into <表明>(<列明列表>) select <select语句>;如:insert into student1 (studentID,studentName) select studentId+2,studentName from student2;意思为向student1表中插入student2表中的数据并且student表中的Id都+2开始。因为student1表中已经存在2条记录了。
表数据的复制,之前有总结过此类的使用方法:select <列明> into <新表名> from <表名>;如:select * into student2 from
student1;意思为:将student1的数据复制到新建的表student2表中。
4.2更改表中已有的数据:
更改单列数据:update <表名> set <新列值列表> where <过滤条件>;
更改多行列数据:在上面的规则上用逗号隔开。
通过更新删除列中的数据:也就是设置某个字段为空即可。如:update set name = null where id=1;
4.3删除数据:
使用delete删除数据:delete from <表名> where <过滤条件>;如果不使用过滤条件将是整个行被删除掉。注意delete不能删除某个字段,只能整行删除,要删除某个字段只能update为null,如果有外键约束的话那么先要删除外键。