Istudent Rana

Istudent Rana

  • 1.4k
  • 360
  • 85k

How do i truncate the table which has constraints?

Mar 5 2019 11:36 AM
How do i truncate the table which has constraints?

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
SET QUOTED_IDENTIFIER ON
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
ALTER TABLE [dbo].[MYTable] ADD CONSTRAINT [DF_MYTable_Type] DEFAULT ((0)) FOR [Type]
GO
ALTER TABLE [dbo].[MYTable] ADD CONSTRAINT [DF_MYTable_Alert] DEFAULT ((-1)) FOR [Alert]
GO
ALTER TABLE [dbo].[MYTable] ADD CONSTRAINT [DF__MYTable__HasNA__7E37BEF6] DEFAULT ((0)) FOR [HasNA]
GO

Answers (5)