0% found this document useful (0 votes)
10 views

DATABASE LAB MID KEY

Uploaded by

sabahat yousaf
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

DATABASE LAB MID KEY

Uploaded by

sabahat yousaf
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q#3

Create a table to store data of Customers, so the table name is Customer,


Columns are Customer ID, Customer Name, Country, age, phone

CREATE TABLE Customer(


CustomerID INT PRIMARY KEY,
CustomerName VARCHAR(50),
Country VARCHAR(50),
Age INT CHECK (Age >= 0 AND Age <= 99),
Phone int(10)
);

Q4. Write a query find number of employees whose DOB is


between 02/05/1970 to 31/12/1975 and are grouped
according to gender

SELECT COUNT(*), Gender

FROM EmployeeInfo

WHERE DOB BETWEEN '02/05/1970 ' AND '31/12/1975'

GROUP BY Gender;

Q5. How do you read the last five records from a database
using a SQL query?

To retrieve the last five records from a database using a SQL query, you can
use the ORDER BY clause combined with LIMIT. Here’s an example query:

SELECT *

FROM your_table
ORDER BY id DESC

LIMIT 5;

Replace your_table_name with the name of your table


and your_primary_key_column with the primary key column that defines the
order of records. The ORDER BY your_primary_key_column DESC part sorts
the records in descending order based on the primary key column, and LIMIT
5 limits the result to the last five records.

Q6. Update the column NAME and set the value to ‘Nitin’ in
the rows where the Age is 22

UPDATE Customer
SET CustomerName = 'Nitin'
WHERE Age = 22;

Q2. Binary Relationship with 1:1 cardinality with total participation of an entity
First Convert each entity and relationship to tables. Person
table corresponds to Person Entity with key as Per-Id. Similarly
Passport table corresponds to Passport Entity with key as Pass-No.
Has Table represents relationship between Person and Passport
(Which person has which passport). So it will take attribute Per-Id
from Person and Pass-No from Passport.

As we can see from Table 1, each Per-Id and Pass-No has only one
entry in Has Table. So we can merge all three tables into 1 with
attributes shown in Table 2. Each Per-Id will be unique and not null.
So it will be the key. Pass-No can’t be key because for some
person, it can be NULL.

Per- Other Person Pass- Other


Id Attribute No PassportAttribute
QUESTION 2: CREATING AN ENTITY-RELATIONSHP DIAGRAM.

UPS prides itself on having up-to-date information on the processing and current location of each

shipped item. To do this, UPS relies on a company-wide information system. Shipped items are

the heart of the UPS product tracking information system. Shipped items can be characterized

by item number (unique), weight, dimensions, insurance amount, destination, and final delivery

date. Shipped items are received into the UPS system at a single retail center. Retail centers are

characterized by their type, uniqueID, and address. Shipped items make their way to their

destination via one or more standard UPS transportation events (i.e., flights, truck deliveries).

These transportation events are characterized by a unique scheduleNumber, a type (e.g, flight,

truck), and a deliveryRoute.

You might also like