Jump to content

Recommended Posts

I'm needing to insert values into a table. I have the data type set up as varchar(4). The values are combinations of 4 letters and/or numbers. When trying to insert it won't accepts the alpha characters. The column is set to Not Null and as the primary key. Any suggestions as to why it won't accept?

Edited by SqlBeginner
Link to post
Share on other sites

This is an example of how I'm putting it in

INSERT INTO [dbo].[tbljobs] (jobcode, Title) VALUES

(2834, 'Clinical Services Director'),(H27A, 'Clinical Social Worker'),(H27C, 'Clinical Social Worker'),(H27D, 'Clinical Social Worker')


When I put it into SQL it'll have red lines underneath it and I'll get the error Msg 207, level 16, state 1, line 1 Invalid column name

Link to post
Share on other sites

Looking at the same table when I attempt to insert the values I'm receiving a new error message.

Msg 2627, Level 14, State 1, Line 1

Violation of PRIMARY KEY constraint 'PK_tblJobs'. Cannot insert duplicate key in object 'dbo.tblJobs'.

The statement has been terminated.


I went through all fields to ensure that there weren't any duplicate values but it still won't take it. JobID is the pk nvarchar(4) I also went through the 'title' column and changed any names that were the same.

Link to post
Share on other sites

That means you're trying to insert a row with a value in the primary key that already exists in a row in the table. A primary key needs to be unique, you can't have multiple rows with the same value in that field.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...