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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:46:06+00:00 2026-05-29T19:46:06+00:00

CREATE TABLE [dbo].[ProjectTasks] ( [TaskID] [int] IDENTITY(1,1) NOT NULL, … [DefaultTaskValue] [int] NULL )

  • 0
CREATE TABLE [dbo].[ProjectTasks]
(
    [TaskID] [int] IDENTITY(1,1) NOT NULL,
    ...
    [DefaultTaskValue] [int] NULL
)

ALTER TABLE [dbo].[ProjectTasks] ADD  CONSTRAINT [PK_ProjectTasks] PRIMARY KEY 
CLUSTERED 
(
    [TaskID] ASC
)

ALTER TABLE [dbo].[ProjectTasks] ADD CONSTRAINT [FK_ProjectTasks_TaskValues] 
FOREIGN KEY([TaskID], [DefaultTaskValue])
REFERENCES [dbo].[TaskValues] ([TaskID], [Value])
GO

CREATE TABLE [dbo].[TaskValues]
(
    [TaskID] [int] NOT NULL,
    [Value] [int] NOT NULL,
    ...
)

ALTER TABLE [dbo].[TaskValues] ADD  CONSTRAINT [PK_TaskValues] PRIMARY KEY CLUSTERED 
(
    [TaskID] ASC,
    [Value] ASC
)

ALTER TABLE [dbo].[TaskValues] ADD CONSTRAINT [FK_TaskValues_ProjectTasks] 
FOREIGN KEY([TaskID])
REFERENCES [dbo].[ProjectTasks] ([TaskID])
GO

Given the above, no record in either table can be deleted – is there any neat solution? What I’d LIKE to do is sort the design to make the link table a pure link table and not to itself carry the value. This has not been a problem up to now because rows were never required to be actually deleted (they were flagged, but not actually deleted), and of course you can insert because DefaultValue can be NULL.

EDIT: In response to my downmarker, I should have mentioned, I have considered both ON DELETE CASCADE and a TRIGGER, I am looking for alternatives to those scenarios, and clearly ON DELETE SET NULL will not work.

  • 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-29T19:46:08+00:00Added an answer on May 29, 2026 at 7:46 pm

    I was surprised by your statement

    and of course you can insert because DefaultValue can be NULL

    and had to look it up. MSKB says

    Specifically, if a composite foreign key has been defined on columns
    that allow nulls, and at least one of the columns, upon the insert or
    update of a row, is set to null, then the foreign key constraint will
    be satisfied. This is true even if there is not a row in the related
    table to which any of the corresponding columns are matched.

    I guess I was not aware of this information. So I suggest the following commands:

    UPDATE ProjectTasks SET DefaultTaskValue = NULL *W
    DELETE TaskValues *W
    DELETE ProjectTasks *W
    

    *W is your WHERE condition (on TaskID etc)

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

Sidebar

Related Questions

I have this sql statement: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName]
CREATE TABLE [dbo].[user]( [userID] [int] IDENTITY(1,1) NOT NULL, [fcode] [int] NULL, [scode] [int] NULL,
I have the following table: CREATE TABLE [dbo].[Tree]( [AutoID] [int] IDENTITY(1,1) NOT NULL, [Category]
I have the following table CREATE TABLE [dbo].[LogFiles_Warehouse]( [id] [int] IDENTITY(1,1) NOT NULL, [timestamp]
I have a table Travelers : CREATE TABLE [dbo].[Travelers]( [TravelerId] [int] IDENTITY(1,1) NOT NULL,
We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
I have a following table CREATE TABLE [dbo].[test_table] ( [ShoppingCartID] [int] IDENTITY(1,1) NOT NULL,
I have the following table: CREATE TABLE [dbo].[EntityAttributeRelship]( [IdNmb] [int] IDENTITY(1,1) NOT NULL, [EntityIdNmb]
I have the following table structures CREATE TABLE [dbo].[WorkItem]( [WorkItemId] [int] IDENTITY(1,1) NOT NULL,
Table definition: CREATE TABLE [dbo].[AllErrors]( [ID] [int] IDENTITY(1,1) NOT NULL, [DomainLogin] [nvarchar](50) NULL, [ExceptionDate]

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.