My Table looks like below. I need to truncate the data from this table So that I could load the data from prod data base.
This table has constraints which does not let me truncate the data.
Please help me with the query necessary to truncate this table.
SET ANSI_NULLS ON
GO
GO
SET QUOTED_IDENTIFIER ON
GO
GO
CREATE TABLE [dbo].[MYTable](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Text] [nvarchar](max) NOT NULL,
[Type] [int] NOT NULL,
[Alert] [int] NOT NULL
[HasNA] [bit] NOT NULL
CONSTRAINT [PK_MYTable] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
[ID] [int] IDENTITY(1,1) NOT NULL,
[Text] [nvarchar](max) NOT NULL,
[Type] [int] NOT NULL,
[Alert] [int] NOT NULL
[HasNA] [bit] NOT NULL
CONSTRAINT [PK_MYTable] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[MYTable] ADD CONSTRAINT [DF_MYTable_Type] DEFAULT ((0)) FOR [Type]
GO
GO
ALTER TABLE [dbo].[MYTable] ADD CONSTRAINT [DF_MYTable_Alert] DEFAULT ((-1)) FOR [Alert]
GO
GO
ALTER TABLE [dbo].[MYTable] ADD CONSTRAINT [DF__MYTable__HasNA__7E37BEF6] DEFAULT ((0)) FOR [HasNA]
GO
GO

Jignesh KumarRank #91 · 22.9K reputationPosted Mar 5, 2019, 8:49 PM EST
Ashish VishwakarmaRank #575 · 4.2K reputationPosted Mar 6, 2019, 2:44 AM EST
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 6, 2019, 2:59 AM EST
Vivek KumarRank #272 · 9.3K reputationPosted Mar 5, 2019, 7:28 AM EST
Istudent RanaRank #4,270 · 354 reputationPosted Mar 6, 2019, 2:29 AM EST
Cannot truncate table 'MYTable' because it is being referenced by a FOREIGN KEY constraint.