4 Logical Design : RDM Schema Definition with SQL / DDL



Similar documents
How To Create A Table In Sql (Ahem)

3.GETTING STARTED WITH ORACLE8i

Comparison of Open Source RDBMS

Fundamentals of Database Design

Porting from Oracle to PostgreSQL

Database Migration from MySQL to RDM Server

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

SQL Server An Overview

Information Systems SQL. Nikolaj Popov

IT2304: Database Systems 1 (DBS 1)

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

Using SQL Server Management Studio

IT2305 Database Systems I (Compulsory)

2/3/04 Doc 7 SQL Part 1 slide # 1


Programming with SQL

Database Design and Programming

Financial Data Access with SQL, Excel & VBA

RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague

Services. Relational. Databases & JDBC. Today. Relational. Databases SQL JDBC. Next Time. Services. Relational. Databases & JDBC. Today.

CSC 443 Data Base Management Systems. Basic SQL

SQL. Short introduction

B.1 Database Design and Definition

Information Technology NVEQ Level 2 Class X IT207-NQ2012-Database Development (Basic) Student s Handbook

Information Systems Modelling Information Systems I: Databases

PL/SQL MOCK TEST PL/SQL MOCK TEST I

Instant SQL Programming

Linas Virbalas Continuent, Inc.

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

MS ACCESS DATABASE DATA TYPES

Database Query 1: SQL Basics

Conventional Files versus the Database. Files versus Database. Pros and Cons of Conventional Files. Pros and Cons of Databases. Fields (continued)

Oracle SQL. Course Summary. Duration. Objectives

Oracle Migration Workbench

4 Simple Database Features

Database 2 Lecture I. Alessandro Artale

6 CHAPTER. Relational Database Management Systems and SQL Chapter Objectives In this chapter you will learn the following:

A Brief Introduction to MySQL

Physical Design. Meeting the needs of the users is the gold standard against which we measure our success in creating a database.

Fact Sheet In-Memory Analysis

Oracle Internal & Oracle Academy

Organization of Records in Blocks

DDL is short name of Data Definition Language, which deals with database schemas and descriptions, of how the data should reside in the database.

Advance DBMS. Structured Query Language (SQL)

MySQL for Beginners Ed 3

MariaDB Cassandra interoperability

ODBC Client Driver Help Kepware, Inc.

Oracle Database: SQL and PL/SQL Fundamentals

Discovering SQL. Wiley Publishing, Inc. A HANDS-ON GUIDE FOR BEGINNERS. Alex Kriegel WILEY

Introduction to Microsoft Jet SQL

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

Oracle 10g PL/SQL Training

Relational Database Basics Review

C++ Wrapper Library for Firebird Embedded SQL

The release notes provide details of enhancements and features in Cloudera ODBC Driver for Impala , as well as the version history.

Database Management System Choices. Introduction To Database Systems CSE 373 Spring 2013

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

sqlite driver manual

Introduction to Database. Systems HANS- PETTER HALVORSEN,

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

!"# $ %& '( ! %& $ ' &)* + ! * $, $ (, ( '! -,) (# *&23. mysql> select * from from clienti;

Microsoft SQL Server to Infobright Database Migration Guide

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

Introduction to Databases

Oracle Database: SQL and PL/SQL Fundamentals NEW

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

Introduction. Introduction: Database management system. Introduction: DBS concepts & architecture. Introduction: DBS versus File system

Summary on Chapter 4 Basic SQL

An Introduction to Relational Database Management System

Database Administration with MySQL

DBMS / Business Intelligence, SQL Server

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

PL/SQL TUTORIAL. Simply Easy Learning by tutorialspoint.com. tutorialspoint.com

Handling Unstructured Data Type in DB2 and Oracle

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

Success Keys For Migrating From Sybase ASE to DB2 UDB

Introduction: Database management system

COSC344 Database Theory and Applications. Java and SQL. Lecture 12

Creating Database Tables in Microsoft SQL Server

A table is a collection of related data entries and it consists of columns and rows.

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

Oracle Database 11g Express Edition PL/SQL and Database Administration Concepts -II

EECS 647: Introduction to Database Systems

Language Reference Guide

Choosing a Data Model for Your Database

SQL:2003 Has Been Published

Databases 2011 The Relational Model and SQL

Microsoft SQL Server Connector for Apache Hadoop Version 1.0. User Guide

Oracle Database 12c: Introduction to SQL Ed 1.1

6. SQL/XML. 6.1 Introduction. 6.1 Introduction. 6.1 Introduction. 6.1 Introduction. XML Databases 6. SQL/XML. Creating XML documents from a database

