SQL Syntax Issue
-
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'.
-
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'.
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
-
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'.
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