Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8142539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:50:55+00:00 2026-06-06T12:50:55+00:00

I have two table masterTbl and detailTbl which structure is given below… –PRIMARY TABLE

  • 0

I have two table masterTbl and detailTbl which structure is given below…

--PRIMARY TABLE
CREATE TABLE masterTbl (
id INT IDENTITY(1,1) CONSTRAINT pk_id PRIMARY KEY, 
name VARCHAR(100) NOT NULL, 
description VARCHAR(max))

--FORIGN TABLE
CREATE TABLE detailTbl (
id INT IDENTITY(1,1) PRIMARY KEY,
m_id INT NOT NULL CONSTRAINT fk_mid FOREIGN KEY REFERENCES masterTbl(id) ON DELETE CASCADE,
details VARCHAR(MAX))

I want to perform

TRUNCATE TABLE masterTbl 

but it is encountering error “Cannot truncate table ‘testDB.dbo.masterTbl’ because it is being referenced by a FOREIGN KEY constraint.”

How can i use TRUNCATE command on masterTbl??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:50:56+00:00Added an answer on June 6, 2026 at 12:50 pm

    You have to remove the FK constraint fk_mid.
    But you won’t be able to put it back if the FK Constraint is not respected, cause the CASCADE REMOVE won’t happen (risk of orphans)

    Or use DELETE instead of TRUNCATE.
    Which will preserve the DELETE CASCADE behaviour.

    EDIT

    DELETE FROM dbo.masterTbl;
    DBCC CHECKIDENT ('dbo.masterTbl', RESEED, 0) -- will set IDENTITY count back to 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two table like below CREATE TABLE IF NOT EXISTS `countries` ( `id`
i have two table: declare @t1 table (id int) declare @t2 table (id int)
I have two table and I should write a select query which join this
Using SQL Server 2005 I have two table which have the same datatype and
I have two table cpuinfo and jobinfo. I want to create report using both
I have two table categories ( hierarchical structure ) and attachment that have relations
I have two table News and NewsComments. I followed the rules of naming structure
I have two table 1. Airline -id(primary), name 2. Form - id(primary), operator, other
I have two table called Production and Chart as below. Production Name Layer CDV
I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.