Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CCC151 first semester reviewer, Study notes of Programming Languages

CCC151 first semester reviewer

Typology: Study notes

2019/2020

Uploaded on 09/21/2021

j-danielle-diana
j-danielle-diana 🇵🇭

5 documents

Partial preview of the text

Download CCC151 first semester reviewer and more Study notes Programming Languages in PDF only on Docsity! Database Management Systems (DBMSs) Database e isacollection of data stored in a format that can be easily accessed. e Databases are crucial for daily operations and decision making in organizations. Daily Operations DATABASE Database Management System/s e are the enabling tools to create and utilize databases in an organization. o Major part of software industry o Revolutionary evolvement over 40 years o Foundation for management of long term memory of Organizations Relational Data Model Document Data Model Pros > Easy to use and setup. de) aoe cs ales (oo > Universal, compatible with many tools. > Rapid development cycles. >» Good at high-performance workloads. ane a ei cm elem > Good at structure data. So ean a Ret Te) CONS >» Time consuming to understand and ‘CONS > Unsuited for interconnected data design the structure of the database. > Technology still maturing. >» Can be difficult to scale. > Can have slower response time. Relational Database Management System a SOL Server MySQus oY ORACLE PostgreSQL MySQL e isan open-source relational database management system (RDBMS). e Its name is a combination of "My", the name of co-founder Michael Widenius's daughter, and "SQL", the abbreviation for Structured Query Language. Structured Query Language (SQL) e isa language designed entirely for accessing and manipulating databases. e with SQL, we can create tables, change data, get back to the data we are interested in Constraint Syntax Example CONSTRAINT PKCourse PRIMARY KEY (CourseNo) CONSTRAINT FKOfferNo FOREIGN KEY (OfferNo) REFERENCES Offering CONSTRAINT OffCourseNoReq NOT NULL CREATE TABLE Course ( CourseNo CHAR (6), CrsDesc VARCHAR (250), CrsUnits SMALLINT, CONSTRAINT PKCourse PRIMARY KEY (CourseNo), CONSTRAINT UniqueCrsDesc UNIQUE (CrsDesc) ) CREATE TABLE Enrollment ( OfferNo INTEGER, StdNo CHAR (11), EnrGrade DECIMAL (3,2), CONSTRAINT PKEnroliment PRIMARY KEY (OfferNo, StdNo), CONSTRAINT FKOfferNo FOREIGN KEY (OfferNo) REFERENCES Offering, CONSTRAINT FKStdNo FOREIGN KEY (StdNo) REFERENCES Student ) CREATE TABLE Offering ( OfferNo INTEGER, CourseNo CHAR (6) CONSTRAINT OffCourseNoReq NOT NULL, OffLocation VARCHAR (50), OffDays CHAR (6), Offferm CHAR (6) CONSTRAINT OfffermReq NOT NULL, OffYear INTEGER CONSTRAINT OffYearReq NOT NULL, FacNo CHAR (11), Offfime DATE, CONSTRAINT PKOffering PRIMARY KEY (OfferNo), CONSTRAINT FKCourseNo FOREIGN KEY (CourseNo) REFERENCES Course, CONSTRAINT FKFacNo FOREIGN KEY (FacNo) REFERENCES Faculty ) CONSTRAINT ValidGPA CHECK ( StdGPA BETWEEN O AND 4 ) CONSTRAINT ValidStdClass CHECK ( StdClass IN ( 'FR’, ‘SO’, ‘JR’, ‘SR’ ) CONSTRAINT OffYearValid CHECK ( OffYear > 1970) CONSTRAINT EnrollDropValid CHECK ( EnrollDate < DropDate ) Query Formulation with SQL Structured Query Language (SQL) e isa language designed entirely for accessing and manipulating databases. ° 00000000 ° SQL can execute queries against a database SQL can retrieve data from a database SQL can insert records in a database SQL can update records in a database SQL can delete records from a database SQL can create new databases SQL can create new tables in a database SQL can create stored procedures in a database SQL can create views in a database SQL can set permissions on tables, procedures, and views Using SQL in Your Web Site / System To build a website that shows data from a database, you will need: e An RDBMS database program (i.e. MS Access, SQL Server, MySQL) e Touse a server-side scripting language, like PHP or ASP e Touse SQL to get the data you want e Touse HTML/CSS to style the page SELECT Statement e The SELECT statement is used to select data from a database. e The data returned is stored in a result table, called the result-set. SELECT Syntax: SELECT column1, columnd2, ... FROM table_name; Use to select all the fields available in the table: SELECT * FROM table_name; Mixing AND and OR Example SELECT OfferNo, CourseNo, FacNo FROM Offering WHERE (OffTerm = 'FALL' AND OffYear = 2016) OR (Offferm = 'WINTER' AND OffYear = 2017); GROUP BY Keyword e The GROUP BY statement groups rows that have the same values into summary tows, like "find the number of customers in each country". e The GROUP BY statement is often used with aggregate functions (COUNT(), MAX(), MINQ, SUMQ, AVG() to group the result-set by one or more columns. SELECT COUNT (CustomerID), Country FROM Customers GROUP BY Country; SELECT COUNT (CustomerID), Country FROM Customers GROUP BY Country ORDER BY COUNT(CustomerID) DESC; INSERT INTO Statement e The INSERT INTO statement is used to insert new records in a table. INSERT INTO table_name (column1, column2, column, ...) VALUES (value, value2, value3, ...): INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal’, 'Tom B. Erichsen’, 'Skagen 21', 'Stavanger', '4006'", 'Norway’): Normalization of Database e Database Normalization is a technique of organizing the data in the database. Normalization is a systematic approach of decomposing tables to eliminate data redundancy(repetition) and undesirable characteristics like Insertion, Update and Deletion Anomalies. It is a multi-step process that puts data into tabular form, removing duplicated data from the relation tables. Normalization is used for mainly two purposes, e Eliminating redundant(useless) data. e Ensuring data dependencies make sense i.e data is logically stored. Problems Without Normalization If a table is not properly normalized and has data redundancy then it will not only eat up extra memory space but will also make it difficult to handle and update the database, without facing data loss. Insertion, Updation and Deletion Anomalies are very frequent if the database is not normalized. To understand these anomalies let us take an example of a Student table. rollno name branch hod office_tel 401 Akon CSE Mr. X 53337 402 Bkon CSE Mr. X 53337 403 Ckon CSE Mr. X 53337 404 Dkon CSE Mr. X 53337 In the table above, we have data of 4 Computer Sci. students. As we can see, data for the fields branch, hod(Head of Department) and office_tel is repeated for the students who are in the same branch in the college, this is Data Redundancy. Insertion Anomaly Suppose for a new admission, until and unless a student opts for a branch, data of the student cannot be inserted, or else we will have to set the branch information as NULL. Also, if we have to insert data of 100 students of the same branch, then the branch information will be repeated for all those 100 students. These scenarios are nothing but Insertion anomalies. Updation Anomaly What if Mr. X leaves the college? or is no longer the HOD of the computer science department? In that case all the student records will have to be updated, and if by mistake we miss any record, it will lead to data inconsistency. This is an Updation anomaly. Deletion Anomaly In our Student table, two different pieces of information are kept together, Student information and Branch information. Hence, at the end of the academic year, if student records are deleted, we will also lose the branch information. This is Deletion anomaly. Normalization Rule Normalization rules are divided into the following normal forms: First Normal Form Second Normal Form Third Normal Form BCNF 5. Fourth Normal Form First Normal Form (41NF) For a table to be in the First Normal Form, it should follow the following 4 rules: 1. It should only have single(atomic) valued attributes/columns. 2. Values stored in a column should be of the same domain 3. All the columns in a table should have unique names. 4. And the order in which data is stored, does not matter. Second Normal Form (2NF) For a table to be in the Second Normal Form, 1. It should be in the First Normal form. 2. And, it should not have Partial Dependency Third Normal Form (3NF) A table is said to be in the Third Normal Form when, 1. It is in the Second Normal form. 2. And, it doesn't have Transitive Dependency. Boyce and Codd Normal Form (BCNF) The Boyce and Codd Normal Form is a higher version of the Third Normal form. This form deals with a certain type of anomaly that is not handled by 3NF. A 3NF table which does not have multiple overlapping candidate keys is said to be in BCNF. For a table to be in BCKF, following conditions must be satisfied: 1. R must be in 3rd Normal Form 2. and, for each functional dependency ( X — Y ), X should be a super Key. Fourth Normal Form (4NF) A table is said to be in the Fourth Normal Form when, 1. Itis in the Boyce-Codd Normal Form. 2. And, it doesn't have Multi-Valued Dependency. RWONS structures the data in a way that eliminates unnecessary duplication(s) and provides a rapid search path to all necessary information. e Normalisation will reduce the amount of space a database uses and ensure that data is efficiently stored. Without normalisation, database systems can be inaccurate, slow, and inefficient. Normalization Rules: e 1st Normal Form (1NF) 2nd Normal Form (2NF) 3rd Normal Form (3NF) Boyce-Codd Normal Form (BCNF) Ath Normal Form (4NF) 1st Normal Form e Single Valued Attributes e Entries in a column should have the same type e Unique name for Attributes/Columns e Order doesn't matters Cust Name Item Shipping Address Newsletter Supplier [Supplier Phone Price Alan Smith Xbox One 35 Palm St, Miami Xbox News Microsoft (800) BUY-KBOX 250 Roger Banks PlayStation 4 ‘47 Campus Rd, Boston PlayStation News ‘Sony (800) BUY-SONY ‘300 Evan Wilson Xbox One, PS Vita 28 Rock Av, Denver __| Xbox News, PlayStation News Wholesale Toll Free 450 Alan Smith PlayStation 4 47 Campus Rd, Boston PlayStation News: Sony (800) BUY-SONY 300 Primary Key Cust Name item Shipping Address Newsletter Supplier [Supplier Phone] Price Alan Smith Xbox One 35 Palm St, Miami Xbox News: Microsoft (800) BUY-XBOX. 250 PlayStation 4 47 Campus Rd, Boston PlayStation News Sony (800) BUY-SONY 300 Xbox One 28 Rock Av, Denver Xbox News: Microsoft (800) BUY-XBOX. 250 PS Vita 28 Rock Av, Denver PlayStation News Sony (800) BUY-SONY 200 Alan Smith PlayStation 4 47 Campus Rd, Boston PlayStation News Sony (800) BUY-SONY. 300 2nd Normal Form e The table should be in the First Normal Form. e No non-prime attribute is dependent on the proper subset of any candidate key of the table. Primary Key Cust Name Item Shipping Address Newsletter Supplier [Supplier Phone| Price ‘Alan Smith ‘Xbox One, 35 Palm St, Miami ‘Xbox News: Microsoft | (800) BUY-XBOX 250 Roger Banks PlayStation 4 | 47 Campus Rd, Boston Playstation News Sony (800) BUY-SONY. 300 Evan Wilson Xbox One 28 Rock Av, Denver Xbox News: Microsoft (800) BUY-XBOX_ 250, Evan Wilson PS Vita 28 Rock Av, Denver PlayStation News: Sony (800) BUY-SONY. 200, Alan Smith PlayStation 4 47 Campus Rd, Boston PlayStation News: Sony (800) BUY-SONY 300 Primary Key Cust Name | Shipping Address Newsletter ‘Alan Smith | _ 35 Palm St, Miami Xbox News Roger Banks 47 Campus Rd, Boston PlayStation News Evan Wilson | _28 Rock Av, Denver ‘Xbox News Evan Wilson 28 Rock Av, Denver PlayStation News: ‘Alan Smith | 47 Campus Rd, Boston | PlayStation News 3rd Normal Form Primary Key Primary Key e The table should be in the 2nd Normal Form. e Transitive functional dependency of non-prime attributes on any super key should be removed. Primary Key Cust Name | Shipping Address Newsletter ‘Alan Smith | 35 Palm St, Miami Xbox News Roger Banks 47 Campus Rd, Boston PlayStation News: Evan Witson | 28 Rock Av, Denver ‘Xbox News Evan Wilson 28 Rock Av, Denver PlayStation News: Alan Smith 47 Campus Rd, Boston PlayStation News. Primary Key Primary Key CustName | Shipping Address Newsletter Alan Smith 35 Palm St, Miami Xbox News Roger Banks: 47 Campus Rd, Boston PlayStation News: Evan Wilson 28 Rock Av, Denver Xbox News: Evan Wilson 28 Rock Av, Denver PlayStation News. Alan Smith 47 Campus Rd, Boston PlayStation News: Primary Key Primary Key Phone (800) BUY-KBOX (800) BUY.SONY Boyce-Codd Normal Form (BCNF) e It should be in the Third Normal Form. e And, for any dependency A — B, Ashould be a super key. e In simple words, it means that for a dependency A — B, A cannot be a non-prime attribute, if B is a prime attribute. student id subject 101 Java 101 Cr+ 102 Java 103 C# 104 Java Student Table student_id 101 101 and so on... And, Professor Table pid professor 1 PJava 2 P.Cpp professor PJava P.Cpp PJava2 P.Chash PJava p_id subject Java C++
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved