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:

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) andIdeasMedia(relationship). p.s. you know the singular of ‘media’ is ‘medium’, right? 🙂Here’s some Standard SQL-92 DDL that focuses on keys only:
There is a ‘chicken and egg’ scenario here: can’t create an idea with without a referencing
IdeasMediabut can’t create anIdeasMediawithout creating anIdea!The ideal (set-based) solution would be for SQL Standard to support multiple assignment e.g.
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:
Sadly, SQL Server doesn’t support
CREATE ASSERTIONnorCHECKconstraints that can refer to other tables nor deferrable constraints!Personally, I would handle this in SQL Server as follows:
Ideasand their respectiveIdeasMediarelationships.procs.
MediaandIdeaentities.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 !!