Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Unique field

Unique field

Scheduled Pinned Locked Moved Visual Basic
databasesql-serversysadminquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    charchabil03
    wrote on last edited by
    #1

    using a Sql Server DB , and having a field 'ID' with a 'varchar' datatype, how can i set the criteria of this field to be : unique No dupplicatate (like MS-Access) to dissallow the user to enter the same value twice thx

    Regards Ramy

    S C 2 Replies Last reply
    0
    • C charchabil03

      using a Sql Server DB , and having a field 'ID' with a 'varchar' datatype, how can i set the criteria of this field to be : unique No dupplicatate (like MS-Access) to dissallow the user to enter the same value twice thx

      Regards Ramy

      S Offline
      S Offline
      sathesh pandian
      wrote on last edited by
      #2

      you can set the primary key for that field so that you can prevent the dupliacates

      Sathesh Pandian

      C 1 Reply Last reply
      0
      • S sathesh pandian

        you can set the primary key for that field so that you can prevent the dupliacates

        Sathesh Pandian

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        sathesh_pandian wrote:

        you can set the primary key for that field so that you can prevent the dupliacates

        Which is not a valid thing to do if you already have a primary key! Do NOT set a column as a primary key just to make it unique. There you can apply a unique constraint to columns.


        Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos

        1 Reply Last reply
        0
        • C charchabil03

          using a Sql Server DB , and having a field 'ID' with a 'varchar' datatype, how can i set the criteria of this field to be : unique No dupplicatate (like MS-Access) to dissallow the user to enter the same value twice thx

          Regards Ramy

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          When you create your table you can do something like this:

          CREATE TABLE dbo.MyTable
          (
          MyUniqueColumn varchar(30) NULL UNIQUE NONCLUSTERED
          )


          Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups