Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Can't Delete Rows

Author  Topic 

GregDDDD
Posting Yak Master

120 Posts

Posted - 2010-03-19 : 18:33:00
I'm kind of new to SQL Server development. Most of what I've done in the past has been with MS Access, or just querying a SQL Server. I designed a table in SQL Server 2000 that has 6 columns. I'm writing data to the table from a VB.Net app using OLEdb. I'm in testing mode, so I tried to delete all or some of the rows in the table from Enterprise Manager. There are only 12 rows and whether I try to delete one or all I get the following error. Any help is appreciated.

"Key column information was insufficient or incorrect. Too many rows were affected by update."

Greg

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-19 : 18:41:24
The GUI inside Enterprise Manager requires that the table has a primary key, or presumably a unique key too, in order to delete the rows. Either add a PK or run the DELETE syntax in Query Analyzer.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

GregDDDD
Posting Yak Master

120 Posts

Posted - 2010-03-19 : 19:55:40
I had a feeling it was a PK issue, given the error message. It really doesn't apply to this table, but I suppose I could add a counter field. Does SQL Server have something like the "AutoNumber" field like Access. I tried "uniqueidentifier", hoping it would auto populate with a counter, but it didn't. I have a date/time field, but the first two rows are null and now I can't delete them. It won't let me set a PK. Should I just start over?

Greg
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-19 : 20:00:21
SQL Server's "autonumber" is called Identity. You can add it through the GUI by going to the table properties and putting "Yes" for the identity field. It'll have to drop the table and recreate it; your data will be saved.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-19 : 20:01:14
Alternatively to adding the identity field, just run a DELETE query in Query Analyzer. There is no requirement of PKs or any constraints in order to delete rows. That's just an Enterprise Manager GUI requirement; T-SQL allows you to delete rows without them.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

GregDDDD
Posting Yak Master

120 Posts

Posted - 2010-03-19 : 20:47:16
Thanks, I'll give it a try Monday. At 5 til 5 today I tried a quick delete query but SQL Server didn't like my Access syntax: DELTE * FROM tblFaxRoute
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-03-19 : 22:35:06
take out the *

DELETE FROM tblFaxRoute

If you intend to delete every record, you can truncate the table:

TRUNCATE TABLE tblFaxRoute
Go to Top of Page

GregDDDD
Posting Yak Master

120 Posts

Posted - 2010-03-22 : 15:03:15
So the 'DELETE FROM tblFaxRoute' syntax worked and I was able to clear the table. However, the 'Identity' field property is grayed out. This got me to thinking about my permissions and I'm not even sure what login I'm using. On SQL Server 2005/08 I must login when I open Enterprise Manger. On SQL Server 2000 it does not prompt me for a login. Is it Windows Authentication? I created a login that I use from VB.Net code, but who am I from the Enterprise Manger?

Greg
Go to Top of Page

GregDDDD
Posting Yak Master

120 Posts

Posted - 2010-03-22 : 16:22:47
Oops, my bad. I was trying to make a 'uniqueidentity' field 'identity'. I deleted the field and created a new. I set that to 'identity' and it is working as expected. I can now delete rows from the Open Table view. Still, who am I logged in as when in Enterprise Manger? Is it sa?

Greg
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-22 : 16:32:01
In Enterprise Manager, right click on the server and go to edit to check out the authentication.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -