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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:56:21+00:00 2026-05-25T11:56:21+00:00

Hi there I have a short question about database design. I also tried the

  • 0

Hi there I have a short question about database design. I also tried the search but can’t find what I am looking for. So here is my question:

I have two database tables Idea and Media (1:N). So basically this means one idea can have none, one or several medias. BUT I asked myself if it’s possible to define the table that each idea must have at least one media. If this is possible how can I achieve this with MS SQL Server 2008?

I hope somebody can help me out.

Thx alot for your help

UPDATE:
this is what it looks like at the moment:

enter image description here

  • 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-25T11:56:21+00:00Added an answer on May 25, 2026 at 11:56 am

    First, there is a design rule of thumb that a table models either a single entity type or a relationship between entity types but not both. Therefore, I envision three tables, Media (entity), Idea (entity) and IdeasMedia (relationship). p.s. you know the singular of ‘media’ is ‘medium’, right? 🙂

    Here’s some Standard SQL-92 DDL that focuses on keys only:

    CREATE TABLE Media (MediaID INTEGER NOT NULL UNIQUE);
    CREATE TABLE Idea (IdeaID INTEGER NOT NULL UNIQUE);
    CREATE TABLE IdeasMedia 
    (
     MediaID INTEGER NOT NULL REFERENCES Media (MediaID), 
     IdeaID INTEGER NOT NULL REFERENCES Idea (IdeaID)
    );
    CREATE ASSERTION Idea_must_have_media DEFERRABLE 
       CHECK (
              NOT EXISTS (
                          SELECT * 
                            FROM Idea AS i 
                           WHERE NOT EXISTS (
                                             SELECT * 
                                               FROM IdeasMedia AS im 
                                              WHERE im.MediaID = i.IdeaID
                                            )
                         )
             );
    

    There is a ‘chicken and egg’ scenario here: can’t create an idea with without a referencing IdeasMedia but can’t create an IdeasMedia without creating an Idea!

    The ideal (set-based) solution would be for SQL Standard to support multiple assignment e.g.

    INSERT INTO Media (MediaID) VALUES (22), 
       INSERT INTO Idea (IdeaID) VALUES (55), 
       INSERT INTO IdeasMedia (MediaID, IdeaID) VALUES (22, 55);
    

    where the semicolon indicates the SQL statement boundary at which point constraints are checked and the commas denoting the sub-statements.

    Sadly, there are no plans to add this set-based paradigm to the SQL Standard.

    The SQL-92 (procedural) solution to this is as follows:

    BEGIN TRANSACTION;
    INSERT INTO Media (MediaID) VALUES (22);
    SET CONSTRAINTS Idea_must_have_media DEFERRED;
    -- omit the above if the constraint was declared as INITIALLY DEFERRED.
    INSERT INTO Idea (IdeaID) VALUES (55);
    INSERT INTO IdeasMedia (MediaID, IdeaID) VALUES (55, 22);
    SET CONSTRAINTS Idea_must_have_media IMMEDIATE;
    -- above may be omitted: constraints are checked at commit anyhow.
    COMMIT TRANSACTION;
    

    Sadly, SQL Server doesn’t support CREATE ASSERTION nor CHECK constraints that can refer to other tables nor deferrable constraints!

    Personally, I would handle this in SQL Server as follows:

    • Create ‘helper’ stored procs to add, amend and remove Ideas and their respective
      IdeasMedia relationships.
    • Remove update privileges from the tables to force users to use the
      procs.
    • Possibly use triggers to handle scenarios when deleting Media and
      Idea entities.

    Certainly, this (again procedural) implementation is far removed from the ideal set-based approach, which probably explains why most SQL coders turn a blind eye to a requirement for a 1:1..N relationship and instead assume the designer meant 1:0..N !!

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

Sidebar

Related Questions

There have been several questions recently about database indexing and clustered indexing and it
I have a question about the calendar class. I can populate days in the
There is an Oracle database schema (very small in data, but still about 10-15
I have an application design question for the nhibernate gurus our there. My application
So, I searched some here, but couldn't find anything good, apologies if my search-fu
There have been a couple of questions that sort of dealt with this but
In short: Is there any known protocol for remote process management? I have a
There have been some questions about whether or not JavaScript is an object-oriented language.
There have been several questions already posted with specific questions about dependency injection ,
I have a question about unit testing. Say I have a controller with one

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.