SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL query doubts
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rajeshskpm
Starting Member

India
10 Posts

Posted - 01/30/2009 :  04:50:53  Show Profile  Reply with Quote
suppose a table contains 500 rows. i want to delete 13th,14th,15th rows in a table. how to do this using single query? please reply

rajesh

raky
Aged Yak Warrior

767 Posts

Posted - 01/30/2009 :  04:52:25  Show Profile  Reply with Quote
If the table contains a identity column or primary key column then

delete from table
where primarykeycol in ( 13,14,15)
Go to Top of Page

Nageswar9
Aged Yak Warrior

India
600 Posts

Posted - 01/30/2009 :  04:52:31  Show Profile  Reply with Quote
if u dont have primarycolumn,
use row_number() it is easy for u

Edited by - Nageswar9 on 01/30/2009 04:53:05
Go to Top of Page

rajeshskpm
Starting Member

India
10 Posts

Posted - 01/30/2009 :  04:54:53  Show Profile  Reply with Quote
plese write full query

rajesh
Go to Top of Page

bklr
Flowing Fount of Yak Knowledge

India
1693 Posts

Posted - 01/30/2009 :  04:59:57  Show Profile  Reply with Quote
delete s from (select row_number() over( order by id)as rid,* from emp)s where rid in (13,14,15)
Go to Top of Page

Nageswar9
Aged Yak Warrior

India
600 Posts

Posted - 01/30/2009 :  05:01:17  Show Profile  Reply with Quote
delete table where primarycol in ( 13,14,15)

(or)

delete t from
( select *,row_number() over ( partition fieldname order by fieldname ) as rn from urtable ) t
where t.rn in (13,14,15)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000