Answer the question
In order to leave comments, you need to log in
How to remove The INSERT statement conflicted with the CHECK constraint error?
Good day!
I get the following error when I try to add a new record to the database:
The INSERT statement conflicted with the CHECK constraint "CK_emp_id". The conflict occurred in database "pubs", table "dbo.employee", column 'emp_id'.
The statement has been terminated.
([emp_id] like '[A-Z][A-Z][A-Z][1-9][0-9][0-9][0-9][0-9][FM]' OR [emp_id] like '[A-Z]-[A-Z][1-9][0-9][0-9][0-9][0-9][FM]')
SqlParameter pEmpIdIns = new SqlParameter("@EmpId", empId);
pEmpIdIns.SqlDbType = SqlDbType.Char;
CREATE OR ALTER PROCEDURE spInsertEmployee
@empId CHAR,
@fName VARCHAR(20),
@mInit CHAR(1)=NULL,
@lName VARCHAR(30),
@jobId SMALLINT,
@jobLvl TINYINT,
@pubId CHAR(4),
@hireDate DATETIME
AS
BEGIN
INSERT INTO employee (emp_id, fname, minit, lname, job_id, job_lvl, pub_id, hire_date, EmployeeType)
VALUES(@empId, @fName, @mInit, @lName, @jobId, @jobLvl, @pubId, @hireDate, 0);
END
GO
INSERT INTO employee (emp_id, fname, minit, lname, job_id, job_lvl, pub_id, hire_date, EmployeeType)
VALUES('A-A11111F', 'Test', 'T', 'Tester', 14, 90, 9952, 2021-01-01, 0);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question