Week 3 – CST– 363 Introduction to Database Systems

1.      Someone described normalization rule as “a non-key column depends on the key, the whole key, and nothing but the key, so help me Codd.” Key refers to a primary or other candidate key of a table. If the key has multiple columns, then “whole key” means all columns together and not just some part of the key. Explain, in your own words, what 3rd normal form is and why it is important.

 The 3rd normal form is a rule used to design tables that eliminate redundancy. Redundancy is the repetition of related values in a table. When a table is in 3rd normal form, all the non-key columns depend on the key only. In case of a composite key, non-key columns must depend on all of the columns that make up the primary key. This is important because when non-key values depend on other non-key values it causes redundancies. Redundancies in a database can cause problems because all related values must be changed when updating, which makes queries take longer. There is also a higher chance of copies becoming inconsistent which makes it difficult to tell which version is correct.

 

2.      What is an SQL view? How is it similar to a table? In what ways is it different?

A view in SQL refers to a view table. The view table is made using a SELECT statement called the view query.

CREATE VIEW ViewName  AS

SELECT column1, column 2, …

FROM table_name

WHERE condition;

A view restructures table columns and data types without changing the underlying database design. We would use a view table when we want to omit personal data from a table or save complex queries for reference without having to write the select statement multiple times.

They are similar to a result table in that you can generate the equivalent result table with a select statement. You can save the optimal select statement as a view to ensure fast execution.

A difference of views from tables is that using INSERT, UPDATE, and DELETE statements with views is problematic.

When trying to insert, if the primary key does not appear in the view, then insert will fail. When updating, if you are using aggregate functions, aggregate values correspond to many base table values. If you create a new aggregate value in the view table, this value must be converted to many base table values and the conversion will be undefined and therefore the update will not be allowed.

When deleting, if you have a join view, you might delete a primary key row, foreign key row, or both. This will make the delete undefined and not allowed.

 


Comments

Popular posts from this blog