Goals Relational Query Languages SQL DDL and DML Creating Tables

Total Page:16

File Type:pdf, Size:1020Kb

Goals Relational Query Languages SQL DDL and DML Creating Tables Goals IT420: Database Management and SQL: Data Definition Language Organization CREATE ALTER DROP SQL: Data Manipulation Language SQL: Structured Query INSERT Language DELETE (Chapter 7) UPDATE SELECT 1 2 Relational Query Languages SQL DDL and DML A major strength of the relational model: SQL statements can be divided into two supports simple, powerful querying of data categories: Data definition language (DDL) statements Queries can be written intuitively, and the Used for creating and modifying tables, views, and DBMS is responsible for efficient other structures evaluation. CREATE, DROP, ALTER Data manipulation language (DML) statements. Used for queries and data modification INSERT, DELETE, UPDATE, SELECT 3 4 Creating Tables CREATE TABLE Example CREATE TABLE table_name( CREATE TABLE Students column_name1 column_type1 [constraints1], (StudentNumber integer NOT NULL, …, StudentLastName char(18) NOT NULL, [[ CONSTRAINT constraint_name] table_constraint] StudentFirstName char(18) NOT NULL, ) Email char(50), Table constraints: PhoneNumber char(18), NULL/NOT NULL MajorDepartmentName char(18), PRIMARY KEY (columns) UNIQUE (columns) CONSTRAINT PK_Students PRIMARY KEY (StudentNumber), CHECK (conditions) CONSTRAINT U_Email UNIQUE (Email), FOREIGN KEY (local_columns ) REFERENCES foreign_table CONSTRAINT FK_Dept FOREIGN KEY(MajorDepartmentName) (foreign_columns ) [ON DELETE action_d ON UPDATE action_u ] REFERENCES DEPARTMENTS(DepartmentName) ON DELETE NO ACTION ON UPDATE CASCADE Specify surrogate key in SQL Server: ) column_name int_type IDENTITY (seed, increment) 5 6 1 FOREIGN KEY Constraints FOREIGN KEY Constraints DEPARTMENTS DepartmentName Phone Building Room CREATE TABLE Students DepartmentName: char(18) Mathematics 410-293-4573 Michelson Hall 308 4 options on (StudentNumber integer, Phone: char(18) History 410-293-2255 Sampson Hall 120 StudentLastName char(18) NOT NULL, Building: char(18) Computer Science 410-293-6800 Michelson Hall 340 deletes and StudentFirstName char(18) NOT NULL, Room: integer Email char(50) NULL, D:SN updates: U:C Student Student Student Email PhoneNumber MajorDepartmentName PhoneNumber char(18) NULL, Number LastName FirstName MajorDepartmentName char(18) NULL, 190 Smith John [email protected] 410-431-3456 NO ACTION Majors PRIMARY KEY (StudentNumber), 673 Doe Jane [email protected] Computer Science (delete/update is UNIQUE(Email), 312 Doe Bob [email protected] 443-451-7865 Mathematics I:SN rejected) FOREIGN KEY (MajorDepartmentName) U:SN REFERENCES Departments (DepartmentName) STUDENTS CREATE TABLE Departments ON DELETE SET NULL StudentNumber: integer (DepartmentName char(18), CASCADE ON UPDATE CASCADE StudentLastName: char(18) Phone char(18) NOT NULL, StudentFirstName: char(18) ) Email: varchar(50) Building char(18), SET NULL PhoneNumber: char(18) Room integer, DepartmentName: char(18) (FK) PRIMARY KEY (DepartmentName) SET DEFAULT ) 7 8 Modifying Tables ALTER TABLE Examples ALTER TABLE table_name clause ALTER TABLE Students ADD COLUMN BirthDate datetime NULL Clauses: ALTER TABLE Students DROP COLUMN BirthDate ADD COLUMN column_name column_type [constraints] DROP COLUMN column_name ALTER COLUMN / MODIFY – DBMS specific! ALTER TABLE Student ADD CONSTRAINT FK_Department ADD CONSTRAINT constraint FOREIGN KEY (MajorDepartmentName) DROP CONSTRAINT constraint_name REFERENCES Departments (DepartmentName) ON DELETE NO ACTION ON UPDATE CASCADE 9 10 Removing Tables SQL DDL and DML DROP TABLE table_name Data definition language (DDL) DROP TABLE Departments; statements Used for creating and modifying tables, views, and other structures If there are constraints dependent on table: Remove constraints CREATE, ALTER, DROP Drop table Data manipulation language (DML) statements. ALTER TABLE Students DROP CONSTRAINT FK_Department; Used for queries and data modification INSERT, DELETE, UPDATE, SELECT DROP TABLE Departments; 11 12 2 SQL DML INSERT Statement INSERT INTO table_name [ (column_list) ] VALUES (data_values) Data manipulation language (DML) INSERT INTO table_name [ (column_list) ] select_statement statements. INSERT command: Used for queries and data modification INSERT INTO Students (StudentNumber, StudentLastName, StudentFirstName) VALUES (190, ‘Smith', ‘John’); INSERT INSERT INTO Students VALUES(190, ‘Smith’, ‘John’, ‘[email protected]’, DELETE ‘410-431-3456’) UPDATE SELECT Bulk INSERT: INSERT INTO Students (StudentNumber, StudentLastName, StudentFirstName, Email, PhoneNumber) SELECT * FROM Second_Class_Students; 13 14 UPDATE Statement DELETE Statement UPDATE table_name DELETE FROM table_name SET column_name1 = expression1 [ ,column_name2 = expression2,… ] [ WHERE search_condition ] [ WHERE search_condition ] DELETE command: UPDATE command: DELETE FROM Students UPDATE Students SET PhoneNumber = ‘410-123-4567’ WHERE StudentNumber = 190; WHERE StudentNumber = 673; If you omit the WHERE clause, you will delete every row in the table! BULK UPDATE command: Another example: UPDATE Students SET PhoneNumber = ‘410-123-4567’ DELETE FROM Departments WHERE StudentLAstName = ‘Doe’; WHERE DepartmentName = ‘ComSci’ Student Student Student Email PhoneNumber Integrity constraints?! Number LastName FirstName 190 Smith John [email protected] 410-431-3456 673 Doe Jane [email protected] 15 16 312 Doe Bob [email protected] 443-451-7865 Selecting All Columns: The SQL SELECT Statement The Asterisk (*) Keyword Basic SQL Query: SELECT * SELECT [DISTINCT] column_name(s) | * FROM Students; FROM table_name(s) Student Student Student Email PhoneNumber MajDeptName [WHERE conditions] Number LastName FirstName 190 Smith John [email protected] 410-431-3456 ComSci 673 Doe Jane [email protected] ComSci 312 Doe Jane [email protected] 443-451-7865 Math 17 18 3 Specific Columns and Rows from The DISTINCT Keyword One Table SELECT StudentNumber, SELECT SName SELECT DISTINCT StudentLastName, StudentFirstName FROM Students; SName FROM Students FROM Students; WHERE MajDeptName = ‘ComSci’; StudentLastName Student Student Student StudentLastName Number LastName FirstName Smith 190 Smith John Doe Smith 673 Doe Jane Doe Doe 19 20 Class Exercise Students, Courses, Enrolled Find the names of students enrolled in IT420 Division(Name , Building, OfficeNb) Department(DeptName , ChairName, WebAddress, SELECT SName DivName) FROM Students S, Enrolled E WHERE S.Snb = E.SNb AND E.Cid = ‘IT420’ Create tables SNb SName Email Cid CName CDept Modify Department to add a FK constraint for DivName 190 Smith [email protected] IT420 Database ComSci Create table Colleges with same structure as Division 673 Doe [email protected] IT340 Networks ComSci Insert everything from Division into Colleges 312 Doe [email protected] SM121 Calculus1 Math Remove Division table SNb Cid Semester Find the name of the Chair of the ‘Math’ Department 190 IT340 Spring2006 312 IT420 Fall2005 21 22 SELECT - Conceptual Evaluation Example Conceptual Evaluation Strategy Semantics of an SQL query defined in terms of SELECT SName the following conceptual evaluation strategy: FROM Students S, Enrolled E WHERE S.Snb = E.SNb AND E.Cid = ‘IT420’ Compute the cross-product of table_names Discard resulting rows if they fail condition Delete columns that are not in column_names S.SNb SName Email E.SNb Cid Semester 190 Smith [email protected] 190 IT340 Spring2006 If DISTINCT is specified, eliminate duplicate rows 190 Smith [email protected] 312 IT420 Fall2005 This strategy is probably the least efficient way 673 Doe [email protected] 190 IT340 Spring2006 673 Doe [email protected] 312 IT420 Fall2005 to compute a query! 312 Doe [email protected] 190 IT340 Spring2006 An optimizer will find more efficient strategies to 312 Doe [email protected] 312 IT420 Fall2005 compute the same answers. 23 24 4 Example Conceptual Evaluation Example Conceptual Evaluation SELECT SName SELECT SName SName FROM Students S, Enrolled E FROM Students S, Enrolled E Doe WHERE S.Snb = E.SNb AND E.Cid = ‘IT420’ WHERE S.Snb = E.SNb AND E.Cid = ‘IT420’ S.SNb SName Email E.SNb Cid Semester 190 Smith [email protected] 190 IT340 Spring2006 S.SNb SName Email E.SNb Cid Semester 190 Smith [email protected] 190 IT340 Spring2006 190 Smith [email protected] 312 IT420 Fall2005 673 Doe [email protected] 190 IT340 Spring2006 190 Smith [email protected] 312 IT420 Fall2005 673 Doe [email protected] 312 IT420 Fall2005 673 Doe [email protected] 190 IT340 Spring2006 312 Doe [email protected] 190 IT340 Spring2006 673 Doe [email protected] 312 IT420 Fall2005 312 Doe [email protected] 312 IT420 Fall2005 312 Doe [email protected] 190 IT340 Spring2006 312 Doe [email protected] 312 IT420 Fall2005 25 26 Modified Query Sorting the Results SELECT SNb SELECT … FROM Students S, Enrolled E FROM … [WHERE …] WHERE S.Snb = E.SNb AND E.Cid =‘IT420’ ORDER BY column_name(s) [ASC/DESC] Would the result be different with Example: DISTINCT? SELECT SNb, SName FROM Students ORDER BY SName ASC, SNb DESC 27 28 LIKE and Wildcards WHERE Clause Options SELECT * AND, OR FROM Students IN, NOT IN, BETWEEN WHERE SNb LIKE ‘_9_%’ SELECT SNb SQL 92 Standard (SQL Server, Oracle, etc.): _ = Exactly one character FROM Students S, Enrolled E % = Any set of one or more characters WHERE S.SNb = E.Nb AND MS Access ? = Exactly one character E.Cid NOT IN (‘ComSci’, ‘Math’) * = Any set of one or more characters 29 30 5 Class Exercise Students(SNb , SName, Email) Courses(Cid ,CName, Dept) Enrolled(SNb,Cid, Semester) Find the student number and name for each student enrolled in ‘Spring2007’ semester Find the names of all students enrolled in ‘ComSci’ courses 31 6.
Recommended publications
  • Genesys Info Mart Physical Data Model for an Oracle Database
    Genesys Info Mart Physical Data Model for an Oracle Database Table RESOURCE_STATE_REASON 9/24/2021 Table RESOURCE_STATE_REASON Table RESOURCE_STATE_REASON Description Modified: 8.5.014.34 (in Microsoft SQL Server, data type for the following columns modified in single- language databases: REASON_TYPE, REASON_TYPE_CODE, HARDWARE_REASON, SOFTWARE_REASON_KEY, SOFTWARE_REASON_VALUE, WORKMODE, WORKMODE_CODE); 8.5.003 (in Oracle, fields with VARCHAR data types use explicit CHAR character-length semantics) In partitioned databases, this table is not partitioned. This table allows facts to be described by the state reason of the associated agent resource at a particular DN resource. Each row describes a hardware or software reason and a work mode. Tip To assist you in preparing supplementary documentation, click the following link to download a comma-separated text file containing information such as the data types and descriptions for all columns in this table: Download a CSV file. Hint: For easiest viewing, open the downloaded CSV file in Excel and adjust settings for column widths, text wrapping, and so on as desired. Depending on your browser and other system settings, you might need to save the file to your desktop first. Column List Legend Column Data Type P M F DV RESOURCE_STATE_REASON_KEYNUMBER(10) X X TENANT_KEY NUMBER(10) X X Genesys Info Mart Physical Data Model for an Oracle Database 2 Table RESOURCE_STATE_REASON Column Data Type P M F DV CREATE_AUDIT_KEYNUMBER(19) X X UPDATE_AUDIT_KEYNUMBER(19) X X VARCHAR2(64 REASON_TYPE CHAR) VARCHAR2(32 REASON_TYPE_CODE CHAR) VARCHAR2(255 HARDWARE_REASON CHAR) VARCHAR2(255 SOFTWARE_REASON_KEY CHAR) VARCHAR2(255 SOFTWARE_REASON_VALUE CHAR) VARCHAR2(64 WORKMODE CHAR) VARCHAR2(32 WORKMODE_CODE CHAR) PURGE_FLAG NUMBER(1) RESOURCE_STATE_REASON_KEY The primary key of this table and the surrogate key that is used to join this dimension to the fact tables.
    [Show full text]
  • 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]
  • Create Table Identity Primary Key Sql Server
    Create Table Identity Primary Key Sql Server Maurits foozle her Novokuznetsk sleeplessly, Johannine and preludial. High-principled and consonantal Keil often stroke triboluminescentsome proletarianization or spotlight nor'-east plop. or volunteer jealously. Foul-spoken Fabio always outstrips his kursaals if Davidson is There arise two ways to create tables in your Microsoft SQL database. Microsoft SQL Server has built-in an identity column fields which. An identity column contains a known numeric input for a row now the table. SOLVED Can select remove Identity from a primary case with. There cannot create table created on every case, primary key creates the server identity column if the current sql? As I today to refute these records into a U-SQL table review I am create a U-SQL database. Clustering option requires separate table created sequence generator always use sql server tables have to the key. This key creates the primary keys per the approach is. We love create Auto increment columns in oracle by using IDENTITY. PostgreSQL Identity Column PostgreSQL Tutorial. Oracle Identity Column A self-by-self Guide with Examples. Constraints that table created several keys means you can promote a primary. Not logged in Talk Contributions Create account already in. Primary keys are created, request was already creates a low due to do not complete this. IDENTITYNOT NULLPRIMARY KEY Identity Sequence. How weak I Reseed a SQL Server identity column TechRepublic. Hi You can use one query eg Hide Copy Code Create table tblEmplooyee Recordid bigint Primary key identity. SQL CREATE TABLE Statement Tutorial Republic. Hcl will assume we need be simplified to get the primary key multiple related two dissimilar objects or adding it separates structure is involved before you create identity? When the identity column is part of physician primary key SQL Server.
    [Show full text]
  • Not ACID, Not BASE, but SALT a Transaction Processing Perspective on Blockchains
    Not ACID, not BASE, but SALT A Transaction Processing Perspective on Blockchains Stefan Tai, Jacob Eberhardt and Markus Klems Information Systems Engineering, Technische Universitat¨ Berlin fst, je, [email protected] Keywords: SALT, blockchain, decentralized, ACID, BASE, transaction processing Abstract: Traditional ACID transactions, typically supported by relational database management systems, emphasize database consistency. BASE provides a model that trades some consistency for availability, and is typically favored by cloud systems and NoSQL data stores. With the increasing popularity of blockchain technology, another alternative to both ACID and BASE is introduced: SALT. In this keynote paper, we present SALT as a model to explain blockchains and their use in application architecture. We take both, a transaction and a transaction processing systems perspective on the SALT model. From a transactions perspective, SALT is about Sequential, Agreed-on, Ledgered, and Tamper-resistant transaction processing. From a systems perspec- tive, SALT is about decentralized transaction processing systems being Symmetric, Admin-free, Ledgered and Time-consensual. We discuss the importance of these dual perspectives, both, when comparing SALT with ACID and BASE, and when engineering blockchain-based applications. We expect the next-generation of decentralized transactional applications to leverage combinations of all three transaction models. 1 INTRODUCTION against. Using the admittedly contrived acronym of SALT, we characterize blockchain-based transactions There is a common belief that blockchains have the – from a transactions perspective – as Sequential, potential to fundamentally disrupt entire industries. Agreed, Ledgered, and Tamper-resistant, and – from Whether we are talking about financial services, the a systems perspective – as Symmetric, Admin-free, sharing economy, the Internet of Things, or future en- Ledgered, and Time-consensual.
    [Show full text]
  • Data Analysis Expressions (DAX) in Powerpivot for Excel 2010
    Data Analysis Expressions (DAX) In PowerPivot for Excel 2010 A. Table of Contents B. Executive Summary ............................................................................................................................... 3 C. Background ........................................................................................................................................... 4 1. PowerPivot ...............................................................................................................................................4 2. PowerPivot for Excel ................................................................................................................................5 3. Samples – Contoso Database ...................................................................................................................8 D. Data Analysis Expressions (DAX) – The Basics ...................................................................................... 9 1. DAX Goals .................................................................................................................................................9 2. DAX Calculations - Calculated Columns and Measures ...........................................................................9 3. DAX Syntax ............................................................................................................................................ 13 4. DAX uses PowerPivot data types .........................................................................................................
    [Show full text]
  • (BI) Using MS Excel Powerpivot
    2018 ASCUE Proceedings Developing an Introductory Class in Business Intelligence (BI) Using MS Excel Powerpivot Dr. Sam Hijazi Trevor Curtis Texas Lutheran University 1000 West Court Street Seguin, Texas 78130 [email protected] Abstract Asking questions about your data is a constant application of all business organizations. To facilitate decision making and improve business performance, a business intelligence application must be an in- tegral part of everyday management practices. Microsoft Excel added PowerPivot and PowerPivot offi- cially to facilitate this process with minimum cost, knowing that many business people are already fa- miliar with MS Excel. This paper will design an introductory class to business intelligence (BI) using Excel PowerPivot. If an educator decides to adopt this paper for teaching an introductory BI class, students should have previ- ous familiarity with Excel’s functions and formulas. This paper will focus on four significant phases all students need to complete in a three-credit class. First, students must understand the process of achiev- ing small database normalization and how to bring these tables to Excel or develop them directly within Excel PowerPivot. This paper will walk the reader through these steps to complete the task of creating the normalization, along with the linking and bringing the tables and their relationships to excel. Sec- ond, an introduction to Data Analysis Expression (DAX) will be discussed. Introduction It is not that difficult to realize the increase in the amount of data we have generated in the recent memory of our existence as a human race. To realize that more than 90% of the world’s data has been amassed in the past two years alone (Vidas M.) is to realize the need to manage such volume.
    [Show full text]
  • Alter Table Column Auto Increment Sql Server
    Alter Table Column Auto Increment Sql Server Esau never parchmentize any jolters plenish obsequiously, is Brant problematic and cankered enough? Zacharie forespeaks bifariously while qualitative Darcy tumefy availingly or meseems indisputably. Stolidity Antonino never reawakes so rifely or bejeweled any viol disbelievingly. Cookies: This site uses cookies. In sql server table without the alter table becomes a redbook, the value as we used. Change it alter table sql server tables have heavily used to increment columns, these additional space is structured and. As a result, had this name changed, which causes data layer in this column. Each path should be defined as NULL or NOT NULL. The illustrative example, or the small addition, database and the problem with us improve performance, it gives the actual data in advanced option. MUST be some option here. You kill of course test the higher values as well. Been logged in sql? The optional column constraint name lets you could or drop individual constraints at that later time, affecting upholstery, inserts will continue without fail. Identity columns are sql server tables have data that this data type of rust early in identity. No customs to concern your primary key. If your car from making unnatural sounds or rocks to help halt, give us a call! Unexpected error when attempting to retrieve preview HTML. These faster than sql server table while alter local processing modes offered by the alter table column sql auto server sqlcmd and. Logged Recovery model to ensure minimal logging. We create use table to generate lists of different types of objects that reason then be used for reporting or find research.
    [Show full text]
  • Keys Are, As Their Name Suggests, a Key Part of a Relational Database
    The key is defined as the column or attribute of the database table. For example if a table has id, name and address as the column names then each one is known as the key for that table. We can also say that the table has 3 keys as id, name and address. The keys are also used to identify each record in the database table . Primary Key:- • Every database table should have one or more columns designated as the primary key . The value this key holds should be unique for each record in the database. For example, assume we have a table called Employees (SSN- social security No) that contains personnel information for every employee in our firm. We’ need to select an appropriate primary key that would uniquely identify each employee. Primary Key • The primary key must contain unique values, must never be null and uniquely identify each record in the table. • As an example, a student id might be a primary key in a student table, a department code in a table of all departments in an organisation. Unique Key • The UNIQUE constraint uniquely identifies each record in a database table. • Allows Null value. But only one Null value. • A table can have more than one UNIQUE Key Column[s] • A table can have multiple unique keys Differences between Primary Key and Unique Key: • Primary Key 1. A primary key cannot allow null (a primary key cannot be defined on columns that allow nulls). 2. Each table can have only one primary key. • Unique Key 1. A unique key can allow null (a unique key can be defined on columns that allow nulls.) 2.
    [Show full text]
  • The Relational Data Model and Relational Database Constraints
    chapter 33 The Relational Data Model and Relational Database Constraints his chapter opens Part 2 of the book, which covers Trelational databases. The relational data model was first introduced by Ted Codd of IBM Research in 1970 in a classic paper (Codd 1970), and it attracted immediate attention due to its simplicity and mathematical foundation. The model uses the concept of a mathematical relation—which looks somewhat like a table of values—as its basic building block, and has its theoretical basis in set theory and first-order predicate logic. In this chapter we discuss the basic characteristics of the model and its constraints. The first commercial implementations of the relational model became available in the early 1980s, such as the SQL/DS system on the MVS operating system by IBM and the Oracle DBMS. Since then, the model has been implemented in a large num- ber of commercial systems. Current popular relational DBMSs (RDBMSs) include DB2 and Informix Dynamic Server (from IBM), Oracle and Rdb (from Oracle), Sybase DBMS (from Sybase) and SQLServer and Access (from Microsoft). In addi- tion, several open source systems, such as MySQL and PostgreSQL, are available. Because of the importance of the relational model, all of Part 2 is devoted to this model and some of the languages associated with it. In Chapters 4 and 5, we describe the SQL query language, which is the standard for commercial relational DBMSs. Chapter 6 covers the operations of the relational algebra and introduces the relational calculus—these are two formal languages associated with the relational model.
    [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]
  • Data Definition Language
    1 Structured Query Language SQL, or Structured Query Language is the most popular declarative language used to work with Relational Databases. Originally developed at IBM, it has been subsequently standard- ized by various standards bodies (ANSI, ISO), and extended by various corporations adding their own features (T-SQL, PL/SQL, etc.). There are two primary parts to SQL: The DDL and DML (& DCL). 2 DDL - Data Definition Language DDL is a standard subset of SQL that is used to define tables (database structure), and other metadata related things. The few basic commands include: CREATE DATABASE, CREATE TABLE, DROP TABLE, and ALTER TABLE. There are many other statements, but those are the ones most commonly used. 2.1 CREATE DATABASE Many database servers allow for the presence of many databases1. In order to create a database, a relatively standard command ‘CREATE DATABASE’ is used. The general format of the command is: CREATE DATABASE <database-name> ; The name can be pretty much anything; usually it shouldn’t have spaces (or those spaces have to be properly escaped). Some databases allow hyphens, and/or underscores in the name. The name is usually limited in size (some databases limit the name to 8 characters, others to 32—in other words, it depends on what database you use). 2.2 DROP DATABASE Just like there is a ‘create database’ there is also a ‘drop database’, which simply removes the database. Note that it doesn’t ask you for confirmation, and once you remove a database, it is gone forever2. DROP DATABASE <database-name> ; 2.3 CREATE TABLE Probably the most common DDL statement is ‘CREATE TABLE’.
    [Show full text]
  • Attunity Compose 3.1 Release Notes - April 2017
    Attunity Compose 3.1 Release Notes - April 2017 Attunity Compose 3.1 introduces a number of features and enhancements, which are described in the following sections: Enhanced Missing References Support Surrogate Key Enhancement Support for Archiving Change Tables Support for Fact Table Updates Performance Improvements Support for NULL Overrides in the Data Warehouse Creation of Data Marts in Separate Schemas or Databases Post-Upgrade Procedures Resolved Issues Known Issues Attunity Ltd. Attunity Compose 3.1 Release Notes - April 2017 | Page 1 Enhanced Missing References Support In some cases, incoming data is dependent on or refers to other data. If the referenced data is missing for some reason, you either decide to add the data manually or continue on the assumption that the data will arrive before it is needed. From Compose 3.1, users can view missing references by clicking the View Missing References button in the Manage ETL Sets' Monitor tab or by switching the console to Monitor view and selecting the Missing References tab below the task list. Attunity Ltd. Attunity Compose 3.1 Release Notes - April 2017 | Page 2 Surrogate Key Enhancement Compose uses a surrogate key to associate a Hub table with its satellites. In the past, the column containing the surrogate key (ID) was of INT data type. This was an issue with entities containing over 2.1 billions records (which is the maximun permitted INT value). The issue was resolved by changing the column containing the surrogate key to BIGINT data type. Attunity Ltd. Attunity Compose 3.1 Release Notes - April 2017 | Page 3 Support for Archiving Change Tables From Compose 3.1, you can determine whether the Change Tables will be archived (and to where) or deleted after the changes have been applied.
    [Show full text]