Working with DB2 UDB objects

Systems Infrastructure for Data Science. Web Science Group Uni Freiburg WS 2012/13

XML Databases 6. SQL/XML

Specifications of Paradox for Windows

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

Beginning SQL, Differences Between Oracle and Microsoft

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

5.1 Database Schema Schema Generation in SQL

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

Transcription:

4 Logical Design : RDM Schema Definition with SQL / DDL 4.1 SQL history and standards 4.2 SQL/DDL first steps 4.2.1 Basis Schema Definition using SQL / DDL 4.2.2 SQL Data types, domains, user defined types 4.2.3 Creating simple tables see: Melton/Simon: chap 2, 3.3, 4 System documentation (e.g. Postgres, Oracle, MySQL, see references) Logical Design Lifecycle Context Requirements analysis Conceptual Design Schema design - logical ( create tables ) Schema design - physical ( create access path ) Loading, administration, tuning, maintenance, reorganization System analyst DB designer Application programmer Application programmer DB administrator DB administrator 2

4.1 SQL History 1974 1975 1986 1989 1992 Prototype System R (IBM, San Jose) First relational DBMS based on Codd s relational model Structured English Query Language (SEQUEL) SEQUEL renamed SQL (pronounced Sequel in US) First standardization attempt based on system R SQL standard ANSI SQL-1, SQL-89 about 120 pages SQL2 standard SQL : Standard Query Language ANSI SQL-2, SQL-92 3 about 600 pages Standard Query Language: Standards SQL-92 compliance levels: (1) Entry SQL: basically SQL-89, essential (2) Intermediate SQL, (3) Full SQL No implementation of SQL-92 on level 2 or3 SQL 1999 (SQL3) levels: Core SQL: essential for standard compliance Additional Features, e.g. object features Standards: not nice to have but inevitable Heavy influenced by strategies of SW-Industry All known implementations do not conform to every aspect of the standard First standard: SQL-89 Important: SQL-92 Core SQL:1999 enhanced SQL:1999 slight extension: SQL:2003 newest : SQL:/XML 4

Query Language Course Information Within the course: Basic concepts of SQL:1999 Oracle9i Core SQL:1999 compliant + additional features [MySQL 3.x not SQL compliant (no subqueries, foreign keys, ), more features in Vers. 4.x ] Postgres: close to SQL99 like Oracle Self study of further SQL concepts Local Oracle-documentation: http://www.inf.fu-berlin.de/inst/agdb/software/oracle/oracle_docu/index.htm Postgres: help files very technical and detailled SQL3 Syntax : local web pages 5 SQL Different sublanuages Data definition Language (DDL) Definition and change of data structures on all three database levels: Namespaces, relations with attributes, domains, data types, integrity constraints, triggers, functions on database,views, placement of data, space needed, access structures, Heavily system depend, least common denominator still SQL 92 entry level Data manipulation language (DML) Create, change, delete data Interactive query formulation Embedding of SQL commands in host language Specification of begin, abort, and end of transaction Data Administration language Access rights, authorization 6

4.2 SQL / DDL first steps 4.2.1 Basis Schema Definition using SQL / DDL Defining the relational schema: concepts to be expressed Logical Schema Namespaces (database, schema,...) Domains, data types Tables Integrityconstraints Key and uniqueness constraints Value constraints Cardinalityconstraints 7 Schema definition using SQL/DDL More Active elements (triggers) Functions defined on the database Physical Schema Physical Storage Space needed Access structures Physical placement of data Physical Schema: postponed 8

Name spaces in SQL / DDL database-name space? schema name space? catalog database schema SQL-2 standard table column Name structure: <cat>.<database>.<schema>.<table>.<column> 9 Databases and schemas in Postgres DB cluster set of databases catalog / SQL 99 Database physically separated set of schemas Schema logical construct; set of "database objects" Tables, functions, triggers,... Namespace: database.schema.table without effect in Postgres 10

Schemas in standard SQL / DDL and DBS CREATE SCHEMA <schemaname> e.g CREATE SCHEMA VideoStoreDB creates a namespace, in which relations (tables) have unambiguous names Has been proposed by SQL-2, but no DBS supports the full naming scheme Only <table>.<column> names are supported by all systems, confusing terminology in systems Oracle: Database = set of physical storage areas ("tablespaces") Name of schema = dbsusername, all objects may be prefixed with<dbusername> MySQL: Database = directory in File system where data reside Schema not defined in MySQL 11 4.2.2 SQL Data types Primitive attribute (column) types Base types of the SQL and/or DB system No constructed types contradict first normal form introduced bysql99 Types for numbers, characters, strings, date / time, Binary objects Numeric datatypes in SQL-2 NUMERIC (p,s) DECIMAL (p,s) INTEGER SMALLINT FLOAT (p,s) REAL DOUBLE PRECISION exact number, basically same as DECIMAL alias: INT approximate number implementation dependent precision 12

SQL Built-inin types More datatypes in SQL-2: Character etc Literal CHARACTER [(n)] CHAR 'A padded string ' // fixed length character string CHARACTER VARYING (n) VARCHAR (n) 'Hello SQL' // variable length string, n=maximum NATIONAL CHARACTER (n) NCHAR (n) NCHAR VARYING (n) not NVARCHAR (n) as in SQL99, do not use it in Oracle e.g. BIT [(n)], BIT VARYING DATE TIME TIMESTAMP DATE '2001-5-2' TIME '01:00:05.01' composed of year, month, day, hour, minute, second INTERVAL FirstUnitofTime [to LastUnitofTime] e.g. '1 day 12 hours 59 min 10 sec' 13 Syntax diagram for ANSI / SQL-2 character data type 14

Large Objects Large Character / Binary Objects since SQL 1999 Restricted, implementation defined restriction of maximum character string length Char(n) / VARCHAR(n), typically 4000 Bytes CHARACTER LARGE OBJECT CLOB NATIONAL CHARACTER LARGE OBJECT NCLOB BINARY LARGE OBJECT BLOB Typically up to 2 GB or even more. Useful for images, videos, No blobs in Postgres... but 'bytea' binary data type and arbitrary long 'text' data type. 15 Postgres specific data types Net specific macaddr MAC address inet IPV4 / V6 address Geometric types point lseg line segment path closed or open path polygon, box circle Miscalleneous serial autoincremented 32-Bit-Integer Constructed types arrays and more... 16

Oracle SQL built-inin types Datatype Description VARCHAR2(size) Variable-length character data CHAR(size) NUMBER(p,s) DATE Fixed-length character data Variable-length numeric data Date and time values LONG Variable-length character data up to 2 gigabytes CLOB Single-byte character data up to 4 gigabytes RAW(n),LONG RAW Raw binary data ( up to 2 KB 2 GB) BLOB BFILE Binary data up to 4 gigabytes e.g. X'49FE' Binary data stored in an external file; up to 4 gigabytes 17 Differences Numeric types in different DBS: Oracle NUMBER(p,s) Variable-length numeric data MySQL: TINYINT[(M)], SMALLINT[(M)], MEDIUMINT[(M)], INT[(M)], BIGINT[(M)], FLOAT(precision), FLOAT[(M,D)], DOUBLE[(M,D)], DOUBLE PRECISION[(M,D)], REAL[(M,D)], DECIMAL[(M[,D])], NUMERIC[(M[,D])] Many differences from standard Always use standard types Makes database less independent from the database system vendor 18

SQL/DDL Domains Domain named sets of values CREATE DOMAIN <domainname> <typedef> CREATE DOMAIN Money DECIMAL (10,2) not really representation independent, but useful in order to avoid semantically meaningless operations, e.g. comparing money with length attributes Not supported in most Systems (neither Oracle nor MySQL, exceptionpostgres, SAP-DB) 19 SQL / DDL: Distinct type: Similar to domain definition Strong typing Type definitions (user defined type) Syntax: CREATE TYPE <typename> as <typedef> [FINAL]; Examples: CREATE TYPE Euro AS DECIMAL(8,2) FINAL; CREATE TYPE Mark AS DECIMAL(8,2) FINAL; CREATE Type Address AS( street varchar (25), zipcode Integer,...); Core SQL:1999 20

4.2.3 Creating simple tables Tables CREATE TABLE <TableName> ( <attributname><attributetype> [<constraint>] {,<attributname><attributetype> [<constraint>]} {,<tableconstraints>}); CREATE TABLE Format ( format CHAR(5), extrach DECIMAL (3,2) ) SQL is basically case-insensitive Basic definition, many more specification options, evenphysical placement of tables 21 SQL / DDL: Simple example Table Definition CREATE TABLE Movie ( /* The Movie table does only store basic facts about the movies */ m_id INTEGER PRIMARY KEY, title CHAR VARYING(60) NOT NULL, cat CHAR(20), year DATE, director VARCHAR(40), price_day DECIMAL(4,2), length INTEGER) No constraints up to now except PRIMARY KEY e.g. multi-attribute primary key, cardinalityconstraints etc. lost. 22