SqlBeginner Posted July 8, 2013 Share Posted July 8, 2013 (edited) 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 July 8, 2013 by SqlBeginner Link to comment Share on other sites More sharing options...
justsomeguy Posted July 8, 2013 Share Posted July 8, 2013 If it only has problems with letters and not numbers then it sounds like you're not quoting the value. Link to comment Share on other sites More sharing options...
SqlBeginner Posted July 8, 2013 Author Share Posted July 8, 2013 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 comment Share on other sites More sharing options...
SqlBeginner Posted July 8, 2013 Author Share Posted July 8, 2013 Oh I figured it out! Link to comment Share on other sites More sharing options...
SqlBeginner Posted July 8, 2013 Author Share Posted July 8, 2013 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 comment Share on other sites More sharing options...
justsomeguy Posted July 8, 2013 Share Posted July 8, 2013 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 comment Share on other sites More sharing options...
SqlBeginner Posted July 9, 2013 Author Share Posted July 9, 2013 The table is empty Link to comment Share on other sites More sharing options...
SqlBeginner Posted July 9, 2013 Author Share Posted July 9, 2013 Nevermind Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now