Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Ass DB

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Assignment Database

Programming
Name : abdelrahem Hussein ali

L4Tfr300n Dr:Amany Eng: Hossam


Task1:

From the above scenario


1- Explain the database join and its types with examples. Consider the following tables, the course table and

The instructor table. State the name of the join for the following output.
code: for database

INNER JOIN: To retrieve the information about courses and their instructors, you can use INNER JOIN to combine the
course and instructor tables based on the instructor_id column:

LEFT JOIN: To retrieve all courses, including those that do not have an instructor, you can use LEFT JOIN to combine
the course and instructor tables, keeping all records from the left (course) table:
RIGHT JOIN: To retrieve all instructors, including those who do not have a course, you can use RIGHT JOIN to combine
the course and instructor tables, keeping all records from the right (instructor) table:

2- Create and manage advanced query to produce the above output


3- The following query is producing an error. Identify the error and also create the correct
core SQL query:
a) GRANT TO peter@localhost ALL PRIVILEGES on *.*;
correct :-

b) CREATE VIEW AS SELECT name, age FROM CUSTOMERS;

For example:

c) CREATE USER IDENTIFIED BY 'password' AHMED;

4- Describe the SQL commands which are used to:


a) Create a virtual table based on the result-set of an SQL statement.
b) Enables you to improve the faster retrieval of records on a database table. It creates an
entry for each
Value of the indexed columns
c) A special type of stored procedure that is invoked automatically in response to an event.
d) A collection of pre-compiled SQL statements stored inside the database. It always
contains a name,
Parameter lists, and SQL statements
e) It is used to combine rows from two or more tables, based on a related column between
them
f) It is used to specify the rule that allows or restricts what values/data will be stored in the
table.
Design in table
Command Description Example

Create a virtual table based on


the result-set of an SQL CREATE VIEW my_view AS SELECT name, age
CREATE VIEW statement. FROM my_table WHERE age > 18;

Enables you to improve the


faster retrieval of records on a
database table. It creates an
CREATE entry for each value of the CREATE INDEX my_index ON my_table
INDEX indexed columns. (last_name);

A special type of stored


procedure that is invoked CREATE TRIGGER my_trigger BEFORE INSERT
CREATE automatically in response to an ON my_table FOR EACH ROW SET
TRIGGER event. NEW.created_at = NOW();

A collection of pre-compiled SQL


statements stored inside the CREATE PROCEDURE my_procedure(IN arg1
database. It always contains a INT, IN arg2 VARCHAR(255)) BEGIN SELECT
CREATE name, parameter lists, and SQL * FROM my_table WHERE column1 = arg1 AND
PROCEDURE statements. column2 = arg2; END;

It is used to combine rows from SELECT * FROM orders JOIN customers ON


two or more tables, based on a orders.customer_id =
JOIN related column between them. customers.customer_id;

It is used to specify the rule that CREATE TABLE my_table ( id INT PRIMARY
allows or restricts what KEY, name VARCHAR(255) NOT NULL, age INT
values/data will be stored in the CHECK (age >= 18), email VARCHAR(255)
CONSTRAINT table. UNIQUE );
Task2
1-critically evaluate NoSQL database types
NoSQL databases are non-relational databases that offer flexible data models and scalability

NoSQL
Database
Type Description Advantages Disadvantages

Store data in semi- - Flexible schema<br>- Can store


Document- structured complex data structures<br>- - Querying can be complex and slow<br>-
Oriented documents such as Good for hierarchical or nested Lack of transaction support<br>- Limited to
Databases JSON or BSON data<br>- Can scale horizontally single-document ACID transactions

- Simple and fast<br>- Can scale


horizontally<br>- Good for - Limited to simple data types<br>- Limited
Key-Value Store data as key- caching<br>- Supports high querying capabilities<br>- No transaction
Stores value pairs throughput support<br>- Lack of secondary indexes

- Can store large amounts of data


Store data in efficiently<br>- Good for write- - Querying can be complex and slow<br>-
Column- column families heavy workloads<br>- Good for Lack of transaction support<br>- Limited
Family Stores instead of rows big data analytics support for ad hoc queries

- Good for complex and highly


connected data<br>- Supports
Store data as querying relationships and - Querying can be complex and slow<br>-
Graph nodes and edges in paths<br>- Can scale Lack of transaction support<br>- Limited to
Databases a graph horizontally graph-specific queries
2-Explain NoSQL database and its characteristics
Term Definition Characteristics

A type of database that is designed to


handle unstructured or semi-structured - Non-relational<br>- Schemaless or flexible
data, which does not fit neatly into the schema<br>- Horizontal scaling<br>-
traditional rows and columns of a Distributed architecture<br>- Optimized for
NoSQL relational database. performance and scalability

NoSQL databases do not use the


traditional relational data model with
tables, rows, and columns. Instead, they
use a variety of data models such as - Data can be organized in different
document, key-value, column-family, and ways<br>- No fixed schema or table
Non-Relational graph. structure

NoSQL databases allow for dynamic


schema changes and do not require a
predefined schema like in relational
databases. This allows for flexibility in data - Data can have varying fields and
Schemaless/Flexible modeling and accommodating structure<br>- Changes can be made on-
Schema unstructured data. the-fly

NoSQL databases are designed to scale


horizontally, meaning they can add more
servers to handle increased traffic or data - Can handle large volumes of data<br>-
Horizontal Scaling storage. Can handle high traffic or concurrency

NoSQL databases are designed to run on


a distributed system, meaning they can
run on multiple servers and nodes. Data is - Data can be stored on multiple
Distributed replicated across these nodes, providing servers<br>- Can provide fault tolerance and
Architecture high availability and fault tolerance. high availability

NoSQL databases are optimized for


performance and scalability, allowing for
faster data retrieval and processing. They
can handle large volumes of data and high
Performance and traffic, making them ideal for big data - High performance<br>- Ability to handle
Scalability applications. big data

3- Describe CAP theorem in table


Concept Description
A concept in distributed computing that states a distributed system can only provide two of three
CAP Theorem guarantees: consistency, availability, and partition tolerance.
Consistency All nodes see the same data at the same time, ensuring data integrity and accuracy.
All nodes can process client requests and respond with available data, ensuring responsiveness
Availability and low latency.
Partition The system continues to function despite network partitions between nodes, ensuring fault
Tolerance tolerance and system availability.
Designers of distributed systems must make trade-offs between these properties based on their
Trade-Offs specific use case and requirements.
4-Compare between SQL database and NoSQL database
Comparison SQL Database NoSQL Database

Data Model Relational Non-relational

Structured schema, with fixed


Schema tables and columns Flexible schema, with dynamic fields and structures

Query Variety of languages (e.g. JSON-based query languages, key-


Language SQL value query languages)

Vertical scaling, adding more


Scalability resources to a single server Horizontal scaling, adding more servers to a distributed system

ACID ACID compliant (Atomicity, Not always ACID compliant, with eventual consistency being a
Compliance Consistency, Isolation, Durability) common approach

Suitable for small to medium-


Data Volume sized data volumes Suitable for large data volumes

Ideal for applications with


structured data and complex Ideal for applications with unstructured or semi-structured
Use Cases queries data, with a focus on scalability and performance

Examples MySQL, PostgreSQL MongoDB, Cassandra, Redis

You might also like