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

normalization-simple queries

The document outlines the process of database normalization, detailing various normal forms (1NF, 2NF, 3NF, BCNF) and their conditions to reduce redundancy and improve data integrity. It also explains SQL commands such as SELECT, DISTINCT, WHERE, LIMIT, and GROUP BY, along with their usage in querying and managing data. Additionally, it discusses anomalies that can occur in databases and the importance of functional dependencies.

Uploaded by

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

normalization-simple queries

The document outlines the process of database normalization, detailing various normal forms (1NF, 2NF, 3NF, BCNF) and their conditions to reduce redundancy and improve data integrity. It also explains SQL commands such as SELECT, DISTINCT, WHERE, LIMIT, and GROUP BY, along with their usage in querying and managing data. Additionally, it discusses anomalies that can occur in databases and the importance of functional dependencies.

Uploaded by

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

Normalization is the process for assigning attributes to The DISTINCT clause is used in the SELECT statem

entities. Reduces data redundancy- Improves data to remove duplicate rows from a result set.
integrity-Simplifies database maintenance- Enhances SELECT DISTINCT column_1
query performance. FROM table_name;

1NF- is a table in which the intersection of every column


and record contains only one value. The conditions are used to filter the rows returned fr
2NF- A table is in 2NF if each non-key (non primary the SELECT statement. (=,>,<,>=,<=, <> or !. no
and/or candidate keys) column depends on ALL candidate equal, AND, OR)
keys, NOT on a subset of ANY candidate key.>Remove SELECT column_1, column_2 … column_n
partial dependencies- Every non-key attribute should be FROM table_name
fully dependent on the primary key. WHERE conditions;
3NF- is a table that is in 1NF and 2NF and in which no
non-primarykey column is transitively dependent on the LIMIT is used in the SELECT statement to get a subs
primary key. >Remove transitive dependencies- Non-key rows returned by the query.
attributes should depend only on the primary key. SELECT *
BCNF- A table is in Boyce-Codd Normal Form (BCNF) FROM TABLE
when it is in 3NF and every determinant in the table is a LIMIT n;
candidate key. For example, if the table is in 3NF and it returns n number of rows generated by the query.
contains a nonprime attribute that determines a prime zero
attribute, the BCNF requirements are not met. > If a table or NULL, it produces the result that is same as omitt
is in 3NF and it contains only one candidate key, 3NF and the
BCNF are equivalent. > BCNF can be violated only if the LIMIT clause.
table contains more than one candidate key.
SELECT *
1nf.ex- A table with multiple phone numbers per FROM table
customer is not in 1NF. It should be split into separate LIMIT n OFFSET m;
rows or a related table. First skips m rows before returning n row generated
2nf.ex- A table where a non-key column depends only on the
part of a composite key should be split to remove partial query.
dependencies.
3nf.ex- If a table has columns where a non-key column The IN operator is used in the WHERE clause to chec
depends on another non-key column, it needs to be split. value matches any value in a list.
1 value IN (value1, value2, ...);
BCNF.ex- A table where a non-primary key column
determines another column should be split. The ORDER BY clause allows sorting rows returned
FD- A relationship where one attribute uniquely the SELECT statement in ascending or descending or
determines another. PD- when a non-key attribute 1 SELECT column_1, column_2
depends on part of a composite key. Must be removed in 2 FROM table_name
2NF. 3 ORDER BY column_1 ASC, column_2 DESC
Adv.- Reduces redundancy-Improves consistency-Makes
database updates easier. Disad- ore complex queries- The BETWEEN operator is used to match a value ag
Additional table joins- Potential performance issues. a
range of values.
The insertion anomaly: Occurs when extra data beyond 1 value BETWEEN low AND high;
the desired data must be added to the database. The
update anomaly: Occurs when it is necessary to change The LIKE operator is used to find rows that match a
multiple rows to modify ONLY a single fact. The deletion pattern.
anomaly: Occurs whenever deleting a row inadvertently 1 SELECT column_1
causes other data to be deleted. 2 FROM table_name
Transitive D- consider a table with columns A, B, and C. 3 WHERE column_1 LIKE 'pattern%';
If B is functionally dependent on A (A → B) and C is Percent ( % ) for matching any sequence of charact
functionally dependent on B (B →C), then C is transitively Underscore ( _ ) for matching any single character.
dependent on A via B (provided that A is not functionally
dependent on B or C). The GROUP BY clause divides rows returned from
theSELECT statement into groups to apply aggregate
SELECT statement to query data from a table functions.
SELECT column_1, column_2, 1 SELECT column_1, aggregate_function(column_2)
FROM table_name 2 FROM table_name
3 GROUP BY column_1;
The HAVING clause filters group rows that do not satisfy
a
specified condition.
1 SELECT column_1, aggregate_function(column_2)
2 FROM table_name
3 GROUP BY column_1
4 HAVING condition;

The CREATE TABLE statement is used to create a new


table
in PostgreSQL.
1 CREATE TABLE table_name (
2 column_name TYPE column_constraint,
3 table_constraint
4 );

You might also like