Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

The INSERT statement conflicted with the CHECK constraint

I am getting error when trying to insert Product Search Filter,

Failed updating,issue is :  The INSERT statement conflicted with the CHECK constraint "CK_ProductSearchFilter". The conflict occurred in database "ShopDb", table "dbo.ProductSearchFilter".
The statement has been terminated.

ProductSearchFilter table has following columns:

CREATE TABLE [dbo].[ProductSearchFilter](
            [Id] [int] IDENTITY(1,1) NOT NULL,
            [Name] [nvarchar](50) NOT NULL,
            [IsRange] [bit] NULL,
            [MinRange] [decimal](18, 2) NULL,
            [MaxRange] [decimal](18, 2) NULL,
            [UIOrder] [int] NULL,
            [CreatedDate] [datetime] NULL,
            [UpdatedDate] [datetime] NULL
           )
 

And table has following constraint


Fix:

When you try to insert record with MinRange=10 and MaxRange=5, Here insert is violating a check constraint. This is a constraint in your database that performs a specific check - which a numeric value is greater than another value.

From that expression, you should be able to determine why your insert is being rejected. Fix the problem and insert again.

 

Invalid object name ‘XYZ’ in stored procedure?

I created successfully stored procedure CreateLeaveType , However

When I am attempting to execute stored procedure facing following error.

Msg 208, Level 16, State 1, Procedure CreateLeaveType, Line 17
Invalid object name 'LeaveType1'.

 

-- =============================================
-- Author:                    Nagnath Kendre
-- Create date: 24/10/2015
-- Description: Create leave type
-- =============================================
CREATE PROCEDURE CreateLeaveType
            -- Add the parameters for the stored procedure here
 @LeaveTitle [nvarchar](100),
 @Description [nvarchar](200),
 @UserId UNIQUEIDENTIFIER
AS
BEGIN
            -- SET NOCOUNT ON added to prevent extra result sets from
            -- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @chkExists int
SELECT @chkExists=TypeId FROM LeaveType1 WHERE LeaveTitle=@LeaveTitle AND
[Description]=@Description
 
INSERT INTO dbo.LeaveType
        (
                                    LeaveTitle,
                                    [Description],
                                    AddedBy,
                                    CreatedDate)
                                    values
                                    (@LeaveTitle,
                                     @Description,
                                     @UserId,
                                     GETDATE()
                                    )
 
END
GO


Fix:

To fix Error change table name ‘LeaveType1’  to ‘LeaveType’ ,reason leaveType1 is not exist in datbase.