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. Setting PRIMARY KEY using Alter Table

Setting PRIMARY KEY using Alter Table

Scheduled Pinned Locked Moved Visual Basic
helpquestion
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.
  • W Offline
    W Offline
    Widgets
    wrote on last edited by
    #1

    Guys im having a problem with this statement.. ALTER TABLE tblSample ADD SampleField nvarchar (30) NOT NULL CONSTRAINT SampleField PRIMARY KEY im just trying to set my newly added column and at the same time setting it as a primary key.. but it wont work.. Is there any other way? or can it set an existing non primary column to a primary one.. if it can then how.. thanks..

    P 1 Reply Last reply
    0
    • W Widgets

      Guys im having a problem with this statement.. ALTER TABLE tblSample ADD SampleField nvarchar (30) NOT NULL CONSTRAINT SampleField PRIMARY KEY im just trying to set my newly added column and at the same time setting it as a primary key.. but it wont work.. Is there any other way? or can it set an existing non primary column to a primary one.. if it can then how.. thanks..

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      This should work. What error are you getting? BTW, you should really ask this question in the SQL forum. It has nothing to do with VB. -- modified at 8:16 Friday 12th October, 2007

      Paul Marfleet

      K 1 Reply Last reply
      0
      • P pmarfleet

        This should work. What error are you getting? BTW, you should really ask this question in the SQL forum. It has nothing to do with VB. -- modified at 8:16 Friday 12th October, 2007

        Paul Marfleet

        K Offline
        K Offline
        kkb_2001
        wrote on last edited by
        #3

        it will not work because in sql u can not add column with Null having a primary key. it will work in access after removing nvarchar->char -- modified at 4:34 Saturday 13th October, 2007

        P 1 Reply Last reply
        0
        • K kkb_2001

          it will not work because in sql u can not add column with Null having a primary key. it will work in access after removing nvarchar->char -- modified at 4:34 Saturday 13th October, 2007

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          I'm not sure why you replied to my message instead of the original poster. Anyway, it's pretty obvious from the query syntax that the database being used is SQL Server not Access.

          Paul Marfleet

          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