Adding records to a table == Violation of UNIQUE K

Results 1 to 5 of 5

Thread: Adding records to a table == Violation of UNIQUE K

  1. #1
    Keith Railton Guest

    Default Adding records to a table == Violation of UNIQUE K

    It is obvious why this is happening, the field I am trying to add or update is set as Unique and I&#039m trying to &#039insert a duplicate key&#039. How can I prevent this? Can I catch the error in the ASP (JScript)? Or is it possible to find out if a field is unique (using an SQL statement or procedure?) before I try to add to the table (so I can at least do -some- client-side validation). The page(s) must run in IE4 -- I&#039m using Visual Interdev 6 for the JScript/ASP, Personal Web Server (for development), and SQL Server 7...<BR><BR>This problem has been driving me mad for over a week now! Any assistance would be gratefully received.<BR><BR>Keith Railton.

  2. #2
    Sathiya Guest

    Default RE: Adding records to a table == Violation of UNIQ

    sqlstr = "Select Name from table where Name ="<BR>sqlstr = sqlstr & "&#039" & NNNNN & "&#039"<BR>set rsName = Conn.Execute("sqlstr")<BR><BR>&#039This is to check for unique <BR>If rsName.Eof then<BR> ADD or Insert records<BR>Else<BR> Dont add give some error message<BR>End IF<BR><BR>this is one way other way is to have count(*) and check if it is greater than 0.<BR><BR>

  3. #3
    Keith Railton Guest

    Default RE: Adding records to a table == Violation of UNIQ

    Forgive my ignorance, but what does NNNNN stand for?

  4. #4
    Sathiya Guest

    Default RE: Adding records to a table == Violation of UNIQ

    sqlstr = "select Name from Tables where Name = "<BR>sqlstr = sqlstr & "&#039" & Request("Name") & "&#039"<BR><BR>--------<BR>&#060;input type ="text" name="Name" value=""&#062;<BR>-------<BR>EX<BR>NNNN = is the value which is to be added to the database


  5. #5
    Keith Railton Guest

    Default I don't think I explained myself properly...

    The code you provided discovers if there are any records that duplicate the data the user is attempting to enter. That is the simple part!<BR><BR>The table has many columns, some must be unique, and some would make no sense if set as unique. I need to discover which columns in a table are set as unique. Maybe I should clarify myself. Say the following columns are in the table:<BR><BR> empNumber int NOT NULL UNIQUE,<BR> empName varchar(15) NOT NULL,<BR> callNumber int NOT NULL UNIQUE<BR><BR>How would I discover that empNumber and callNumber had to be unique?<BR><BR>Thanks,<BR><BR>Keith.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •