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 6821967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:36:26+00:00 2026-05-26T21:36:26+00:00

I’ve got SQL database in SQL Server 2008 generated as follows: CREATE TABLE Client

  • 0

I’ve got SQL database in SQL Server 2008 generated as follows:

CREATE TABLE Client ( 
    ID bigint,
    Code varchar(50),
    ClientID int NOT NULL
);
ALTER TABLE Client 
  ADD CONSTRAINT PK_Client PRIMARY KEY CLUSTERED (ClientID);

CREATE TABLE Company ( 
    ID bigint,
    Description nvarchar(100),
    SubsidiaryOf bigint,
    companyID int NOT NULL,
    FK_Client_Company int,
    PK_Company int
);
ALTER TABLE Company 
  ADD CONSTRAINT PK_Company PRIMARY KEY CLUSTERED (companyID);

ALTER TABLE Company 
  ADD CONSTRAINT (ID = ID) FOREIGN KEY (FK_Client_Company) 
      REFERENCES Client (ClientID);

ALTER TABLE Company 
  ADD CONSTRAINT (SubsidiaryOf = ID) FOREIGN KEY (PK_Company) 
      REFERENCES Company (companyID);

CREATE TABLE ContactData ( 
    ID bigint,
    LocationID bigint,
    Contact nvarchar(50),
    contactDataID int NOT NULL,
    PK_Location int
);
ALTER TABLE ContactData 
  ADD CONSTRAINT PK_ContactData PRIMARY KEY CLUSTERED (contactDataID);

ALTER TABLE ContactData 
  ADD CONSTRAINT (LocationID = ID) FOREIGN KEY (PK_Location) 
      REFERENCES Location (locationID);


CREATE TABLE Location ( 
    ID bigint,
    CompanyID bigint,
    Country nvarchar(50),
    ZIPCode nvarchar(50),
    locationID int NOT NULL,
    PK_Company int
);
ALTER TABLE Location 
   ADD CONSTRAINT PK_Location PRIMARY KEY CLUSTERED (locationID);

ALTER TABLE Location 
   ADD CONSTRAINT (CompanyID = ID) FOREIGN KEY (PK_Company) 
       REFERENCES Company (companyID);

And would like to delete all the Companies with ID > 140000 (with related rows in other tables). I tried some combination of INNER JOINs all together in one transaction, but there is still a problem with FK_Client_Company constraint. Can anyone help me?

One more thing – I cannot add anything/modify DB structure/constraints. It has to be a query-base-solution.

  • 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-05-26T21:36:27+00:00Added an answer on May 26, 2026 at 9:36 pm

    First delete those companies’ clients

        delete client where id in (select fk_client_company from company where id > 140000)
    

    After that you should be able to run the delete statement on the company table

        delete company where id > 140000
    

    I’m ‘fairly’ sure that’s the answer you’re looking for but I’m not a 100% positive only because your naming scheme seems a little odd. I’m making the assumption that company.fk_client_company = client.id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
i got an object with contents of html markup in it, for example: string
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.