Question

ON SQL Explain Normalization and Denormalization of data, What is ACID in SQL? Please explain in...

ON SQL

Explain Normalization and Denormalization of data, What is ACID in SQL? Please explain in your own word as much as possible, List the steps in creating a View, List the steps in modifying a View, List the steps in creating a table, List the steps in modifying a table, What are the different Joins? please give examples, Create a database and populate the database with data of your choice, List and explain the different data types used in a table, Explain Primary Key, Foreign Key, and Unique Key.

Homework Answers

Answer #1

Normalization:

Normalisation is used to reduce rendundancy in the data of tables in database

It avoids insert,update and delete anomolies which occurs due to redundant data.

Denormalization:

Denormalization is a database optimization technique in which we add redundant data the tables of database. This can help us to avoid costly joins in a relational database.

This can be done after normalization.

ACID properties:

A - Atomicity:

Atomicity is nothing but we have to do the entire transaction at at time or not at all.It follows all or nothing rule.

There is no chance for partial transactions.

Abort : If we abort the transaction,changes made are not visible.

Commit : If we commit the transaction,changes made are visible.

C-Consistency:

It means the database has to maintain the integrity constraints before and after the transaction.There should be no change in the constraints due to transaction.

I - Isolation:

Isolation property ensures multiple transactions can occur concurrently without leading to the inconsistency of database state. Transactions occur independently without interference. Changes occurring in a one transaction will not be visible to any other transaction until that particular change in that transaction is written to memory or has been committed.

D-Durability:

Durability is the property of assuring the data of the database will never lost.Once the transaction has completed,the updates will be stored in a permanent disk so that the data will be never losteven in the case of system failure.

Database creation and inserting data:

Primary key:

It is the attribute which uniquely identifies each ane every record of the relation.

it doesn't accepts null values.

Foreign key:

It is the attribute which refers the attribute of another table.

Unique key:

It is the attribute which uniquely identifies each ane every record of the relation.

it accepts null values.

Creation of database:

mysql> create database joins;
Query OK, 0 rows affected (0.16 sec)

mysql> use joins;
Database changed

creation of tables:

mysql> create table Student(SID varchar(10),SName char(20),SAge int,CID varchar(10));
Query OK, 0 rows affected (0.95 sec)

mysql> create table course(CID varchar(10),CName char(20),CFee float);
Query OK, 0 rows affected (0.47 sec)

mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| SID   | varchar(10) | YES |     | NULL    |       |
| SName | char(20)    | YES |     | NULL    |       |
| SAge | int(11)     | YES |     | NULL    |       |
| CID   | varchar(10) | YES |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> desc course;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| CID   | varchar(10) | YES |     | NULL    |       |
| CName | char(20)    | YES |     | NULL    |       |
| CFee | float       | YES |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

Inserting data:

mysql> insert into Student values("S160144","Praveena",21,"c1");
Query OK, 1 row affected (0.09 sec)

mysql> insert into Student values("S160431","Kalyani",22,"c2");
Query OK, 1 row affected (0.13 sec)

mysql> insert into Student values("S160646","Anusha",24,"c4");
Query OK, 1 row affected (0.06 sec)

mysql> insert into Student values("S160619","Uma Maheswari",23,"c3");
Query OK, 1 row affected (0.16 sec)

mysql> insert into Course values("c1","OOPS",50000);
Query OK, 1 row affected (0.05 sec)

mysql> insert into Course values("c2","PYTHON",40000);
Query OK, 1 row affected (0.10 sec)

mysql> insert into Course values("c5","C",60000);
Query OK, 1 row affected (0.07 sec)

mysql> select * from Student;
+---------+---------------+------+------+
| SID     | SName         | SAge | CID |
+---------+---------------+------+------+
| S160144 | Praveena      |   21 | c1   |
| S160431 | Kalyani       |   22 | c2   |
| S160646 | Anusha        |   24 | c4   |
| S160619 | Uma Maheswari |   23 | c3   |
+---------+---------------+------+------+
4 rows in set (0.00 sec)

mysql> select * from Course;
+------+--------+-------+
| CID | CName | CFee |
+------+--------+-------+
| c1   | OOPS   | 50000 |
| c2   | PYTHON | 40000 |
| c5   | C      | 60000 |
+------+--------+-------+
3 rows in set (0.00 sec)

