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. Database & SysAdmin
  3. Database
  4. SQL Syntax Issue

SQL Syntax Issue

Scheduled Pinned Locked Moved Database
databasehelpsql-serversysadmin
3 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.
  • F Offline
    F Offline
    Frank Lepkowski
    wrote on last edited by
    #1

    Guru's, I have the following SQL query and it gives me back some syntactical errors and I am not familiar enough with Sql Server to understand exactly what it is I am doing wrong. Thanks in advance for an information! ALTER TABLE BatchData DROP CONSTRAINT PK_BatchData ALTER COLUMN StartTime VARCHAR(50) NOT NULL ADD PRIMARY KEY (BatchID,StartTime) Gives error: Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'COLUMN'.

    T L 2 Replies Last reply
    0
    • F Frank Lepkowski

      Guru's, I have the following SQL query and it gives me back some syntactical errors and I am not familiar enough with Sql Server to understand exactly what it is I am doing wrong. Thanks in advance for an information! ALTER TABLE BatchData DROP CONSTRAINT PK_BatchData ALTER COLUMN StartTime VARCHAR(50) NOT NULL ADD PRIMARY KEY (BatchID,StartTime) Gives error: Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'COLUMN'.

      T Offline
      T Offline
      Tim Carmichael
      wrote on last edited by
      #2

      From what I can tell, you are trying to perform three actions: drop constraint alter column add primary key Each action must be completed separately, so: ALTER TABLE BatchData DROP CONSTRAINT PK_BatchData ALTER TABLE BatchData ALTER COLUMN StartTime VARCHAR(50) NOT NULL ALTER TABLE BatchData ADD PRIMARY KEY (BatchID,StartTime) Does that help? Tim

      1 Reply Last reply
      0
      • F Frank Lepkowski

        Guru's, I have the following SQL query and it gives me back some syntactical errors and I am not familiar enough with Sql Server to understand exactly what it is I am doing wrong. Thanks in advance for an information! ALTER TABLE BatchData DROP CONSTRAINT PK_BatchData ALTER COLUMN StartTime VARCHAR(50) NOT NULL ADD PRIMARY KEY (BatchID,StartTime) Gives error: Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'COLUMN'.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Member 8003276 wrote:

        ADD PRIMARY KEY (BatchID,StartTime)

        Try:

        ALTER TABLE BatchData
        ADD CONSTRAINT PK_BatchData PRIMARY KEY (BatchID, StartTime);

        It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

        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