Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does this means?

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint 'PK_info'. Cannot insert duplicate key in object 'info'.

/Register1.asp, line 30


thank you everyone!!! :-(
 
The field u are trying to update/insert is defined as a primary key which means u cant update/insert a value which is already present or enter a null value so u always have to update the field with a unique value.
 
So it means that i must use recordset to do it?
if yes, what must i do.:-(
 
It means that the value u are inserting into a particular column should be unique.
Check the table defn and find out which field has been defined with primary key.
Then try to insert values into this column which are not already present, i.e distinct.
It does not matter if u use recordset/command object/connection object/db lib etc. All u have to do is ensure that value of the primary key column is unique and not = null

So if u already have a value of 100 in that column, u cannot insert one more value of 100,it should be say 101.

Go through constraints and keys in SQL BOL, it would help a lot.

 
i have checked already that it is not equal to null and it is unique.

8-)
 
i have checked already that it is not equal to null and is unique.

8-)
 
I think u have not understood what i meant.You need to insert unique values for the field if u are inserting a new row if a field is specified as Primary/Unique. So try entering unique(distinct) values.

Have a read of SQL BOL for Primary key.
 
I think vishnuprasad is completely correct in his analysis and solution of your problem. I would add that in my tables I define the primary key as an IDENTITY column. Then whenever I INSERT a row, SQL Server supplies a value for the primary key column. My list of columns to insert must not include the name of the primary key.

In this example my primary key column is colA -
Code:
INSERT INTO myTable (colB, colC, ColD)
VALUES ('Not','the','primary key')

If you are not using an IDENTITY column for the primary key then you must write some code to confirm that the value you want to insert is not already used in the existing rows in the table.

For example, suppose I think 'cactus' is a value that has not yet been used as a primary key -

This is the SQL query.
Code:
SELECT * FROM myTable WHERE colA = 'cactus'

This fragment of my ASP code leaves out the gory details.
<%
if(rsCheckKeyValue.bof && rsCheckKeyValue.eof){
  //'cactus' is not yet used in the table
} else {
  //'cactus' is alread used so must pick another value,
  //  or possibly UPDATE instead of INSERT.
}
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top