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 2000 Forums
 Transact-SQL (2000)
 Positioned Updates/Deleted without PK
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

krisrajz
Starting Member

19 Posts

Posted - 02/04/2007 :  04:46:13  Show Profile  Reply with Quote
How can I update/delete record(s) as specific location without using Primary Key or where using Primary Key is not possible?

Kristen
Test

United Kingdom
22403 Posts

Posted - 02/04/2007 :  08:02:50  Show Profile  Reply with Quote
You would need to use a WHERE clause that uniquely identifies the record.

UPDATE U
SET MyColumn = 'SomeValue'
FROM MyTable AS U
    -- Optional join
    JOIN MyOtherTable AS X
        ON X.SomeColumn = U.SomeColumn
WHERE     U.UniqueColumn1 = 'SomeValue1'
      AND U.UniqueColumn2 = 'SomeValue2'

Kristen
Go to Top of Page

krisrajz
Starting Member

19 Posts

Posted - 02/05/2007 :  02:41:52  Show Profile  Reply with Quote
If rows are not unique?
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 02/05/2007 :  02:45:51  Show Profile  Reply with Quote
"If rows are not unique?"

Well, I would assume that the rows in a table are different, otherwise you will have an exact duplicate.

Normally a combination of several columns will be unique.

Failing that you can include EVERY column in the WHERE clause, so that you restrict to the original record (making sure to handle NULL properly).

However, IF there are two rows which are identical [in every column] then then will BOTH get updated.

One option might be to add an IDENTITY column, which will provide a unique value for each row, and then you can use that to control the Update.

Kristen
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17584 Posts

Posted - 02/05/2007 :  02:46:36  Show Profile  Reply with Quote
quote:
Originally posted by krisrajz

If rows are not unique?


Then how do you identify which one do you want to delete if it is not unique ?



KH

Go to Top of Page

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 02/05/2007 :  02:50:41  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
Take a look at this:
http://support.microsoft.com/kb/139444

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
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.14 seconds. Powered By: Snitz Forums 2000