alter table add cloumns id identity(1,1) delete from table where id=n
--删除某一行其中id为主键 declare @x int,@sql varchar(8000) set @x=11 set @sql='delete jobs where job_id in('+ 'select job_id from (select top '+cast(@x as varchar(4)) +' job_id from jobs) aa where not exists (select 1 from '+ '(select top '+ cast(@x-1 as varchar(4)) +' job_id from jobs) bb where aa.job_id=bb.job_id))' exec(@sql)
你可以:SET ROWCOUNT 10 delete 表只删前10条
SET ROWCOUNT 1 delete from 表 where 主键 not in ( select top n-1 主键 from 表 )
是可以用游标实现啊。如下面: declare state_cursor cursor scroll for 你的sql语句, open state_cursor FETCH relative 你要删除的行号 from state_cursor --移动到你所要删除的行号 然后取出关键字了,再在表中的where语句中写上关键字,可以试试。
declare @t1 table (id int) declare @t2 table (id int) insert @t1 select top 3 id from test_1 insert @t2 select top 2 id from test_1 delete from test_1 t where t.id =(select id from @t1 t1 where id not in (select id from @t2))
delete from table where id=n
declare @x int,@sql varchar(8000)
set @x=11
set @sql='delete jobs where job_id in('+
'select job_id
from (select top '+cast(@x as varchar(4)) +' job_id
from jobs) aa
where not exists
(select 1 from '+
'(select top '+ cast(@x-1 as varchar(4)) +' job_id
from jobs) bb where aa.job_id=bb.job_id))'
exec(@sql)
delete 表只删前10条
delete from 表
where 主键 not in (
select top n-1 主键 from 表
)
可以看看我的这个问题吗?
http://expert.csdn.net/Expert/TopicView1.asp?id=2488838
我是想在VC的程序中做这件事情,现在竟然创建表出问题了
declare state_cursor cursor scroll for 你的sql语句,
open state_cursor
FETCH relative 你要删除的行号 from state_cursor --移动到你所要删除的行号
然后取出关键字了,再在表中的where语句中写上关键字,可以试试。
declare @t2 table (id int)
insert @t1 select top 3 id from test_1
insert @t2 select top 2 id from test_1
delete from test_1 t where t.id =(select id from @t1 t1 where id not in (select id from @t2))