0% found this document useful (0 votes)
27 views3 pages

SB101 - C2

The document contains SQL queries to create tables, insert data, and perform joins. Tables created include person and address with a left join between them. Other tables created are customers and orders with a foreign key relationship.

Uploaded by

priyobrato banik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

SB101 - C2

The document contains SQL queries to create tables, insert data, and perform joins. Tables created include person and address with a left join between them. Other tables created are customers and orders with a foreign key relationship.

Uploaded by

priyobrato banik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

=================================================================

1.
--------------------------------------------------
create table person

(personId int primary key,


lastName varchar(18),
firstName varchar(18)
);

create table Address


(addressId int primary key,
personId int,
City varchar(20),
state varchar(20)
);

insert into person values(1, 'wang', 'Allen');


insert into person values(1, 'Alice', 'Bob');

insert into Address values(1, 2,'New York City','New York');


insert into Address values(2, 3,'San Diego','California');

select firstName,lastName,City,state from person left join Address on


person.personId=address.personId;

+-----------+----------+---------------+----------+
| firstName | lastName | City | state |
+-----------+----------+---------------+----------+
| Allen | wang | NULL | NULL |
| Bob | Allice | New York City | New York |
+-----------+----------+---------------+----------+

===================================================================================
==========================================================
2.Briefly explain what a transaction is along with the ACID properties.

Ans - Transaction is small unit of program which may contains several low level
task.
Transaction in a database system must maintain Atomicity, Consistency,
Isolation, and Durability , which is commonly
known as ACID properties.

Atomicity : Atomocity means either all operatins of the transaction are


reflected properly in the database or else none.

Consistecny : Consistency simply means the the executation of a


transaction in isolatin , perserve the consistency of the datebase.

Isolation :Isolation can be explained through multiple transaction may


execute concurrently, the system gurantee that the pair of Transaction Ti,
and Tj which execute finised before and after.Each transaction is unaware of other
transaction executating concurrenlty in the system.

Durability : Durability means when the transaction is complete


successfully, the change is made in database remians, if there are some system
failure in the future.
===================================================================================
======================================================================
3.
CREATE TABLE customers (
customer_id INT NOT NULL PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
address VARCHAR(255) DEFAULT NULL,
city VARCHAR(255) DEFAULT NULL,
state VARCHAR(2) DEFAULT NULL,
zip_code VARCHAR(5) DEFAULT NULL
);

insert into customers values(1 , 'abc', 'a', '[email protected]' , '1st


street','chennai', 'TN', '60001');
insert into customers values(2, 'efg', 'e', '[email protected]' , '2nd
street','Bangalore', 'KA', '50002');
insert into customers values(3 , 'ijk', 'i', '[email protected]' , '3rd
street','Mumbai', 'MH', '40002');

CREATE TABLE orders (


order_id INT NOT NULL PRIMARY KEY,
customer_id INT NOT NULL,
order_placed_date DATE NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers
(customer_id)
);

insert into orders values(1, 1, '2016-11-11');


insert into orders values(2, 1, '2016-10-01');
insert into orders values(3, 2, '2016-06-01');
insert into orders values(4, 2, '2015-06-01');
insert into orders values(5, 1, '2015-06-01');

===================================================================================
==============================================================
4.a) What is normalization and why is it needed?
Ans -
Normalization is a database design technique that reduce data redundancy and
eliminates undesirable
characteristics like insertion, updation,and Deletion Anomalies. Normalization
rules divies larger tables
into smaller tables and link them using relationships.The purpose the
normalization in SQL is to eliminate
repetative data and ensure data is stored logically.

It is needed because it ensure that the table only contains data directly
related to the primary key,each data
field contains only one data elements, and remove repetative data.

b) What is the 2NF? Explain with an example. You don�t need to draw the
tables or write the queries. Just mention the schema before and after the
third normal form.

Ans : A database is in 2nd normal form if it satify following conditions;


i. All the database tables must be in the first normal form.
ii. All non-key attribues are fully dependent on the primary key attribues. The
partial dependency of non-key
attributes on the primary key attributes is not allowed.

Example-
1. The baby is partially dependent on her father , and similarly
partially dependent on her mother.
2. if there is three data candId, subject_NO, Subject_Fee , then
subject_fee can't determine the values of the CandNo, or
Subject_No;subjec_fees with subject_No still cant determine the CandId. conclusion
subject_fee is non-prime doesn't
belong to candidate key.

You might also like