Tuesday, 20 November 2018
MSSQL - Fix Error - Incorrect syntax near the keyword 'Inner'. when deleting record
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'Inner'.
watch solution on YouTube
Replace
Delete From Parent Inner Join Child On Parent.ParentID = Child.ParentID
Where Child.ChildID > 0
With
Delete p From Parent p Inner Join Child c On p.ParentID = c.ParentID
Where c.ChildID > 0
PARENT TABLE
/****** Object: Table [dbo].[Parent] Script Date: 2018-11-20 7:34:54 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Parent](
[ParentID] [int] IDENTITY(1,1) NOT NULL,
[ParentName] [varchar](50) NULL,
CONSTRAINT [PK_Parent] PRIMARY KEY CLUSTERED
(
[ParentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CHILD TABLE
/****** Object: Table [dbo].[Child] Script Date: 2018-11-20 7:35:22 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Child](
[ChildID] [int] IDENTITY(1,1) NOT NULL,
[ChildName] [varchar](50) NULL,
[ParentID] [nchar](10) NULL,
CONSTRAINT [PK_Child] PRIMARY KEY CLUSTERED
(
[ChildID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment