sql中的有一个小问题 - .NET技术 / C#
我在数据库中设置了一个ID编号,我以为他可以自动编号,我在程序中执行时,让他插入一调记录,则ID自动加1,让他删一条语句,譬如开始有九条记录,我把第四条删掉,使他后面的,第5,6,7,8,9一次变为4,5,6,7,8,但不知在程序中如何修改,难道说一定要一个一个的用update吗
自动编号的字段你想修改还不行。
你为何要修改?
自动编号ID不能修改吧。
自动编号的话可以设施列的属性,但是不会自动下移
不能修改,主键本来就是区分唯一性的,只要能区分就行了啊!
自动增长列不能修改。
SQL code:
'设置非递增编号字段,然后为此表创建触发器来重新按顺序编号!'
use test
go
if object_id('test.dbo.tb') is not null drop table tb
-- 创建数据表
create table tb
(
id int
)
go
insert into tb select 2
union all select 4
union all select 6
union all select 8
union all select 10
go
select id=(select count(1)+1 from tb where id<t.id),* from tb t
/*
id id
---------------
1 2
2 4
3 6
4 8
5 10
*/
select * from tb
/*
id
--------
2
4
6
8
10
*/
if object_id('test.dbo.t') is not null drop table t
select idd=identity(int,1,1),id into t from tb
update tb set id=t.idd
from t,tb where t.id=tb.id
select * from tb
/*
id
----
1
2
3
4
5
*/
自定义函数 把你的主键字段默认值 搞成函数 就可以了
主键id只要能标识唯一性就行了,你要那么好看干嘛,可以用存储过程和触发器来替代自增主键
{
相关问答:
DataSet导出xml 批处理(循环)得怎么处理
XML文件
<A>
<B>
<C>
</C>
&nb ......
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
sql的软件在哪里可以下啊!在网上找了蛮多都用不了啊
随便搞一D版吧,
迅雷第一个就可以用
2000,2005都这样
http://119.147.41.16/down?cid=0698C2D64D7D637D90A6D2482298E6717D4F15CD&t=2&fmt=-1 ......
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......