删除数据表中的数据 让主键id 从1开始自增
1 方式1
清空表数据并且将主键自增长从1开始(1.先清空表数据2.在把表的自增长设置为1)
DELETE FROM grade;
ALTER TABLE grade AUTO_INCREMENT=1;
方式2
使用truncate清空全部数据主键自增长是从1开始(效率更高)
truncate table "表名字"
删除表中部分数据
delete from table where id>100
插入数据
insert into tablename(id,name,...) values (id,name,...)
INSERT INTO tb_name (field1, field2, ..., fieldn) VAULES(value1, value2, ...,valuen);
可空字段、非空但是含有默认值的字段、自增字段可以不列在字段列表中。
INSERT INTO tb_name VAULES(value1, value2, ...,valuen);
更新数据
update tablename set id=?,name=?... where id=?
UPDATE tb_name SET field1=value1, field2=value2, ..., fieldn=valuen [WHERE condition];
删除一条数据
delete from tablename where id=?
DELETE FROM tb_name [WHERE condition];
查询记录
select * from tablename
SELECT column_name FROM tb_name WHERE condition;
内连接:
SELECT field1, field2, ...,fieldn FROM tb_name1, tb_name2, ..., tb_namen [WHERE condition];
外连接分为左连接和右连接
右连接
SELECT left_field, right_field FROM left_tb_name
LEFT JOIN right_tb_name ON condition;
左连接
SELECT left_field, right_field FROM right_tb_name
LEFT JOIN left_tb_name ON condition;
网友评论