Unix Technical Forum

SQL Delete Syntex

This is a discussion on SQL Delete Syntex within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi You can do a select top 1 * from <table>, my question is how does one delete the ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 04:56 AM
rc@die@you@!spammers.sandworm.demon.co.uk
 
Posts: n/a
Default SQL Delete Syntex

Hi

You can do a select top 1 * from <table>, my question is
how does one delete the row whithout having to do lots of where
clause ?
Is there a equivelant delete top 1 from <table>

Thanks




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 04:56 AM
Ronnie Chee
 
Posts: n/a
Default Re: SQL Delete Syntex

<rc@die@you@!spammers.sandworm.demon.co.uk> wrote in message
news:vol9q094ehtd9d5n9c5rab726cr17s05m2@4ax.com...
> Hi
>
> You can do a select top 1 * from <table>, my question is
> how does one delete the row whithout having to do lots of where
> clause ?
> Is there a equivelant delete top 1 from <table>
>
> Thanks
>

You can use "SET ROWCOUNT" to limit the number of rows affected by the
subsequent statement.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 04:56 AM
David Portas
 
Posts: n/a
Default Re: SQL Delete Syntex

> Is there a equivelant delete top 1 from <table>

How useful would that be? If you want to delete something you usually want
to delete something specific:

DELETE FROM YourTable
WHERE x = 1234

Tables of course have no inherent order so to perform an operation on "TOP
1" of anything without specifying any other criteria is both meaningless and
dangerous.

--
David Portas
SQL Server MVP
--


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 04:56 AM
Ross Presser
 
Posts: n/a
Default Re: SQL Delete Syntex

On Wed, 24 Nov 2004 18:49:09 +0000,
rc@die@you@!spammers.sandworm.demon.co.uk wrote:

> Hi
>
> You can do a select top 1 * from <table>, my question is
> how does one delete the row whithout having to do lots of where
> clause ?
> Is there a equivelant delete top 1 from <table>
>
> Thanks


The best way is

DELETE FROM tbl WHERE tbl.pkey = (SELECT TOP 1 pkey FROM tbl)

It's not that much extra typing, and it's clear what is meant.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 04:56 AM
--CELKO--
 
Posts: n/a
Default Re: SQL Delete Syntex

>> how does one delete the row without having to do lots of WHERE
clause ?<<

In a relational database, you use the key in the WHERE clause. Have
you ever read anything about relational databases?

The idea of using the non-relational, hidden cursor SELECT TOP 1 is
insane. Since tables have no ordering, you don't know what will be in
the PHYSICAL location that is being trashed. This "feature" is a
serious violation of the Relational model.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:56 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com