我表数据:
PID NAME
1
2
3
4
5 之后删除了5后,再插入数据,就会从6开始,,,怎么令到它从5重新开始过?
PID NAME
1
2
3
4
5 之后删除了5后,再插入数据,就会从6开始,,,怎么令到它从5重新开始过?
解决方案 »
- 请教按部门统计栏目文章数的SQL问题?
- ★50元求购软件可以监测SQLServer2000中数据库表变化的情况
- 达人帮忙写个select,送分
- 想起最开始学计算机时候的一个技巧,替换case when 在两个字段中选会最小的办法。
- 《***ADO数据绑定出错问题!一直没有解决,大家看问题在哪呀?***》
- 计算最大连号
- 判断某表中几个不相关字段是否不为空(有一个以上不为空即可)的sql如何写?在线等~~
- 出現以下提示是什麼原因:"name conflicts with existing modue,project,or object library'
- sql高手请进
- 各位同仁在分发ORACLE程序时怎么处理ORACLE的客户端?
- sql2000批量更新
- 新手问个小问题.
2000用子查询
2005及以上用row_number
--生成测试数据
CREATE TABLE products (id int IDENTITY PRIMARY KEY, product varchar(40))
GOINSERT INTO products (product) VALUES ('screwdriver')
INSERT INTO products (product) VALUES ('hammer')
INSERT INTO products (product) VALUES ('saw')
INSERT INTO products (product) VALUES ('like')
INSERT INTO products (product) VALUES ('saw')
INSERT INTO products (product) VALUES ('where')
INSERT INTO products (product) VALUES ('shovel')
GODELETE products
WHERE product = 'saw'
GOSET IDENTITY_INSERT products ON
GOINSERT INTO products (id, product) VALUES(3, 'garden shovel')
GOSELECT *
FROM products
GODROP TABLE products
id product
----------- ----------------------------------------
1 screwdriver
2 hammer
3 garden shovel
4 like
6 where
7 shovel(6 行受影响)这样的方式只能在插入的时候指明你的主键值了,比如上边插入3的时候,id为5的依然没有,必须得insert
1: 取消 字段PID 的自动标识
2: 手动添加删掉的5条数据(PID手动添加)
3. 设置 字段PID 自动增长
ok 了