Join queries:

//Query 1:Write a query for inner join.

mysql> select * from Student inner join course on Student.CID=Course.CID;
+---------+----------+------+------+------+--------+-------+
| SID     | SName    | SAge | CID | CID | CName | CFee |
+---------+----------+------+------+------+--------+-------+
| S160144 | Praveena |   21 | c1   | c1   | OOPS   | 50000 |
| S160431 | Kalyani |   22 | c2   | c2   | PYTHON | 40000 |
+---------+----------+------+------+------+--------+-------+
2 rows in set (0.00 sec)

//Query 2:Write a query for left outer join.

mysql> select * from Student left Outer join course on Student.CID=Course.CID;
+---------+---------------+------+------+------+--------+-------+
| SID     | SName         | SAge | CID | CID | CName | CFee |
+---------+---------------+------+------+------+--------+-------+
| S160144 | Praveena      |   21 | c1   | c1   | OOPS   | 50000 |
| S160431 | Kalyani       |   22 | c2   | c2   | PYTHON | 40000 |
| S160646 | Anusha        |   24 | c4   | NULL | NULL   | NULL |
| S160619 | Uma Maheswari |   23 | c3   | NULL | NULL   | NULL |
+---------+---------------+------+------+------+--------+-------+
4 rows in set (0.00 sec)

//Query 3:Write a query for right outer join.

mysql> select * from Student right Outer join course on Student.CID=Course.CID;
+---------+----------+------+------+------+--------+-------+
| SID     | SName    | SAge | CID | CID | CName | CFee |
+---------+----------+------+------+------+--------+-------+
| S160144 | Praveena |   21 | c1   | c1   | OOPS   | 50000 |
| S160431 | Kalyani |   22 | c2   | c2   | PYTHON | 40000 |
| NULL    | NULL     | NULL | NULL | c5   | C      | 60000 |
+---------+----------+------+------+------+--------+-------+
3 rows in set (0.00 sec)

//Query 4:Write a query for full outer join.

mysql> select * from Student right Outer join course on Student.CID=Course.CID union select * from Student left Outer join course on Student.CID=Course.CID;
+---------+---------------+------+------+------+--------+-------+
| SID     | SName         | SAge | CID | CID | CName | CFee |
+---------+---------------+------+------+------+--------+-------+
| S160144 | Praveena      |   21 | c1   | c1   | OOPS   | 50000 |
| S160431 | Kalyani       |   22 | c2   | c2   | PYTHON | 40000 |
| NULL    | NULL          | NULL | NULL | c5   | C      | 60000 |
| S160646 | Anusha        |   24 | c4   | NULL | NULL   | NULL |
| S160619 | Uma Maheswari |   23 | c3   | NULL | NULL   | NULL |
+---------+---------------+------+------+------+--------+-------+
5 rows in set (0.00 sec)


//Query 5:Write a query for cross join.

mysql> select * from Student cross join Course;
+---------+---------------+------+------+------+--------+-------+
| SID     | SName         | SAge | CID | CID | CName | CFee |
+---------+---------------+------+------+------+--------+-------+
| S160144 | Praveena      |   21 | c1   | c1   | OOPS   | 50000 |
| S160144 | Praveena      |   21 | c1   | c2   | PYTHON | 40000 |
| S160144 | Praveena      |   21 | c1   | c5   | C      | 60000 |
| S160431 | Kalyani       |   22 | c2   | c1   | OOPS   | 50000 |
| S160431 | Kalyani       |   22 | c2   | c2   | PYTHON | 40000 |
| S160431 | Kalyani       |   22 | c2   | c5   | C      | 60000 |
| S160646 | Anusha        |   24 | c4   | c1   | OOPS   | 50000 |
| S160646 | Anusha        |   24 | c4   | c2   | PYTHON | 40000 |
| S160646 | Anusha        |   24 | c4   | c5   | C      | 60000 |
| S160619 | Uma Maheswari |   23 | c3   | c1   | OOPS   | 50000 |
| S160619 | Uma Maheswari |   23 | c3   | c2   | PYTHON | 40000 |
| S160619 | Uma Maheswari |   23 | c3   | c5   | C      | 60000 |
+---------+---------------+------+------+------+--------+-------+
12 rows in set (0.00 sec)


