Optional relationship in SQL Server -- How to implement in SSMS Schema Designer

3.6k views Asked by At

I have two cases where I would like to set 'optional' relationship inside one table or between two tables.

First:

enter image description here

I want to set this relation as optional, in other words: there will be categories and subcategories in one table, so subcategory column is only optional.

Second:

enter image description here

Here I want to make sure that House cannot exist without Member (mandatory relation), but Member can be without any House (optional relation).

I don't have any experience with Microsoft SQL Server and I don't have idea how can I modify these relations.

Here is the end result in Oracle diagram:

enter image description here

1

There are 1 answers

3
CJBS On BEST ANSWER

If you're asking how this can be done in the schema designer (DB Diagram) in SQL Management Studio, it's easy:-

  1. Right-click the table in the digram, choose 'Table View' -> 'Standard'

Right-clicking the table

  1. In the 'Allow Nulls' column, set the optional Foreign Keys to 'Allow Nulls'

Setting NULLable in designer

  1. Press Ctl + S to save the updates to the schema.

Additional details about the selected object in the designer (column, table, FK etc.) are available by viewing the Properties window (usually in the right of the screen). For example, here are the properties for the subcat column in the example:

subcat properties