问题一:有一张user表,客户要求ID号码唯一,最大的ID号码就是user总人数,可以实现吗?
问题二:有一张news表,我想用两个字段排序,这两个字段都是数字,也就是说,先对字段一排过一次序的基础上在对字段二排序,可以实现吗?
你看这样行不行:
1.
create table table2
(userid int identity(1,1) not null constraint pk_table2_id primary clustered key,
username varchar(30))
2.
alter trigger trig1 on table2
for delete
as
alter table table2
drop pk_table2_id
alter table table2
drop column userid
--drop index table2.pk_table2_id
alter table table2
add
userid int identity(1,1) not null constraint pk_table2_id primary key
go
3.
declare @i int
declare @name varchar(30)
set @i=1
set @name=tom
while (@i<2000)
begin
insert into table2(username) values(@name+convert(varchar(30),@i))
set @i=@i+1
end
select * from table2
4.
delete table2 where username=tom8
select * from table2
为了抢时间,所以代码比较乱,不过应该可以满足你的要求
问题一:可以实现,但并不好
一张user表,客户要求ID号码唯一,将此字段设为主键即可。
user总人数不必用最大的ID号码,而用一个count函数即可。
问题二:一张news表,用两个字段排序,可以实现
select * from news order by vol1,vol2;
其中:vol1为主,在此基础上对vol2排序.
最大的ID号码就是user总人数
绝对不合理。
总人数用count(*)就可以。
不然你就在程序中重新编排ID号,使最大的ID号码就是user总人数,但在数据库中这样做是没有任何保证的。