Creating and Managing Tables. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets.

Slides:



Advertisements
Similar presentations
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Advertisements

9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Data Definition Language (DDL)
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
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,
Oracle Data Definition Language (DDL)
Structured Query Language S Q L. What is SQL It is a database programming language developed by IBM in the early 1970’s. It is used for managing and retrieving.
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.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Copyright © 2004, Oracle. All rights reserved. Lecture 3: Creating Other Schema Objects Lecture 3: Creating Other Schema Objects ORACLE.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2006, 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 (DDL & DML Commands)
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
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
10 Creating and Managing Tables Objectives At the end of this lesson, you will be able to: Describe the main database objects Create tables Describe.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
10-1 Copyright  Oracle Corporation, All rights reserved. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
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.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
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. 11 Including Constraints.
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.
Copyright  Oracle Corporation, All rights reserved. 4 Introduction.
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.
INCLUDING CONSTRAINTS lecture5. Outlines  What are Constraints ?  Constraint Guidelines  Defining Constraint  NOT NULL constraint  Unique constraint.
8 Copyright © 2007, Oracle. All rights reserved. Managing Schema Objects.
Lecture5: SQL Overview, Oracle Data Type, DDL and Constraints Ref. Chapter6 Lecture4 1.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
Copyright © 2004, Oracle. All rights reserved. Lecture 2: Using DDL Statements to Create and Manage Tables & Indexes ORACLE.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
DDL and Views. Database Objects Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage;
Creating and Managing Tables 14. ObjectivesObjectives After completing this lesson, you should be able to do the following: After completing this lesson,
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
Database Programming Sections 9 & 10 – DDL Data Definition Language,
Chapter 3 Table Creation and Management Oracle 10g: SQL.
Installation Oracle 11g Express 2 double click the "setup" button to install the Oracle.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
SQL Statements SELECT INSERTUPDATEDELETECREATEALTERDROPRENAMETRUNCATECOMMITROLLBACKSAVEPOINTGRANTREVOKE Data Retrieval Language (DRL) Data Retrieval Language.
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
TABLES AND INDEXES Ashima Wadhwa.
Using DDL Statements to Create and Manage Tables
Including Constraints
Insert, Update and the rest…
SQL Creating and Managing Tables
Using DDL Statements to Create and Manage Tables
ORACLE SQL Developer & SQLPLUS Statements
SQL Creating and Managing Tables
SQL Creating and Managing Tables
SQL data definition using Oracle
SQL Statements SELECT INSERT UPDATE DELETE CREATE ALTER DROP RENAME
Oracle Data Definition Language (DDL)
Session - 6 Sequence - 1 SQL: The Structured Query Language:
IST 318 Database Administration
Creating and Managing Tables
Presentation transcript:

Creating and Managing Tables

Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets of data from one or more tables Sequence Numeric value generator IndexImproves the performance of some queries SynonymGives alternative names to objects

The CREATE TABLE Statement CREATE TABLE tablename (column datatype [DEFAULT expr][,...]); You specify: – Table name – Column name, column data type, and column size DEFAULT expr specifies a default value if a value is omitted in the INSERT statement

Naming Rules Table names and column names: Must begin with a letter Must be 1 to 30 characters long Must contain only A–Z, a–z, 0–9, _, $, and # Must not duplicate the name of another object owned by the same user Must not be an Oracle Server reserved word Note: Names are not case sensitive. For example, EMPLOYEES is treated as the same name as eMPloyees or eMpLOYEES.

Creating Tables Create the table. CREATE TABLE dept (deptno NUMBER(2), dname VARCHAR2(14), loc VARCHAR2(13)); Table created. Confirm creation of the table. DESCRIBE dept

Data Types Data typeDescription VARCHAR2(size) Variable-length character data (a maximum size must be specified: min1 max 4000 CHAR [(size)] Fixed-length character data (Min size is 1 max size is 2000) NUMBER [(p,s)] Number having precision p and scale s (The precision is the total number of decimal digits and the scale is the number of digits to the right DATEDate and time values to the nearest second LONG Variable-length character data up to 2 gigabytes CLOBCharacter data up to 4 gigabytes

The ALTER TABLE Statement Use the ALTER TABLE statement to: Add a new column Modify an existing column Define a default value for the new column Drop a column

The ALTER TABLE Statement Use the ALTER TABLE statement to add, modify or drop columns. – ALTER TABLE table ADD (column datatype [DEFAULT expr] [, column datatype]...); – ALTER TABLE table MODIFY (column datatype [DEFAULT expr] [, column datatype]...); – ALTER TABLE table DROP COLUMN columnname;

Adding a Column Use the ADD clause to add columns. ALTER TABLE dept80 ADD (job_id VARCHAR2(9)); The new column becomes the last column

Modifying a Column You can change a column’s data type, size, and default value. ALTER TABLE dept80 MODIFY (last_name VARCHAR2(30)); A change to the default value affects only subsequent insertions to the table You can decrease the width of a column only if the column contains only null values or if the table has no rows. You can change the data type only if the column contains null values.

Dropping a Column Use the DROP COLUMN clause to drop columns you no longer need from the table. ALTER TABLE dept80 DROP COLUMN job_id; The column may or may not contain data. Using the ALTER TABLE statement, only one column can be dropped at a time. The table must have at least one column remaining in it after it is altered. Once a column is dropped, it cannot be recovered

Dropping a Table All data and structure in the table is deleted. You cannot roll back the DROP TABLE statement. DROP TABLE dept80;

Truncating a Table The TRUNCATE TABLE statement: – Removes all rows from a table – Releases the storage space used by that table TRUNCATE TABLE detail_dept; You cannot roll back row removal when using TRUNCATE. Alternatively, you can remove rows by using the DELETE statement. If the table is the parent of a referential integrity constraint, you cannot truncate the table. Disable the constraint before issuing the TRUNCATE statement.

Exersises. Create the DEPT table based on the following table instance chart. Place the syntax in a script called lab_1.sql, then execute the statement in the script to create the table. Confirm that the table is created. Modify the DEPT table to allow for longer employee last names. Confirm your modification Empty the table. Column Name ID name Data typeNUMBERVARCHAR2 Length 725