Hierarchical and Recursive Queries in SQL Server
Jasmin Ludolf
Content Developer
The relational database model is the most widely used database model, which is the standard in database development.
A relational data model consists of:
Properties:
| ID | Name | Birthday |
|---|---|---|
| 1 | Adam Smith | 1.3.1978 |
| 2 | Anna Jones | 23.8.1991 |
| 3 | Paul Williams | 2.5.1954 |
| 4 | Jessica Anderson | 2.5.1954 |
A relation is created by:
Properties of primary keys:
Properties of foreign keys:
Example: Order history

Primary key:
fieldName fieldType NOT NULL PRIMARY KEY,
e.g., for table Person_Data:ID INT NOT NULL PRIMARY KEY
Foreign key:
fieldName fieldType FOREIGN KEY REFERENCES tableName(primaryKey)
e.g., newID INT FOREIGN KEY REFERENCES Person_Data(ID)
Relational algebra is a formal language for relational databases and makes it possible to form a new relation from two or more relations.
Examples:
SELECTUNIONDIFFERENCE JOINHierarchical and Recursive Queries in SQL Server