You are on page 1of 2

ACID principle: Atomic, Consistent, Isolated, Durable Aggregation: allows us to treat a relationship set as an entity set for purposes

of participation in (other) relationships Attribute: a property or description of an entity. Candidate key: A minimal superkey that does not contain a subset of attributes that is itself a superkey Cardinality: number of rows Concurrency Control: important to keep the CPU humming by working on several user programs concurrently. Interleaving actions of different user programs can lead to inconsistency, DBMS ensures such problems dont arise. Covering Constraint: within an ISA hierarchy, determines where the entities in the subclasses collectively include all entities in the superclass. Data Independence: Applications insulated from how data is structured and stored. Data Integrity: Make sure your data can be trusted, avoid unnecessary duplication, ensure only correct value. Data Security: Avoid unauthorized access, protect the security and privacy of your data, access rights maintained by DBA Data model: a collection of concepts for describing data Database: A very large integrated collection of data, models real world enterprise Database Administrator (DBA): They perform the following tasks: (1) Access control and monitoring, (2) Performance tuning, (3) Disk space management, (4) Concurrency control, (5) Designs logical /physical schemas, (6) Data availability, crash recovery Database Management System (DBMS): the software package designed to store and manage databases. It provides the following functions: (1) Uniform data administration, (2) Reduced application development time, (3) Data independence, (4) Efficient access, (5) Data integrity and security, (6) Concurrent access, recovery from crashes, (7) Web-based access and distribution. Designing a database : (1) Get requirements and data, (2) Create Conceptual model (EER diagram), (3) Create Logical model (Relational model), (4) Implement logical model (tables), (5) Import data, (6) Query data SQL to create Reports Descriptive Attributes: used to record information about a relationship. Degree (Arity) : Number of fields Domain (Data Type): a set of possible values for an attribute, columns in table Distinct: an optional keyword indicating that the answer should not contain duplicates. Default is that duplicates are not eliminated! Entity: Realworld object distinguishable from other objects. An entity is described using a set of attributes Entity Set: A collection of similar entities Foreign key: An attribute or combination of attributes in one table whose value must either (a) match the primary key in another table, or (b) be null (contain no value, i.e. empty) Foreign key: Set of fields in one relation that is used to `refer to a tuple in another relation. (Must correspond to primary key of the second relation.) Like a `logical pointer. If all foreign key constraints are enforced, referential integrity is achieved. Indirect attack: Infer results based on one or more query Instance: a set of relationships Integrity Constraints (IC): condition that must be true for any instance of the database, specified when schema is defined, checked when relations are modified Key Constraint: each entity is appears in at most one realtionship Key/Entity integrity: No null entries in a primary key, all entries are unique. Purpose: Each row or tuple has a unique identity

Log: keeps all information about a transaction (Old value, new value, commit or abort). Also ensures redo and undo capabilities Logical data independence: Protection from changes in logical structure of data Many-to-many relationship: a key constraint that indicates that many of one relationship can be associated with many of another entity. Nested Queries: A WHERE, FROM or HAVING clause can itself contain an SQL query. One-to-many relationship: a key constraint that indicates that one entity can be associated with many of another entity Overlap constraint: within an ISA hierarchy, an overlap constraint determines whether or not two subclasses can contain the same entity. Partial Participation Constraints: Every entity in the total set E1 does not need to be related to another in the entity E2 Participation constraint: a participation constraint determines whether relationships must involve certain entities. Physical data independence: Protection from changes in physical structure of data Primary key: A candidate key selected to uniquely identify all other attribute values in a given row. No nulls allowed. Qualification: Comparisons (Attr op const or Attr1 op Attr2, where op is one of <,>,=,) combined using AND, OR and NOT. Query languages: Allow manipulation and retrieval of data from a database Reduced development time: using structured query language gives or fast ad hoc queries Referential integrity: Foreign key either empty (null value) or value matches the primary key of related table. Purpose: Impossible for attribute to have an invalid entry. Possible for attribute to have no value Relation: a table with rows and columns. Each relation has a schema. Relation-list: A list of relation names (possibly with a range-variable after each name). Relationship: Association among two or more entities Relationship Set: Collection of similar relationships Role Indicator: if an entity set plays more than one role, role indicators describe the different purpose in the relationship. Schema: a description of a particular collection of data, using the a given data model, defined using DDL Secondary key: An attribute or combination of attributes used strictly for data-retrieval purposes Security mechanism: allows us to enforce a chosen security policy. Two main types, discretionary or mandatory access control. Security policy: specifies who is authorized to do what Security Solutions: Suppress obvious sensitive information, authenticate your users, track what the user knows, disguise data Security Tasks of the DBA : Grant, revoke access rights to users or group of users, ensure transparent security, identify intrusion attempts, define a plan, manage high risk statistical queries Superkey: An attribute or combination of attributes that uniquely identifies each entity in a table Target-list: A list of attributes of relations in relation-list Total Participation Constraints: Every entity in the total set E1 must be related to another in the entity E2 Transaction: An atomic sequence of database actions (reads/writes). View: just a relation, but we store a definition, rather than a set of tuples Weak Entity: an entity that cannot be identified uniquely without considering some primary key attributes of another identifying owner entity.