//Query 6:Write a query for Natural join.

mysql> select * from Student Natural join Course;
+------+---------+----------+------+--------+-------+
| CID | SID     | SName    | SAge | CName | CFee |
+------+---------+----------+------+--------+-------+
| c1   | S160144 | Praveena |   21 | OOPS   | 50000 |
| c2   | S160431 | Kalyani |   22 | PYTHON | 40000 |
+------+---------+----------+------+--------+-------+
2 rows in set (0.00 sec)


//Query 7:Write a query for equi join.

mysql> select * from Student,Course where Course.CID=Student.CID;
+---------+----------+------+------+------+--------+-------+
| SID     | SName    | SAge | CID | CID | CName | CFee |
+---------+----------+------+------+------+--------+-------+
| S160144 | Praveena |   21 | c1   | c1   | OOPS   | 50000 |
| S160431 | Kalyani |   22 | c2   | c2   | PYTHON | 40000 |
+---------+----------+------+------+------+--------+-------+
2 rows in set (0.00 sec)

//Query 8:Write a query for Condition join.

mysql> select * from Student,Course where Course.CID<>Student.CID;
+---------+---------------+------+------+------+--------+-------+
| SID     | SName         | SAge | CID | CID | CName | CFee |
+---------+---------------+------+------+------+--------+-------+
| S160144 | Praveena      |   21 | c1   | c2   | PYTHON | 40000 |
| S160144 | Praveena      |   21 | c1   | c5   | C      | 60000 |
| S160431 | Kalyani       |   22 | c2   | c1   | OOPS   | 50000 |
| S160431 | Kalyani       |   22 | c2   | c5   | C      | 60000 |
| S160646 | Anusha        |   24 | c4   | c1   | OOPS   | 50000 |
| S160646 | Anusha        |   24 | c4   | c2   | PYTHON | 40000 |
| S160646 | Anusha        |   24 | c4   | c5   | C      | 60000 |
| S160619 | Uma Maheswari |   23 | c3   | c1   | OOPS   | 50000 |
| S160619 | Uma Maheswari |   23 | c3   | c2   | PYTHON | 40000 |
| S160619 | Uma Maheswari |   23 | c3   | c5   | C      | 60000 |
+---------+---------------+------+------+------+--------+-------+
10 rows in set (0.00 sec)

//Query 9:Write a query on Self join.

