1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.

Slides:



Advertisements
Similar presentations
A Guide to Oracle9i1 Creating and Modifying Database Tables Chapter 2.
Advertisements

Session 2Introduction to Database Technology Data Types and Table Creation.
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.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
1 Chapter 2: Creating and Modifying Database Tables.
Guide to Oracle 10g1 Chapter 2: Creating and Modifying Database Tables.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Creating Database Tables © Abdou Illia MIS Spring /21/2015.
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.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
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.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
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 Chapter 2: Creating and Modifying Database Tables.
Oracle Data Definition Language (DDL)
Copyright © Curt Hill SQL The Data Definition Language.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
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.
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.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
CSC 2720 Building Web Applications Database and SQL.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Sizing Basics  Why Size?  When to size  Sizing issues:  Bits and Bytes  Blocks (aka pages) of Data  Different Data types  Row Size  Table Sizing.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1 Creating and Modifying Database Objects. 2 An Oracle database consists of multiple user accounts Each user account owns database objects Tables Views.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
CS 3630 Database Design and Implementation. Assignment 3 Style! Agreement between database designer and the client. UserName1_EasyDrive UserName2_EasyDrive.
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.
LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat.
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
Creating Tables and Inserting Records -- Not easy to edit! -- check constraints! Create table test1 ( C1 char(5) primary key, C2 Varchar2(15) not null.
ITBIS373 Database Development Lecture 2 - Chapter 2 Creating And Modifying Database Tables.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
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.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Data types  CHAR (size): This data type is used to store character strings values of fixed length. The size in brackets determines the number of characters.
Lecture5: SQL Overview, Oracle Data Type, DDL and Constraints Ref. Chapter6 Lecture4 1.
8 Copyright © 2004, Oracle. All rights reserved. Managing Schema Objects.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
1 Chapter 2: Creating and Modifying Database Objects.
Sql DDL queries CS 260 Database Systems.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
Oracle 9i. Agenda Start and exit SQL Plus (General) Start and exit SQL Plus (Tah 1006) Syntax Create a new user Create a new table Enter data into a new.
Academic Year 2015 Autumn. MODULE CC2006NI: Data Modelling and Database Systems Academic Year 2015 Autumn.
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.
Basic SQL*Plus edit and execute commands SQL*Plus buffer and built-in editor holds the last SQL statement Statements are created in free-flow style and.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Creating and Managing Tables. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets.
3 A Guide to MySQL.
CIT 214 Introduction to Database Management
Guide to Oracle 10g Chapter 2: Creating and Modifying Database Tables.
CS 3630 Database Design and Implementation
Managing Tables, Data Integrity, Constraints by Adrienne Watt
SQL and SQL*Plus Interaction
TOPIC 6 RELATIONAL DATABASE LANGUAGE - SQL WENNY RAHAYU
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
ORACLE SQL Developer & SQLPLUS Statements
Relational Database Language - SQL
SQL data definition using Oracle
Oracle Data Definition Language (DDL)
Chapter 2: Creating And Modifying Database Tables
Introduction to Oracle
SQL (Structured Query Language)
Presentation transcript:

1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2

2 Creating and Modifying Database Tables 2  Query: Command to perform database operation  insert  modify  delete  view  Structured Query Language (SQL)  Standard query language for relational databases

3 Oracle Database Tables  Table specifications  table name  field names  field data types  field sizes  field constraints 2

4 Oracle Table and Field Names 2  1-30 characters  Alphanumeric characters and restricted symbols $ _ #  Must begin with a character  Cannot be a reserved word

5 Oracle Data Types  Data type: Specifies type of data stored in a field  Error checking  Efficient use of storage space 2

6 Character Data Types 2  VARCHAR2  Variable-length character strings  Maximum of 4,000 characters  Must specify maximum width allowed  No trailing blank spaces are added  Example declaration: student_name VARCHAR2(30)

7 Character Data Types  CHAR  Fixed-length character data  Maximum size 255 characters  Must specify maximum width allowed  Adds trailing blank spaces to pad width  Example declaration: s_gender CHAR(1) 2

8 Character Data Types 2  NCHAR  Supports 16-digit binary character codes  Used for alternate alphabets  LONG  Stores up to 2 GB of variable-length character data  Each table can have only one LONG field

9 Number Data Type  NUMBER  Stores values between and  General declaration format: variablename NUMBER(precision, scale) 2

10 Number Data Type  Number type (integer, fixed point, floating point) specified by precision and scale  Precision: Total number of digits on either side of the decimal point  Scale: Number of digits to right of decimal point 2

11 Integer Numbers  Whole number with no digits to right of decimal point  Precision is maximum width  Scale is omitted  Sample declaration: s_age NUMBER (2) 2

12 Fixed-Point Numbers  Contains a specific number of decimal places  Precision is maximum width  Scale is number of decimal places  Sample declaration: item_price NUMBER(5, 2) 2

13 Floating-Point Numbers  Contains a variable number of decimal places  Precision and scale are omitted  Sample declaration: s_GPA NUMBER 2

14 Date Data Type  DATE  Stores dates from 1/1/4712 BC to 12/31/4712 AD  Default date format: DD-MON-YY  Example: 05-JUN-01  Sample declaration: s_dob DATE 2

15 Date Data Type 2  DATE data type also stores time values  If no time value is given when a date is inserted, default value is 12:00:00 AM  If no date value is given when a time is inserted, default date is first day of current month

16 Large Object (LOB) Data Types  BLOB: Binary LOB, up to 4 GB of binary data in database  CLOB: Character LOB, up to 4 GB of character data in database  BFILE: Reference to binary file stored in operating system  NCLOB: Character LOB supporting 16-bit character codes 2

17 Format Masks 2  Specify input and output formats for data values  Common NUMBER format masks Format MaskFormatted Data 99,99912,345 $99,999.99$12, ,999PR 99,999MI-12,345 $99,999.99PR

18 Format Masks  Common DATE format masks Format MaskFormatted Data DD-MON-YY05-JUN-01 DD-MON-YYYY05-JUN-2001 MM/DD/YY06/05/2001 HH:MI AM02:30 PM MONTH DAY, YYYYJUNE 5, 2001 MM/DD/YY HH:MI AM06/05/01 02:30 PM 2

19 Format Masks 2  Common character format masks with embedded characters Format MaskFormatted Data  Social Security Number: FM999”-”999”-”  Phone Number: FM”(“999”) “999”-”9999(715)

20 Integrity Constraints  Used to define primary and foreign keys  Constraint name: Internal name used by DMBS to identify the constraint  Constraint name convention:  tablename_fieldname_constraintID  Constraint ID values:  Primary key: PK  Foreign key: FK 2

21 Primary Key Constraints  Defining a primary key: CONSTRAINT PRIMARY KEY  Example: sid NUMBER(6) CONSTRAINT student_sid_pk PRIMARY KEY 2

22 Primary Key Constraints  Defining a composite primary key: CONSTRAINT PRIMARY KEY (field1, field2)  Example: sid NUMBER(6), course_id NUMBER(6), grade NUMBER, CONSTRAINT enrollment_sid_course_id_pk PRIMARY KEY (sid, course_id) 2

23 Foreign Key Constraints  Defining a foreign key: CONSTRAINT REFERENCES ( )  Example: advisorid NUMBER(6) CONSTRAINT student_advisorid_fk REFERENCES faculty(fid) 2

24 Value Constraints  Restricts data values that can be inserted into a field  Types  Check condition: Restricts to specific values  example: s_gender (M or F)  NOT NULL: Specifies that a field cannot be NULL 2

25 Defining Value Constraints  Check condition  CONSTRAINT CHECK s_gender CHAR(1) CONSTRAINT student_s_gender_cc CHECK ((s_gender = ‘M’) OR (s_gender = ‘F’))  Not NULL  CONSTRAINT NOT NULL s_name VARCHAR2(30) student_s_name_nn NOT NULL 2

26 SQL*Plus 2  Oracle SQL command line utility  Starting SQL*Plus

27 SQL*Plus 2  All commands must be terminated with a semicolon  Use a text editor and copy and paste commands  Character data is case sensitive and must be in single quotes ‘M’ ‘Sarah’

28 Creating a Database Table  CREATE TABLE (, <field2 declaration, …); CREATE TABLE mystudent (sid NUMBER(6) CONSTRAINT mystudent_sid_pk PRIMARY KEY, s_name VARCHAR2(30) CONSTRAINT mystudent_s_name_nn NOT NULL); 2

29 Other Table Operations  Viewing a table’s structure DESCRIBE mystudent;  Viewing constraint information SELECT CONSTRAINT_NAME FROM USER_CONSTRAINTS WHERE TABLE_NAME = ‘MYSTUDENT’ ;  Deleting a table DROP TABLE mystudent; 2

30 Modifying Tables  Prohibited  Changing the table name  Changing a column name  Unrestricted  Adding a new column  Deleting a primary key or foreign key constraint 2

31 Modifying Tables  Restricted (allowed only if existing data fits new specification)  Changing a column’s data type, size, and default value  Adding a primary key constraint  Adding a foreign key constraint  Adding a CHECK CONDITION constraint  Adding a NOT NULL constraint 2

32 Exiting SQL*Plus  Type exit at SQL> prompt or  Click Close button 2