Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.

Slides:



Advertisements
Similar presentations
Data Definition Language (DDL)
Advertisements

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.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
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 SQL to create tables Ways of using Databases.
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.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Database Management System LICT 3011 Eyad H. Elshami.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
1 CSE 480: Database Systems Lecture 9: SQL-DDL Reference: Read Chapter of the textbook.
Oracle Data Definition Language (DDL)
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
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.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
SQL FUNDAMENTALS SQL ( Structured Query Language )
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Lecture 2: Using DDL Statements to Create and Manage Tables & Indexes
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
SQL: DDL John Ortiz Cs.utsa.edu.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Copyright  Oracle Corporation, All rights reserved. Introduction.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
SQL: Part 1 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Schema Objects.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Populating and Querying tables Insert, Update, Delete and View (DML)
Relational Database Management System(RDBMS) Structured Query Language(SQL)
At the end of this lesson, you will be able to: Describe constraints Create and maintain constraints.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Lecture # 24 Introduction to SQL Muhammad Emran Database Systems.
LECTURE FOUR Introduction to SQL DDL with tables DML with tables.
SQL Statements SELECT INSERTUPDATEDELETECREATEALTERDROPRENAMETRUNCATECOMMITROLLBACKSAVEPOINTGRANTREVOKE Data Retrieval Language (DRL) Data Retrieval Language.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
SQL: Schema Definition and Constraints Chapter 6 week 6
Insert, Update and the rest…
SQL Creating and Managing Tables
DATABASE MANAGEMENT SYSTEM
SQL Creating and Managing Tables
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
SQL Creating and Managing Tables
Database systems Lecture 3 – SQL + CRUD
Oracle Data Definition Language (DDL)
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Chapter 2: Creating And Modifying Database Tables
Data Definition Language
Session - 6 Sequence - 1 SQL: The Structured Query Language:
SQL (Structured Query Language)
Presentation transcript:

Physical Model Lecture 11

Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access

Structured Query Language (SQL)  SQL (sequel) is used on a most RDBMS systems and ORDBMS (Oracle, PostGIS, IBM DB2, MySQL and SQL Server)  The first version of SQL was developed at IBM by Donald D. Chamberlin and Raymond F. Boyce in the early 1970s. This version, initially called SEQUEL

SQL The SQL language is sub-divided into several language elements, including: – Data Definition Language (DDL) – Data Manipulation Language and Transaction Control (DML) – Query Language – Procedural Language PL/SQL and – Data Control Language DCL. (language for DBA)

Data Definition Language (DDL)  DDL allows the user to define new database objects › Tables › Views › Index and › Other elements  The most basic items of DDL are the › CREATE, › ALTER, › RENAME, › TRUNCATE and › DROP statements :

Data Definition Language (DDL)  CREATE causes an object (a table, for example) to be created within the database.  DROP causes an existing object within the database to be deleted, usually irretrievably.  TRUNCATE deletes all data from a table (non- standard, but common SQL statement).  ALTER statement permits the user to modify an existing object in various ways -- for example, adding a column to an existing table. 7

Create table Command CREATE TABLE ([schema.]table column datatype [DEFAULT expr] [column_constraint(s)] [,column datatype [,...]] ) table_constraint table_ref_constraintdatatypecolumn_constraint(s) table_constrainttable_ref_constraint

Oracle Data types Numeric Data Types String Data Types Data/Time Data Types Spatial Data Types

Oracle Data Types (Numeric) NUMBER (p, q) signed number p digits, q decimals PLS_INTEGERused only in PL/SQL

Oracle Data Types (String) CHAR(n) fixed length string, VARCHAR2(n) varying length string, up to n-8 bits NCHAR(n) fixed length string national character set NVARCHAR2(n) varying length string national characterset

Oracle Data Types (Date/Time) DATE TIMESTAMP (fractional_seconds_precision)

Create a Table CREATE TABLE [GLOBAL TEMPORARY] table_name (column_name data_type [NOT NULL] [UNIQUE][DEFAULT default_option] [CHECK (search_condition)] [,…] [PRIMARY KEY (list_of_columns),] {[UNIQUE (list_of_columns),][,…]} {[FOREIGN KEY {(list_of_foreign_key_columns) REFERENCES parent_table_name[(list_of_candidate_key_columns)]) [] optional, {} one or more, lower case – user supplied names, upper case reserved words, [|] either or, () are part of the syntax.

Specifying Primary and Foreign keys Constraints can be added to the table at the time it is created, i.e. the primary key on dnumber and foreign key on mgrssn CREATE TABLE department ( dname VARCHAR2(15) NOT NULL, dnumber INTEGER NOT NULL, mgrssn VARCHAR2 (9) NOT NULL, mgrstartdate DATE, CONSTRAINT department_pk PRIMARY KEY(dnumber), CONSTRAINT fk_department_emp FOREIGN KEY(mgrssn) REFERENCES employee (ssn) );

ALTER TABLE COMMAND  ALTER TABLE – used to change an existing table definition. This statement can be used to › add a new column › remove an existing column in a table › modify the data type for an existing column › add or remove a constraint.  We will add constraints on the employee table using the ALTER TABLE statement

ALTER TABLE SYNTAX  ALTER TABLE [schema].table_name ADD [COLUMN] column_name  ALTER TABLE [schema].table_name ADD constraint_declare  ALTER TABLE [schema].table_name DROP [COLUMN] column_name  ALTER TABLE [schema].table_name DROP CONSTRAINT constraint_name  ALTER TABLE [schema].table_name DROP PRIMARY KEY  ALTER TABLE [schema].table_name ALTER [COLUMN] column_name SET default_expr  ALTER TABLE [schema].table_name ALTER [COLUMN] column_name DROP DEFAULT

Alter Table To add primary key and foreign key constraint to the employee table ALTER TABLE employee ADD CONSTRAINT pk_emp PRIMARY KEY (ssn);

DROP TABLE COMMAND To delete complete table use drop command Syntax – DROP TABLE [schema].table_name

DROP TABLE COMMAND To delete complete table use drop command Syntax – DROP TABLE [schema].table_name

Truncate Command Use to remove all the rows from the table Syntax – TRUNCATE TABLE [schema].table_name

Inserting data into a table To add a row of data to a table INSERT INTO VALUES (value1, value2, …valueN) If the value list matches the column list exactly, there is no need to list the column names. If the value list does not match the column list exactly, there is a need to list the column names.

Example insert into Expert values ( ,'Dr. O‘’Meara’,'Orthopaedic');

Delete Delete from expert where expert_id = ; This deletes all rows from the expert table that have an expert_id of Please note that you can only delete a row if no other row depends on it.