DROP TABLE Students Destroys the relation Students. The schema information and the tuples are deleted. ALTER TABLE Students ADD COLUMN firstYear: integer The schema of Students is altered by adding a new field; every tuple in the current instance is extended with a null value in the new field INSERT INTO Students (sid, name, login, gpa) VALUES (53688, Smith, smith@ee, 18, 3.2) Inserts the tuple DELETE FROM Students S WHERE S.name = Smith Can delete all tuples satisfying some condition Referential integrity options Default is NO ACTION or RESTRICT (delete/update is rejected) CASCADE (also delete all tuples that refer to deleted tuple) SET NULL / SET DEFAULT (sets foreign key value of referencing tuple) Creating a table for entity:

Tables for weak entities:

CREATE TABLE Dep_Policy ( pname CHAR(20), age INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (pname, ssn), FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE CASCADE Tables for ISA hierarchies: Approach one: Have 3 relations: Hourly_Emps: Every employee is recorded in Employees. For h_emps, extra info recorded. Delete H_Emps tuple if referenced Employees tuple is deleted). Queries involving all employees easy, those involving just Hourly_Emps require a join to get some attribute. This approach will always work. Approach Two: Just Hourly_Emps and Contract_Emps. Subclasses must be total or disjoint CREATE VIEW YoungStudents (name, grade) AS SELECT S.name, E.grade FROM Students S, Enrolled E WHERE S.sid = E.sid and S.age<2 This is used to present necessary information, while hiding details in underlying relation(s). SQL SELECT Query Keywords: FROM which tables WHERE which rows HAVING identify combined rows GROUP BY combine rows with related values ORDER BY sorting the data AS and = are two ways to name fields in result. LIKE is used for string matching. `_ stands for any one character and `% stands for 0 or more arbitrary characters. SELECT S.sname FROM Sailors S, Reserves R WHERE S.sid=R.sid AND R.bid=10 Give the names of the Sailors who reserved boat with bid = 103 Set operations: UNION, EXCEPT, INTERSECTION, IN, UNIQUE, EXISTS, NOT EXISTS, NOT IN, NOT UNIQUE SELECT S.sid FROM Sailors S, Boats B, Reserves R WHERE S.sid=R.sid AND R.bid=B.bid AND (B.color=red OR B.color=green) Find sids of sailors whove reserved a red or a green boat SELECT * FROM Sailors S WHERE S.rating > ANY (SELECT S2.rating FROM Sailors S2 WHERE S2.sname=Horatio) Find sailors whose rating is greater than that of some sailor called Horatio

SELECT S.sid FROM Sailors S, Boats B, Reserves R WHERE S.sid=R.sid AND R.bid=B.bid AND B.color=red AND S.sid IN (SELECT S2.sid FROM Sailors S2, Boats B2, Reserves R2 WHERE S2.sid=R2.sid AND R2.bid=B2.bid AND B2.color=green) Find sids of sailors whove reserved both a red and a green boat SELECT S.sname FROM Sailors S WHERE NOT EXISTS ((SELECT B.bid FROM Boats B) EXCEPT (SELECT R.bid FROM Reserves R WHERE R.sid=S.sid) Find sailors whove reserved all boats Aggregation: COUNT (*), COUNT ( [DISTINCT] A), SUM ( [DISTINCT] A), AVG ( [DISTINCT] A), MAX (A), MIN (A) Aggregate operations cannot be nested. SELECT S.sname, S.age FROM Sailors S WHERE S.age = (SELECT MAX (S2.age) FROM Sailors S2 Find name and age of the oldest sailor(s) SELECT MIN (S.age) FROM Sailors S GROUP BY S.rating Find the age of the youngest sailor for each rating level SELECT S.rating, MIN (S.age) FROM Sailors S WHERE S.age >= 18 GROUP BY S.rating HAVING COUNT (*) > 1 Find the age of the youngest sailor with >= age 18, for each rating with at least 2 such sailor SELECT Temp.rating, Temp.avgage FROM (SELECT S.rating, AVG (S.age) AS avgage FROM Sailors S GROUP BY S.rating) AS Temp WHERE Temp.avgage = (SELECT MIN (Temp.avgage) FROM Temp Find those ratings for which the average age is the minimum overall ratings SELECT C.Country, C.date-of-issue FROM Catalog C WHERE (SELECT count(*) FROM Stamp S WHERE S.CatalogID = C.CatalogID) >= 5; Displays the countries and date of issues of all catalogs that contain more than 4 stamp

CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot INTEGER, PRIMARY KEY (ssn)) Creating a table for relationship (M to N):

CREATE TABLE Works_In( ssn CHAR(1), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments) Creating a table for relationship(1 to M):

CREATE TABLE Manages( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments

You might also like