You are on page 1of 6

Assignment - 1

Name : Branch : CSE

UID : Subject : DBMS

Ques : 2

Derive a schema for CUIMS database.

Answer:
A schema diagram is a diagram which contains entities and the attributes that
will define that schema.

A schema diagram only shows us the database design. It does not show the
actual data of the database. Schema can be a single table or it can have more
than one table which is related.

When constructing the backend of an application, you need to take into account
how the frontend will talk to the backend. More important, however, is the
construction and design of your database. The relationships your data forms will
lead to the construction of your database schema.

A database schema is an abstract design that represents the storage of your


data in a database. It describes both the organization of data and the
relationships between tables in a given database. Developers plan a database
schema in advance so they know what components are necessary and how they
will connect to each other.
In this guide, we will learn what a database schema is and why they are used.
We will go through a few common examples so you can learn how to configure a
database schema on your own.

When it comes to choosing your database, one of the things you have to think
about is the shape of your data, what model it will follow, and how the
relationships formed will help us as we develop 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.

A database schema will include:

• All important or relevant data


• Consistent formatting for all data entries
• Unique keys for all entries and database objects
• Each column in a table has a name and data type

The size and complexity of your database schema depends on the size of your
project. The visual style of a database schema allows programmers to structure
the database and its relationships properly before jumping into the code. The
process of planning a database design is called data modeling.

Schemas are important for designing database management systems (DBMS) or


relational database management systems (RDBMS). A DBMS is a software that
stores and retrieves user data in a secure way that follows the ACID concept.

In many companies, database design and DBMS responsibilities usually fall to


the role of the Database Administrator (DBA). DBAs are responsible for ensuring
that data analysts and database users can easily access information. They work
alongside management teams to plan and securely manage an organization’s
database.

We use the statement CREATE SCHEMA to get started. Note that PostgreSQL will
automatically create a public schema. Every new object will be placed here.
To create objects in a database schema, we write a qualified name that includes
the name of the schema and the name of the table:

The following example from the Postgres documentation CREATE SCHEMA to


initiate a new schema called scm, a table called deliveries, and a view called
delivery_due_list.
Primary keys and foreign keys prove useful here as they represent the
relationship from one table to the next.
Program code :
CREATE DATABASE
example; USE example;
DROP TABLE IF EXISTS
customer; CREATE TABLE
customer (
id INT AUTO_INCREMENT
PRIMARY KEY,
postalCode VARCHAR(15)
default NULL,
)

DROP TABLE IF EXISTS


product;

CREATE TABLE product (


id INT AUTO_INCREMENT
PRIMARY KEY,
product_name
VARCHAR(50) NOT NULL,
price VARCHAR(7) NOT
NULL,
qty VARCHAR(4) NOT NULL
)
DROP TABLE IF EXISTS
transactions; CREATE
TABLE transactions (
id INT AUTO_INCREMENT
PRIMARY KEY,
cust_id INT, timedate
TIMESTAMP, FOREIGN
KEY(cust_id)
REFERENCES customer(id),
)
CREATE TABLE
product_transaction (
prod_id INT,
trans_id INT,
PRIMARY KEY(prod_id,
trans_id), FOREIGN
KEY(prod_id)
REFERENCES product(id),
FOREIGN KEY(trans_id)
REFERENCES
transactions(id)

You might also like