mysql> select C1.* from Course C1,Course C2 where C1.CFee=C2.CFee and C1.CName="OOPS";
+------+-------+-------+
| CID | CName | CFee |
+------+-------+-------+
| c1   | OOPS | 50000 |
+------+-------+-------+
1 row in set (0.00 sec)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Created the database and all the tables in phpMyadmin. In addition, write all the sql statements...
Created the database and all the tables in phpMyadmin. In addition, write all the sql statements used in perforing the tasks in a word document and submit that for grading. Lab 1: CREATE STATEMENT This statement is used to create a database or a table. CREATE DATABASE This statement is used to create a database Syntax: CREATE DATABASE database_name; OR CREATE SCHEMA database_name; Example: CREATE DATABASE Nyumbani; OR CREATE SCHEMA Nyumbani ; CREATE TABLE This SQL statement is used to...
Perform SQL queries in the given data structure. write an SQL query that gives the number...
Perform SQL queries in the given data structure. write an SQL query that gives the number of courses taken for every student in the student table. For each instructor, show the instructor name and the number of sections that have been taught by that instructor. You do not need to include instructors who have never taught a section. List in order of decreasing the number of sections taught. Give the number of semester/year combinations in which sections have been offered....
SQL allows a foreign-key dependency to refer to the same relation, as in the following example:...
SQL allows a foreign-key dependency to refer to the same relation, as in the following example: create table manager ( employee_ID char(20), Manager_ID char(20), primary key employee_ID, foreign key (manager_ID) references manager(employee_ID) on update cascade ) Here, employee_ID is a key to the table manager, meaning that each employee has at most one manager. The foreign-key clause requires that every manager also be an employee. Explain exactly what happens when a tuple in the relation manager is updated. Specify all...
Examine the Employees table. Note that the data in the Title field contains redundant values and...
Examine the Employees table. Note that the data in the Title field contains redundant values and therefore is a candidate for a one-field lookup table. Use your Access Query Design View or SQL skills to create a lookup table named Titles with the unique values in the Title field of the Employees table. List the steps you performed to create the lookup table.
SQL DATABASE Task 4 [1.5 marks] Create Index (0.5 marks) Currently, the database only contains a...
SQL DATABASE Task 4 [1.5 marks] Create Index (0.5 marks) Currently, the database only contains a small number of records. However, the data contained within it is expected to grow significantly in the future. Creating indexes on commonly searched columns is a way performance issues can be minimized. Write a command to create an index on student_name column of the student table. Create view – 1 mark Write a command to create a view to list the student ID and...
1. For the Pet Database described in the previous practical, write an SQL statement with a...
1. For the Pet Database described in the previous practical, write an SQL statement with a subquery to list all the people in the Owner table who own more than one pet. should be a collum of the total number of pets owned, owner id, first name and last name -- DROP TABLE PetAndOwner, Pet, PetType, Owner; CREATE TABLE PetType ( petTypeId VARCHAR(10) PRIMARY KEY, animalType VARCHAR(20), breed VARCHAR(20) ); CREATE TABLE Owner ( ownerId VARCHAR(10) PRIMARY KEY, firstName VARCHAR(20),...
PLEASE USE MICROSOFT SQL SERVER MANAGEMENT STUDIO 18 The purpose of this task is to create...
PLEASE USE MICROSOFT SQL SERVER MANAGEMENT STUDIO 18 The purpose of this task is to create a student table such that it has 2 partitions. One that will include all student id's through 500 and a second one that will include all student id's above 500. StudentID                   int           StudentName              varchar(30) *StudentID should be a a primary key. **StudentName should be required. Do you not use the master filegroup. Each partition should be associated with a different physical file. Use any...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment 4’s schema (Customer-Invoice-Line-Product-Vendor). Make sure that your SQL script runs without any errors. Submit your answers in a .SQL file. 1 (2 Points) - Find the count of distinctvendors thatsupplied products that are priced lowerthan 185? 2 (2 Points) - For each vendor, find their product that has the lowest product quantity. Your output should include vendor code, vendor name, product description and product...
If you had to create a new table in your database called EMPLOYEE and load data...
If you had to create a new table in your database called EMPLOYEE and load data into it using SQL commands below. CREATE TABLE EMPLOYEE (               EMP_ID INT PRIMARY KEY,               EMP_FNAME VARCHAR(200) NOT NULL,               EMP_LNAME VARCHAR(200) NOT NULL,               EMP_CITY VARCHAR(500) NULL ,               EMP_STATE VARCHAR(20) NULL ) INSERT INTO EMPLOYEE VALUE (1, ‘Kevin’, ‘Lailnay’, NULL, ‘PA’) INSERT INTO EMPLOYEE VALUE (2, ‘Sarita, ‘Kawn, ‘Princeton’,’NJ’) INSERT INTO EMPLOYEE VALUE (2, ‘Gloria, ‘Pitts, ‘Allentown, ‘PA’) INSERT INTO EMPLOYEE...
-- Table construction (just 1 simplest possible way) CREATE TABLE PetType ( petTypeId VARCHAR(10) PRIMARY KEY,...
-- Table construction (just 1 simplest possible way) CREATE TABLE PetType ( petTypeId VARCHAR(10) PRIMARY KEY, animalType VARCHAR(20), breed VARCHAR(20) ); CREATE TABLE Owner ( ownerId VARCHAR(10) PRIMARY KEY, firstName VARCHAR(20), lastName VARCHAR(20) NOT NULL, homePhoneNumber VARCHAR(20), streetAddress VARCHAR(80), suburb VARCHAR(20), postcode VARCHAR(10) ); CREATE TABLE Pet ( petId VARCHAR(10) PRIMARY KEY, petName VARCHAR(20), sex CHAR(1) CHECK (sex IN ('M', 'F')), petTypeId VARCHAR(10) FOREIGN KEY REFERENCES PetType ); CREATE TABLE PetAndOwner ( ownerId VARCHAR(10), petId VARCHAR(10), PRIMARY KEY (ownerId, petId),...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT