1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

Database Chapters.
Pertemuan ke 2 Tipe data & ERD Kurniawan Eka Permana.
Database Design -- Basic SQL
SQL’s Data Definition Language (DDL) n DDL statements define, modify and remove objects from data dictionary tables maintained by the DBMS n Whenever you.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
Sanjay Goel, School of Business, University at Albany, SUNY 1 SQL- Data Definition Language ITM 692 Sanjay Goel.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
Database Modifications A modification command does not return a result as a query does, but it changes the database in some way. There are three kinds.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
Database Management System LICT 3011 Eyad H. Elshami.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 10: Data Definition Language.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Database Design (for IQ-M). Introduction This section has been re-vamped for the course I have removed all the design bits that are not absolutely.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Chapter 3: SQL Data Definition Language Data Definition Language Basic Structure of SQL Basic Structure of SQL Set Operations Set Operations Aggregate.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
Copyright © Curt Hill SQL The Data Definition Language.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Ms. Hatoon Al-Sagri CCIS – IS Department SQL-99 :Schema Definition, Constraints, Queries, and Views 1.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Guofeng Cao CyberInfrastructure and Geospatial Information Laboratory Department of Geography National Center for Supercomputing Applications (NCSA) University.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
CSC 2720 Building Web Applications Database and SQL.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
SQL: DDL John Ortiz Cs.utsa.edu.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
MySQL More… 1. More on SQL In MySQL, the Information Schema is the “Catalog” in the SQL standard SQL has three components: Data definition Data manipulation.
Advanced Web 2012 Lecture 3 Sean Costain What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Chapter 6 SQL. Agenda Data Definition Language (DDL) Access Control.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
Sql DDL queries CS 260 Database Systems.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
Lecture # 24 Introduction to SQL Muhammad Emran Database Systems.
LECTURE FOUR Introduction to SQL DDL with tables DML with tables.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Data Definition and Data Types
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
Insert, Update and the rest…
SQL OVERVIEW DEFINING A SCHEMA
SQL data definition using Oracle
Database systems Lecture 2 – Data Types
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Chapter 2: Creating And Modifying Database Tables
Chapter 4 Introduction to MySQL.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Structured Query Language Path from Unorganized to Organized….
SQL (Structured Query Language)
Presentation transcript:

1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL

2 SQL Data Types Numeric  INTEGER, INT, SMALLINT MySQL: TINYINT (1 BYTE), SMALLINT (2 BYTE), MEDIUMINT (3 BYTE), INT or INTEGER (4 BYTE), BIGINT (8 BYTE), both SIGNED and UNSIGNED  FLOAT, REAL, DOUBLE PRECISION MySQL: FLOAT (single precision), DOUBLE, REAL, DOUBLE PRECISION (double precision)  DECIMAL, DEC, NUMERIC(I, J) I is number of digits, J is number following decimal point MySQL: DECIMAL, DEC, NUMERIC, FIXED

3 SQL Data Types Character String  CHAR(n) or CHARACTER(n)  VARCHAR(n), CHAR VARYING(n), CHARACTER VARYING(n) MySQL:  CHAR(n), VARCHAR(n) - n <= 255  BINARY, VARBINARY - same except binary  xBLOB, xTEXT (x = TINY, (none), MEDIUM, LONG - controls maximum size)  ENUM - string object with restricted set of values, internally stored as integers

4 SQL Data Types Boolean  Three valued (True, False, Unknown)  Used to support logic with NULLs  MySQL: Boolean is a synonym for a one-bit TINYINT Full SQL Standard Booleans to be implemented

5 SQL Data Types Date and Time Types  DATE: YYYY-MM-DD (Standard and MySQL)  TIME: HH:MM:SS (Standard and MySQL)  DATETIME: YYYY-MM-DD HH:MM:SS (MySQL)  TIMESTAMP: YYYY-MM-DD HH:MM:SS NNNNNN (Includes fractional seconds) (Standard) (MySQL - no fractional seconds)

6 CREATE SCHEMA CREATE DATABASE Standard: CREATE SCHEMA schema_name AUTHORIZATION user_name;  Create the named schema administered by the named user MySQL: CREATE DATABASE [IF_NOT_EXISTS] database_name;  Create named database. User must have requisite privileges  CREATE SCHEMA is being added in MySQL 5.0

7 Basic CREATE TABLE CREATE TABLE table_name … CREATE TABLE schema_name.table_name …  Create the named table MySQL:  CREATE [TEMPORARY] TABLE table_name … table_name includes database_name.table_name

8 Basic CREATE TABLE CREATE TABLE table_name (column_def, … ); Where column_def is: column_name column_type [NOT NULL | NULL] [DEFAULT value] [CHECK expr]  NULL is default  DEFAULT value is default for type if not specified An insert which doesn’t specify a value for a column will: 1. Use the DEFAULT value if that’s specified 2. Use NULL is that’s allowed 3. Use the default for type if that’s allowed (switch/option) 4. Return an error CHECK expr causes the expression to be checked when the column is changed (not in MySQL)

9 Some More CREAT TABLE CREATE TABLE table_name ( column_def, …, column_def, create_def, …, create_def)  Technically: A column_def is a create_def

10 Create Definitions Constraints  CONSTRAINT constraint_name PRIMARY KEY (col_name, … col_name)  CONSTRAINT constraint_name UNIQUE (col, … col) Alternate Key  CONSTRAINT constraint_name FOREIGN KEY (col, … col) REFERNCES table(col, … col) [ ON DELETE … ] [ ON UPDATE …]

11 Create Definitions Others  INDEX name (col, … col) Create an (non-unique) Index  CHECK(expr) Check that expr holds when table is modified MySQL: Parsed but ignored (ouch!) And many, many others …  Includes DB Engine specific options for all DBMSs

12 DROP DROP TABLE DROP SCHEMA | DATABASE  Optional IF EXISTS Delete whatever

13 ALTER TABLE ALTER TABLE table_name alter_spec, … alter_spec  ADD COLUMN, CONSTRAINT, INDEX Use the definition as in CREATE TABLE  DROP COLUMN, CONSTRAINT, INDEX name  ALTER COLUMN name SET DEFAULT value  ALTER COLUMN name DROP DEFAULT  RENAME new_table_name And a host of others

14 Guidance Create a shell script that looks something like DROP TABLE table_name IF EXISTS; CREATE TABLE table_name … LOAD DATA INFILE …  Load test data May include DROP DATABASE, CREATE DATABASE if you have the privileges Edit and run the shell script when you need to recreate the database Reserve ALTER, … for fixing databases when they reach the point where the above won’t work

15 Guidance for Creating Databases