---
# System prepended metadata

title: Schemas and relationships in Database

---

# Schemas and relationships in Database

## Schema

### What is a Schema
A database schema is a blueprint or architecture of how our data will look. It doesn’t hold data itself, but instead describes the shape of the data and how it might relate to other tables or models. An entry in our database will be an instance of the database schema. It will contain all of the properties described in the schema.

### Why to use a Schema
- Database schemas provide us with the flexibility to create logical object groups in a database. If multiple teams are working with the same database, we can design various schemas to segregate their objects.
- Database schemas help database professionals manage access, as you can control access to users for their respective schema(s) instead of providing access to the database as whole.
- You can more efficiently manage databases because it allows the same objects in multiple schemas to appear as a different logical group.
- You can quickly move objects within different schemas.
- The schema ownership can be assigned with any database principal or roles and ownership can be transferred as well.
- It provides an additional layer of security since you need to know the correct object schema to query or manipulate data. You can also control access on schema and schema-owned objects.

## what does a primary key mean
- A primary key is a special relational database table column (or combination of columns) designated to uniquely identify each table record.
- A primary key is used as a unique identifier to quickly parse data within the table. A table cannot have more than one primary key.

## A primary key’s main features are

- It must contain a unique value for each row of data.
- It cannot contain null values.
- The primary key uniquely identifies a row.

##### A primary key might use one or more fields already present in the underlying data model, or a specific extra field can be created to be the primary key.

## Database Relationships

<img src="https://i.imgur.com/IZ12gR1.png" style="object-fit: cover;">




### One-One Relationship (1-1 Relationship)
The term One-to-One (1-1) relationship is defined as the relationship between two tables where both the tables should be associated with each other based on only one matching row.

![](https://i.imgur.com/Z84Shdn.png)

### One-Many Relationship (1-M Relationship)
The One-to-Many relationship is defined as a relationship between two tables where a row from one table can have multiple matching rows in another table.

![](https://i.imgur.com/1c49L0g.png)

### Many-Many Relationship (M-M Relationship)
M-M relationship is defined as a relationship when one or more rows in a table are associated with one or more rows in another table.

![](https://i.imgur.com/i96eFrW.png)

<iframe width="100%" height="500px" style="box-shadow: 0 2px 8px 0 rgba(63,69,81,0.16); border-radius:15px;" allowtransparency="true" allowfullscreen="true" scrolling="no" title="Embedded DrawSQL IFrame" frameborder="0" src="https://drawsql.app/alwohosh/diagrams/schema/embed%22%3E</iframe>
