4 Schema Definition with SQL / DDL (II)

Total Page:16

File Type:pdf, Size:1020Kb

4 Schema Definition with SQL / DDL (II) 4.3 SQL/DDL - Constraints Different kinds of integrity constraints 4 Schema Definition with SQL / DDL (II) Important • on attributes, column constraints “ 0 <= accountValue“, “must not be NULL” 4.3 SQL/DDL – Constraints • cardinalities 4.3.1 Attribute and simple table constraints 4.3.2 Enforcing cardinality constraints and foreign keys • “semantic” constraints ("business rules") 4.3.3 Deferred constraints e.g. "The percentage of movies not older than one year must be 25% or more" 4.3.4 Assertions and triggers " After 100 loans a video tape (not DVD) has to be discarded" 4.3.5 Case study – Column constraint 4.3.6 Metadata management Specify constraint as part of column definition 4.3.7 Modifying and deleting definitions and more… – Table constraint More than one row involved, specify constraint after the column definitions HS / DBS04-06-DDL -2 2 Constraints 4.3.1 Attribute and simple table constraints Constraints may be violated when DB is changed • PRIMARY KEY (update, insert, delete) – Only once per table ð Exception – Not necessary, but omission is bad style ORA-02291: integrity constraint (SYS_C0067174) – May be column constraint (single attribute) or table violated - parent key not found constraint CREATE TABLE Tape( Constraint name (optional) t_id INTEGER PRIMARY KEY, m_id INTEGER NOT NULL, CONSTRAINT <name> <def> format CHAR(5), Advantage: error message shows violated constraint in a aquired DATE ) readable way CREATE TABLE People( ORA-02291: integrity constraint name VARCHAR(20), (FKMovieOnTape.SYS_C0067174) violated - parent birth_date DATE, ..., key not found CONSTRAINT pk PRIMARY KEY (name, birth_date) HS / DBS04-06-DDL -2 3 ) HS / DBS04-06-DDL -2 4 Not Null constraint Unique semantics • NOT NULL Strange UNIQUE semantics: Simplest constraint on attribute values, a column with more than one NULL value does column constraint not violate the UNIQUE constraint CREATE TABLE uniqueTest ( CREATE TABLE ExtraCharge ( x INTEGER UNIQUE, Simple example format CHAR(5) NOT NULL, y VARCHAR(2) extraCh DECIMAL(3,2)) ); Therefore UNIQUE INSERT INTO uniqueTest without NOT NULL VALUES (NULL,'a'); does not really make sense. • Default values SQL/DML INSERT INTO uniqueTest <attributeName> <attributeType> DEFAULT <value> statements, VALUES ( NULL,'a'); will be • UNIQUE discussed SELECT * FROM uniqueTest; later • Column contains only unique values X Y ---------- -- • Left over from SQL-89 (no primary key constraint) 1 a • Should be used for candidate keys a UNIQUE + NOT NULL =PRIMARY KEY • Column constraint or table constraint a HS / DBS04-06-DDL -2 5 HS / DBS04-06-DDL -2 6 1 CHECK clause Use of table constraints Predicates which must hold for each row General constraint syntax Enumeration: for column (except NOT NULL) and table constraints CHECK (VALUES IN (' comedy', 'entertainment', CREATE TABLE <tab> (< listOfColumnSpecs> 'suspense', 'drama', 'action', 'sci-fi')).. [[CONSTRAINT <constraintName>] Interval restriction: <constraint on columns or table>]0..n CHECK (extraCh >= 0), ) CHECK (extraCh < 10) equivalent to Constraint may be UNIQUE / PRIMARY KEY or CHECK clause CHECK (extraCh >= 0 AND extraCh < 10) or REFERENCES CREATE TABLE Customer( Multicolumn constraint: ... CREATE TABLE Accounts ( name VARCHAR(40), ... amount DECIMAL(9,2), zipcode VARCHAR(6), credit DECIMAL(7,2),..., ... , CONSTRAINT accountIsPos CONSTRAINT customerUniqueness CHECK amount + credit > 0 ) UNIQUE (name, zipcode, street, no) HS / DBS04-06-DDL -2 7 HS / DBS04-06-DDL -2 8 ) 4.3.2 Enforcing cardinality constraints Foreign keys • Constraint NOT ( m_ID IS NULL ) “Hard code" cardinality constraints in the database schema always true in example above for every row (1,1) (1,*) Movie Tape but the value of may not be among the isCopyOf ... m_Id mId values in table Movie Tape(id, acqDate,format, m_Id ) • m_ID is a foreign key in Tape table Movie(m_id, title, category, price_day, – Should exist, otherwise "missing entity" ~"dangling pointer" director, year) – "Find title of movie on tape with id=1175" would fail (1,..) ð NOT NULL constraint sufficient ? CREATE TABLE Tape ( CREATE TABLE Tape ( ..., t_id INTEGER PRIMARY KEY, movieId INTEGER NOT NULL, aquired DATE, CONSTRAINT movieExists Sufficient to enforce format CHAR(5) NOT NULL, FOREIGN KEY (movieID) REFERENCES Movie(mId) constraint only if mId INTEGER NOT NULL) foreign key ); HS / DBS04-06-DDL -2 9 HS / DBS04-06-DDL -2 10 Foreign keys Preserving referential integrity Let R be a relation with key k Important concept Referential integrity means: important fk Ì S(S) of relation S is foreign key if for all tuples sÎS Foreign key constraint holds holds: 1. The attributes of s.fk contain only NULL values or DBS has to prevent violations only values ¹ NULL – prevent execution of SQL statements which violate 2. If all attibutes of s.fk have value != NULL referential Integrity there exists a tuple rÎR and the value of s.fk is – INSERT, UPDATE, DELETE statements modify state the key of s – Update and Delete of a table may cause a violation – Violations cause an exception Tape Movie – Avoid violations by appropriate actions specified in a id format movie_id id title REFERENCES clause of the referencing table 0001 DVD 095 095 Psycho 0004 DVD 345 345 Star Wars I 0005 VHS 345 ... ... 0009 VHS 345 .... .... .... HS / DBS04-06-DDL -2 11 HS / DBS04-06-DDL -2 12 2 Preserving referential integrity Example: Referential Integrity in SQL/DDL • Actions on referenced tables: CREATE TABLE Tape( t_id INTEGER PRIMARY KEY, NOT NULL and ON DELETE CASCADE FOREIGN KEY format VARCHAR(5) NOT NULL, – delete all referenced tuples together guarantee e.g. if a movie is deleted, all tapes with this movie m_id INTEGER NOT NULL, constraint min=1 are deleted from the database CONSTRAINT tapeNotEmpty ON DELETE SET NULL FOREIGN KEY (m_id) REFERENCES Movie(m_id) ON DELETE CASCADE, ON DELETE DEFAULT CONSTRAINT formatCheck ON UPDATE CASCADE FOREIGN KEY (format) REFERENCES Format(name) – update key in referencing table ON DELETE SET DEFAULT); e.g. movie gets a new key, update value used as ON condition preserves constraint foreign key in the same way Format Tape Movie ON UPDATE SET NULL format extraCH id format movie_id id title DVD 1.00 0001 DVD 095 095 Psycho ON UPDATE SET DEFAULT VHS 0.00 0004 DVD 345 345 Star Wars I .... .... 0005 VHS 345 ... ... 0009 VHS 345 HS / DBS04-06-DDL -2 13 .... .... .... HS / DBS04-06-DDL -2 14 Example (cont.) SQL / DDL: Integrity constraints • Cardinality constraints (1,*) (1,1) Tape Movie id format movie_id id title Tape hold Movie 0001 DVD 095 095 Psycho 0004 DVD 345 345 Star Wars I 0005 VHS 345 ... ... 0009 VHS 345 .... .... .... – NOT NULL ensures min = 1 Delete from Movie CREATE TABLE Tape( Where id = 345; id INTEGER PRIMARY KEY, format CHAR(10) NOT NULL, Tape Movie m_id INTEGER NOT NULL, id format movie_id id title 0001 DVD 095 095 Psycho CONSTRAINT tapeNotEmpty .... .... .... ... ... FOREIGN KEY (m_id) REFERENCES Movie(m_id), CONSTRAINT formatCheck HS / DBS04-06-DDL -2 15 FOREIGN KEY (format) REFERENCES Format(name));HS / DBS04-06-DDL -2 16 Cardinality constraints Circular relationships born_in Example (1,*) (1,1) (0,1) (1,1) City is_mayor Person City Person id: INTEGER id: INTEGER (1,1) (0,1) is_mayor – NOT NULL ensures min = 1 • Table must be created in order to be referenced – UNIQUE ensures max= 1 • How to define “circular” constraints? – Specify constraints after table definition CREATE TABLE City( ALTER TABLE Person id INTEGER PRIMARY KEY, ADD CONSTRAINT birthPlaceReference mayor INTEGER UNIQUE NOT NULL, FOREIGN KEY (birthplace) CONSTRAINT mayorFK REFERENCES city(id); FOREIGN KEY (mayor) REFERENCES Person(id)); ALTER TABLE Person MODIFY COLUMN( birthplace NOT NULL); HS / DBS04-06-DDL -2 17 HS / DBS04-06-DDL -2 18 3 4.3.3 Deferred constraints Deferred constraints The Chicken-Egg problem Insertion violates foreign key constraint CREATE TABLE chicken(cID INT PRIMARY KEY, INSERT INTO chicken VALUES(1, 2); eID INT); CREATE TABLE egg(eID INT PRIMARY KEY, ORA-02291: integrity constraint cID INT); (chickenREFegg.SYS_C0067174) violated - parent key not found -- Example by J. Widom et al. INSERT INTO egg VALUES(2, 1); ALTER TABLE chicken ORA-02291: integrity constraint ADD CONSTRAINT chickenREFegg (eggREFchicken.SYS_C0067174) violated - parent FOREIGN KEY (eID) REFERENCES egg(eID); key not found ALTER TABLE egg Defer constraint checking ADD CONSTRAINT eggREFchicken ALTER TABLE chicken FOREIGN KEY (cID) REFERENCES chicken(cID) ; ADD CONSTRAINT chickenREFegg FOREIGN KEY (eID) REFERENCES egg(eID) What happens if an egg / chicken is inserted? INITIALLY DEFERRED DEFERRABLE; HS / DBS04-06-DDL -2 19 HS / DBS04-06-DDL -2 20 Deferred constraints and transactions Complex CHECK clauses Deferred constraints checked at the end of a transaction CHECK clause may be an arbitrary predicate Transaction: unit of work consisting of one or more operations on the DB over the DB (SQL 99) "COMMIT" closes a transaction CREATE TABLE competitors_Price(title:..., price...) INSERT INTO chicken VALUES(1, 2); CREATE TABLE movie (... -- constraint not checked here CONSTRAINT price_Limit INSERT INTO egg VALUES(2, 1); CHECK (“ At least 4 * lowest price”)) COMMIT; -- but here Variants INITIALLY DEFERRED DEFERRABLE Will be specified as SQL SELECT clause INITIALLY IMMEDIATE DEFERRABLE CHECK clause defined as a predicate over SET CONSTRAINT <name> [DEFERED|IMMEDIATE] one table only in most DBS implementations allow checking at arbitrary times HS / DBS04-06-DDL -2 21 HS / DBS04-06-DDL -2 22 4.3.4 Assertions and triggers Assertions and triggers SQL / DDL • Assertions
Recommended publications
  • Foreign(Key(Constraints(
    Foreign(Key(Constraints( ! Foreign(key:(a(rule(that(a(value(appearing(in(one(rela3on(must( appear(in(the(key(component(of(another(rela3on.( – aka(values(for(certain(a9ributes(must("make(sense."( – Po9er(example:(Every(professor(who(is(listed(as(teaching(a(course(in(the( Courses(rela3on(must(have(an(entry(in(the(Profs(rela3on.( ! How(do(we(express(such(constraints(in(rela3onal(algebra?( ! Consider(the(rela3ons(Courses(crn,(year,(name,(proflast,(…)(and( Profs(last,(first).( ! We(want(to(require(that(every(nonLNULL(value(of(proflast(in( Courses(must(be(a(valid(professor(last(name(in(Profs.( ! RA((πProfLast(Courses)((((((((⊆ π"last(Profs)( 23( Foreign(Key(Constraints(in(SQL( ! We(want(to(require(that(every(nonLNULL(value(of(proflast(in( Courses(must(be(a(valid(professor(last(name(in(Profs.( ! In(Courses,(declare(proflast(to(be(a(foreign(key.( ! CREATE&TABLE&Courses&(& &&&proflast&VARCHAR(8)&REFERENCES&Profs(last),...);& ! CREATE&TABLE&Courses&(& &&&proflast&VARCHAR(8),&...,&& &&&FOREIGN&KEY&proflast&REFERENCES&Profs(last));& 24( Requirements(for(FOREIGN(KEYs( ! If(a(rela3on(R(declares(that(some(of(its(a9ributes(refer( to(foreign(keys(in(another(rela3on(S,(then(these( a9ributes(must(be(declared(UNIQUE(or(PRIMARY(KEY(in( S.( ! Values(of(the(foreign(key(in(R(must(appear(in(the( referenced(a9ributes(of(some(tuple(in(S.( 25( Enforcing(Referen>al(Integrity( ! Three(policies(for(maintaining(referen3al(integrity.( ! Default(policy:(reject(viola3ng(modifica3ons.( ! Cascade(policy:(mimic(changes(to(the(referenced( a9ributes(at(the(foreign(key.( ! SetLNULL(policy:(set(appropriate(a9ributes(to(NULL.(
    [Show full text]
  • Referential Integrity in Sqlite
    CS 564: Database Management Systems University of Wisconsin - Madison, Fall 2017 Referential Integrity in SQLite Declaring Referential Integrity (Foreign Key) Constraints Foreign key constraints are used to check referential integrity between tables in a database. Consider, for example, the following two tables: create table Residence ( nameVARCHARPRIMARY KEY, capacityINT ); create table Student ( idINTPRIMARY KEY, firstNameVARCHAR, lastNameVARCHAR, residenceVARCHAR ); We can enforce the constraint that a Student’s residence actually exists by making Student.residence a foreign key that refers to Residence.name. SQLite lets you specify this relationship in several different ways: create table Residence ( nameVARCHARPRIMARY KEY, capacityINT ); create table Student ( idINTPRIMARY KEY, firstNameVARCHAR, lastNameVARCHAR, residenceVARCHAR, FOREIGNKEY(residence) REFERENCES Residence(name) ); or create table Residence ( nameVARCHARPRIMARY KEY, capacityINT ); create table Student ( idINTPRIMARY KEY, firstNameVARCHAR, lastNameVARCHAR, residenceVARCHAR REFERENCES Residence(name) ); or create table Residence ( nameVARCHARPRIMARY KEY, 1 capacityINT ); create table Student ( idINTPRIMARY KEY, firstNameVARCHAR, lastNameVARCHAR, residenceVARCHAR REFERENCES Residence-- Implicitly references the primary key of the Residence table. ); All three forms are valid syntax for specifying the same constraint. Constraint Enforcement There are a number of important things about how referential integrity and foreign keys are handled in SQLite: • The attribute(s) referenced by a foreign key constraint (i.e. Residence.name in the example above) must be declared UNIQUE or as the PRIMARY KEY within their table, but this requirement is checked at run-time, not when constraints are declared. For example, if Residence.name had not been declared as the PRIMARY KEY of its table (or as UNIQUE), the FOREIGN KEY declarations above would still be permitted, but inserting into the Student table would always yield an error.
    [Show full text]
  • Normalization Exercises
    DATABASE DESIGN: NORMALIZATION NOTE & EXERCISES (Up to 3NF) Tables that contain redundant data can suffer from update anomalies, which can introduce inconsistencies into a database. The rules associated with the most commonly used normal forms, namely first (1NF), second (2NF), and third (3NF). The identification of various types of update anomalies such as insertion, deletion, and modification anomalies can be found when tables that break the rules of 1NF, 2NF, and 3NF and they are likely to contain redundant data and suffer from update anomalies. Normalization is a technique for producing a set of tables with desirable properties that support the requirements of a user or company. Major aim of relational database design is to group columns into tables to minimize data redundancy and reduce file storage space required by base tables. Take a look at the following example: StdSSN StdCity StdClass OfferNo OffTerm OffYear EnrGrade CourseNo CrsDesc S1 SEATTLE JUN O1 FALL 2006 3.5 C1 DB S1 SEATTLE JUN O2 FALL 2006 3.3 C2 VB S2 BOTHELL JUN O3 SPRING 2007 3.1 C3 OO S2 BOTHELL JUN O2 FALL 2006 3.4 C2 VB The insertion anomaly: Occurs when extra data beyond the desired data must be added to the database. For example, to insert a course (CourseNo), it is necessary to know a student (StdSSN) and offering (OfferNo) because the combination of StdSSN and OfferNo is the primary key. Remember that a row cannot exist with NULL values for part of its primary key. The update anomaly: Occurs when it is necessary to change multiple rows to modify ONLY a single fact.
    [Show full text]
  • Clarion & ANSI SQL Standard Referential Integrity and Referential
    Clarion & ANSI SQL Standard Referential Integrity and Referential Actions November 12, 2018 Whitemarsh Information Systems Corporation 2008 Althea Lane Bowie, Maryland 20716 Tele: 301-249-1142 Email: [email protected] Web: www.wiscorp.com Referential Integrity and Referential Actions Fundamental Definition: Actions resulting from instruction to the database engine created in the dictionary (i.e., schema) associated with “Relationship” specifications. For SQL-engine DBMSs, these relationship-specifications and actions relate to value congruence between the value-set of a primary key’s column(s) and the value-set of a Foreign key’s column(s). When either a Update or Delete action occurs that violates the value congruence, a Referential Action occurs. The actions depend on whether the Referential Action is specified. In ANSI SQL Standards, the four referential integrity actions: No Action, Cascade, or Set Null or Set Default. In Clarion, the five referential integrity actions are: None, Restrict, Cascade, Clear, Cascade Server, ClearServer and Restrict Server. Copyright 2018, Whitemarsh Information Systems Corporation Proprietary Data, All Rights Reserved 2 Referential Integrity and Referential Actions Referential Integrity and Actions Referential Action taken when violation occurs On Update On Delete Referential Action Parent Child Parent Child Function ANSI Clarion Table Table Table Table Parent Table No equivalent None: Instructs the Primary No change Row is Nothing. Primary Key Application Generator not key in the deleted Effect is to Column value can to generate any code to column foreign key make the change. Foreign maintain referential value can value child table Key Column value integrity between any change row an does not change.
    [Show full text]
  • A Simple Database Supporting an Online Book Seller Tables About Books and Authors CREATE TABLE Book ( Isbn INTEGER, Title
    1 A simple database supporting an online book seller Tables about Books and Authors CREATE TABLE Book ( Isbn INTEGER, Title CHAR[120] NOT NULL, Synopsis CHAR[500], ListPrice CURRENCY NOT NULL, AmazonPrice CURRENCY NOT NULL, SavingsInPrice CURRENCY NOT NULL, /* redundant AveShipLag INTEGER, AveCustRating REAL, SalesRank INTEGER, CoverArt FILE, Format CHAR[4] NOT NULL, CopiesInStock INTEGER, PublisherName CHAR[120] NOT NULL, /*Remove NOT NULL if you want 0 or 1 PublicationDate DATE NOT NULL, PublisherComment CHAR[500], PublicationCommentDate DATE, PRIMARY KEY (Isbn), FOREIGN KEY (PublisherName) REFERENCES Publisher, ON DELETE NO ACTION, ON UPDATE CASCADE, CHECK (Format = ‘hard’ OR Format = ‘soft’ OR Format = ‘audi’ OR Format = ‘cd’ OR Format = ‘digital’) /* alternatively, CHECK (Format IN (‘hard’, ‘soft’, ‘audi’, ‘cd’, ‘digital’)) CHECK (AmazonPrice + SavingsInPrice = ListPrice) ) CREATE TABLE Author ( AuthorName CHAR[120], AuthorBirthDate DATE, AuthorAddress ADDRESS, AuthorBiography FILE, PRIMARY KEY (AuthorName, AuthorBirthDate) ) CREATE TABLE WrittenBy (/*Books are written by authors Isbn INTEGER, AuthorName CHAR[120], AuthorBirthDate DATE, OrderOfAuthorship INTEGER NOT NULL, AuthorComment FILE, AuthorCommentDate DATE, PRIMARY KEY (Isbn, AuthorName, AuthorBirthDate), FOREIGN KEY (Isbn) REFERENCES Book, ON DELETE CASCADE, ON UPDATE CASCADE, FOREIGN KEY (AuthorName, AuthorBirthDate) REFERENCES Author, ON DELETE CASCADE, ON UPDATE CASCADE) 1 2 CREATE TABLE Publisher ( PublisherName CHAR[120], PublisherAddress ADDRESS, PRIMARY KEY (PublisherName)
    [Show full text]
  • Relational Schema Relational Integrity
    Relational Schema Relational Integrity Unpassionate and purposeless Orlando never combine his incalculability! Infinitival Oswald signalize canonically or proceed trustingly when Piotr is leery. Orbadiah volatilizes her options bulgingly, she outwalks it amorally. Save my choice for tables can have no parent table, only on data are problems with multiple base tables may be a combination with the! Employee to radio mandatory role of Employee. DBMSs to check important data satisfies the semantics. Filing System, the dummy set add all Counties of all Countries. It does not seriously affect both tables related in relation schema designs the integrity constraints are. RFS, this sin that goes do dot use fresh unique ID to identify value object. Manual is separate horn the Product entity. Overlap constraints: Can Joe be an Hourly_Emps as through as a Contract_Emps entity? Web site which select a few attributes. Was this on helpful? It involves the relational tables that data are shown is an entity and implemented via objects are modified depending on file sharing services can! In relational schema may want to track of your session has gained wide range of moral character. There is our chance for duplication of data. An unknown error occurred. DBMSs but were originally slower. The second sentence to keep only two tables separated. Similarly, data manipulation, enabling them to shelter network traffic and unit run in disconnected mode. Eer object over any data item, delete all enrolled tuple. When there was not refundable and each table should not allowed through views reflects pdf solve mcq quiz yourself, relational integrity risk is called dno in.
    [Show full text]
  • 3 Data Definition Language (DDL)
    Database Foundations 6-3 Data Definition Language (DDL) Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Roadmap You are here Data Transaction Introduction to Structured Data Definition Manipulation Control Oracle Query Language Language Language (TCL) Application Language (DDL) (DML) Express (SQL) Restricting Sorting Data Joining Tables Retrieving Data Using Using ORDER Using JOIN Data Using WHERE BY SELECT DFo 6-3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 3 Data Definition Language (DDL) Objectives This lesson covers the following objectives: • Identify the steps needed to create database tables • Describe the purpose of the data definition language (DDL) • List the DDL operations needed to build and maintain a database's tables DFo 6-3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 4 Data Definition Language (DDL) Database Objects Object Description Table Is the basic unit of storage; consists of rows View Logically represents subsets of data from one or more tables Sequence Generates numeric values Index Improves the performance of some queries Synonym Gives an alternative name to an object DFo 6-3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 5 Data Definition Language (DDL) Naming Rules for Tables and Columns Table names and column names must: • Begin with a letter • Be 1–30 characters long • Contain only A–Z, a–z, 0–9, _, $, and # • Not duplicate the name of another object owned by the same user • Not be an Oracle server–reserved word DFo 6-3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 6 Data Definition Language (DDL) CREATE TABLE Statement • To issue a CREATE TABLE statement, you must have: – The CREATE TABLE privilege – A storage area CREATE TABLE [schema.]table (column datatype [DEFAULT expr][, ...]); • Specify in the statement: – Table name – Column name, column data type, column size – Integrity constraints (optional) – Default values (optional) DFo 6-3 Copyright © 2015, Oracle and/or its affiliates.
    [Show full text]
  • Fast Foreign-Key Detection in Microsoft SQL
    Fast Foreign-Key Detection in Microsoft SQL Server PowerPivot for Excel Zhimin Chen Vivek Narasayya Surajit Chaudhuri Microsoft Research Microsoft Research Microsoft Research [email protected] [email protected] [email protected] ABSTRACT stored in a relational database, which they can import into Excel. Microsoft SQL Server PowerPivot for Excel, or PowerPivot for Other sources of data are text files, web data feeds or in general any short, is an in-memory business intelligence (BI) engine that tabular data range imported into Excel. enables Excel users to interactively create pivot tables over large data sets imported from sources such as relational databases, text files and web data feeds. Unlike traditional pivot tables in Excel that are defined on a single table, PowerPivot allows analysis over multiple tables connected via foreign-key joins. In many cases however, these foreign-key relationships are not known a priori, and information workers are often not be sophisticated enough to define these relationships. Therefore, the ability to automatically discover foreign-key relationships in PowerPivot is valuable, if not essential. The key challenge is to perform this detection interactively and with high precision even when data sets scale to hundreds of millions of rows and the schema contains tens of tables and hundreds of columns. In this paper, we describe techniques for fast foreign-key detection in PowerPivot and experimentally evaluate its accuracy, performance and scale on both synthetic benchmarks and real-world data sets. These techniques have been incorporated into PowerPivot for Excel. Figure 1. Example of pivot table in Excel. It enables multi- dimensional analysis over a single table.
    [Show full text]
  • Databases : Lecture 1 1: Beyond ACID/Relational Databases Timothy G
    Databases : Lecture 1 1: Beyond ACID/Relational databases Timothy G. Griffin Lent Term 2015 • Rise of Web and cluster-based computing • “NoSQL” Movement • Relationships vs. Aggregates • Key-value store • XML or JSON as a data exchange language • Not all applications require ACID • CAP = Consistency, Availability, and Partition tolerance • The CAP theorem (pick any two?) • Eventual consistency Apologies to Martin Fowler (“NoSQL Distilled”) Application-specific databases have always been with us . Two that I am familiar with: Daytona (AT&T): “Daytona is a data management system, not a database”. Built on top of the unix file system, this toolkit is for building application-specific But these systems and highly scalable data stores. Is used at AT&T are proprietary. for analysis of 100s of terabytes of call records. http://www2.research.att.com/~daytona/ Open source is a hallmark of NoSQL DataBlitz (Bell Labs, 1995) : Main-memory database system designed for embedded systems such as telecommunication switches. Optimized for simple key-driven queries. What’s new? Internet scale, cluster computing, open source . Something big is happening in the land of databases The Internet + cluster computing + open source systems many more points in the database design space are being explored and deployed Broader context helps clarify the strengths and weaknesses of the standard relational/ACID approach. http://nosql-database.org/ Eric Brewer’s PODC Keynote (July 2000) ACID vs. BASE (Basically Available, Soft-state, Eventually consistent) ACID BASE • Strong consistency Weak consistency • Isolation Availability first • Focus on “commit” Best effort • Nested transactions Approximate answers OK • Availability? Aggressive (optimistic) • Conservative (pessimistic) Simpler! • Difficult evolution (e.g.
    [Show full text]
  • CSC 443 – Database Management Systems Data and Its Structure
    CSC 443 – Database Management Systems Lecture 3 –The Relational Data Model Data and Its Structure • Data is actually stored as bits, but it is difficult to work with data at this level. • It is convenient to view data at different levels of abstraction . • Schema : Description of data at some abstraction level. Each level has its own schema. • We will be concerned with three schemas: physical , conceptual , and external . 1 Physical Data Level • Physical schema describes details of how data is stored: tracks, cylinders, indices etc. • Early applications worked at this level – explicitly dealt with details. • Problem: Routines were hard-coded to deal with physical representation. – Changes to data structure difficult to make. – Application code becomes complex since it must deal with details. – Rapid implementation of new features impossible. Conceptual Data Level • Hides details. – In the relational model, the conceptual schema presents data as a set of tables. • DBMS maps from conceptual to physical schema automatically. • Physical schema can be changed without changing application: – DBMS would change mapping from conceptual to physical transparently – This property is referred to as physical data independence 2 Conceptual Data Level (con’t) External Data Level • In the relational model, the external schema also presents data as a set of relations. • An external schema specifies a view of the data in terms of the conceptual level. It is tailored to the needs of a particular category of users. – Portions of stored data should not be seen by some users. • Students should not see their files in full. • Faculty should not see billing data. – Information that can be derived from stored data might be viewed as if it were stored.
    [Show full text]
  • Foreign Keys
    IT360: Applied Database Systems From Entity-Relational Model To Relational Model Chapter 6, 7 in Kroenke 1 Database Design Process . Requirements analysis . Conceptual design: Entity-Relationship Model . Logical design: transform ER model into relational schema . Schema refinement: Normalization . Physical tuning 2 1 Goals . Transform ER model to relational model . Write SQL statements to create tables 3 Relational Database . A relation is a two-dimensional table . Relation schema describes the structure for the table . Relation name . Column names . Column types . A relational database is a set of relations 4 2 ER to Relational . Transform entities in tables . Transform relationships using foreign keys . Specify logic for enforcing minimum cardinalities 5 Create a Table for Each Entity . CREATE TABLE statement is used for creating relations/tables . Each column is described with three parts: . column name . data type . optional constraints 6 3 Specify Data Types . Choose the most specific data type possible!!! . Generic Data Types: . CHAR(n) CREATE TABLE EMPLOYEE ( . VARCHAR(n) EmployeeNumber integer, . DATE EmployeeName char(50), . TIME Phone char(15), . MONEY Email char(50), . INTEGER . DECIMAL HireDate date, ReviewDate date ) 7 Specify Null Status . Null status: CREATE TABLE EMPLOYEE ( whether or not EmployeeNumber integer NOT the value of the NULL, column can be EmployeeName char (50) NOT NULL, NULL Phone char (15) NULL, Email char(50) NULL, HireDate date NOT NULL, ReviewDate date NULL ) 8 4 Specify Default Values . Default value - value supplied by the DBMS, if no value is specified when a row is inserted CREATE TABLE EMPLOYEE ( Syntax/support depends on DBMS EmployeeNumber integer NOT NULL, EmployeeName char (50) NOT NULL, Phone char (15) NULL, Email char(50) NULL, HireDate date NOT NULL DEFAULT (getdate()), ReviewDate date NULL ) 9 Specify Other Data Constraints .
    [Show full text]
  • March 2017 Report
    BCS THE CHARTERED INSTITUTE FOR IT BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 6 Professional Graduate Diploma in IT ADVANCED DATABASE MANAGEMENT SYSTEMS March 2017 Answer any THREE questions out of FIVE. All questions carry equal marks. Time: THREE hours Answer any Section A questions you attempt in Answer Book A Answer any Section B questions you attempt in Answer Book B The marks given in brackets are indicative of the weight given to each part of the question. Calculators are NOT allowed in this examination. Section A Answer Section A questions in Answer Book A A1 Examiner's General Comments This was a fairly popular question, attempted by around half of the candidates, with two-thirds of the attempts achieving pass level marks. Therefore, the performance was generally quite good with a wide range of marks, some candidates producing near correct solutions. The definition of a true distributed database system is that it consists of a collection of geographically remote sites of physical databases, connected together via some kind of communication network, in which a user at any site can access data anywhere in the network exactly as if the data were all stored in one single database at the user’s own site. a) Explain the problems associated with achieving a true distributed database in practice. 12 marks ANSWER POINTER Fragmentation of tables requires maintenance of unique keys across horizontal fragments and consistency of primary keys that are reflected in vertical fragments. Also increased network traffic occurs as many fragments may need to be consulted to perform one query.
    [Show full text]