Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why Iam getting this error while iam inserting data through stored procedure. Any thing is wrong here
Error:The INSERT statement conflicted with the CHECK constraint "CK__Master_Adm__role__7E6CC920". The conflict occurred in database "samp", table "dbo.Master_Admin", column 'role'.

I have table, the table structure is like
CREATE TABLE Master_Admin
(
mstr_id int primary key identity(1,1),
login_UserName varchar(30) not null unique,
login_pass varchar(20) not null,
role char(20) check(role in ('SuperAdmin','Admin','EndUser')) not null,
)

And iam inserting values into this table through storedprocedure and structure of SP is like
create procedure Master_Admin_Insert(
@login_uname varchar(30),
@login_pwd varchar(20),
@role char(20)
)
as
begin
insert into Master_Admin(
login_UserName,
login_pass,
role
)
values
(
'@login_uname',
'@login_pwd',
'@role'
)
end

Execution of Procedure
declare @login_uname varchar(30),
@login_pwd varchar(20),
@role char(20)
set @login_uname='sai'
set @login_pwd='sai123'
set @role='EndUser'
exec Master_Admin_Insert @login_uname,@login_pwd,@role
Posted
Updated 24-Jul-11 23:06pm
v3

1 solution

Remove the single quotes in the value list of your Insert statement. Try this
sq
insert into Master_Admin(
login_UserName,
login_pass,
role
)
values
(
@login_uname,
@login_pwd,
@role
)
 
Share this answer
 
Comments
Toniyo Jackson 25-Jul-11 5:08am    
Correct +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900