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.

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.
CC SQL Utilities.
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.
Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Chapter 6 SQL. Agenda Data Definition Language (DDL) Access Control.
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
1 Chapter 2: Creating and Modifying Database Tables.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Creating Database Tables © Abdou Illia MIS Spring /21/2015.
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.
Concepts of Database Management Sixth Edition
Database Management System LICT 3011 Eyad H. Elshami.
SQL Query Extras MIS 433. Rerunning the last Query n Type the forward slash “/” to rerun the last query that was entered.
Chapter 6 SQL. Agenda Data Definition Language (DDL) Access Control.
ORACLE Using ORACLE 8 SQL using ORACLE 8 PL/SQL using ORACLE 8.
Oracle Data Definition Language (DDL)
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
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.
Concepts of Database Management Seventh Edition
1 Creating and Modifying Database Objects. 2 An Oracle database consists of multiple user accounts Each user account owns database objects Tables Views.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
CS 3630 Database Design and Implementation. Assignment 3 Style! Agreement between database designer and the client. UserName1_EasyDrive UserName2_EasyDrive.
1 A Guide to SQL Chapter 2. 2 Introduction Mid-1970s: SQL developed under the name SEQUEL at IBM by San Jose research facilities to be the data manipulation.
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.
Personal Oracle8i Create a new user Create a new table Enter data into a new table Export & import data Start and exit SQL Plus SQL Plus Syntax.
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.
1 PL\SQL Dev Templates. 2 TEMPLATE DEFINITION Whenever you create a new program unit, its initial contents are based upon a template which contains pre-defined.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Chapter 6 SQL. Agenda Data Definition Language (DDL) Access Control.
1 Chapter 2: Creating and Modifying Database Objects.
Sql DDL queries CS 260 Database Systems.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Personal Oracle8i Create a new user Create a new table Enter data into a new table Export & import data Start and exit SQL Plus SQL Plus Syntax.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
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.
Installation Oracle 11g Express 2 double click the "setup" button to install the Oracle.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CSE 4701 Chapter 10-1 Chapter 10 6e: Oracle Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut 191.
Dept. of Computer & Information Sciences
3 A Guide to MySQL.
CIT 214 Introduction to Database Management
CS 3630 Database Design and Implementation
SQL and SQL*Plus Interaction
Using SQL*Plus.
Using SQL*Plus.
ORACLE SQL Developer & SQLPLUS Statements
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
SQL data definition using Oracle
Oracle Data Definition Language (DDL)
Chapter 2: Creating And Modifying Database Tables
Using SQL*Plus.
Wings 2.0 Business Flow Reference
Presentation transcript:

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 table Export & import data

Start and Exit SQL Plus Start SQL Plus –Start –Select Program –Select Oracle-ORACLE_9i –Select Application Development –Select SQL Plus –Enter your name for User Name (system) –Enter Enter your password for Password (manager) Exit SQL Plus –Type exit at SQL prompt

Start and Exit SQL Plus (Tah 1006) Start Database –Start the computer –Wait for couple minutes –Select Oracle-XP-SP1 –Press Enter for password (no password is needed) –Double clicks the SQL Plus icon –Enter your name for User Name (system) –Enter your password for Password (manager) Exit SQL Plus –Type exit at SQL prompt –Close the database window

Syntax - General Use semicolon (;) to terminate a statement SQL is not case-sensitive SQL statement can be entered into several lines Use comma (,) to separate attributes Use a pair of single quotes (‘) for any character string Use a pair of double quotes (“”) for a single (‘) character string

Syntax - General Use percentage sign (%) for a group of wildcard characters Use underscore (_) for one wildcard character Escape character –Select…from….where city like ‘%s/_f%’ escape ‘/’; –Underscore _ after / will be interpreted as a regular meaning underscore Subquery must be enclosed in a pair of parentheses

Syntax - Name Table name or attribute name limited to 30 characters (characters, number, special symbols $, _, and #) Name has to begin with a character No blank Not case sensitive No reserved word

Syntax - Data Types Characters –Varchar2(n): max 4,000 characters (ASCII, 8-digit) –Char(n): max 2,000 characters (ASCII, 8-digit) –Nvarchar2(n): as char (Unicode, 16-digit) –Nchar(n): as char (Unicode, 16-digit) Numbers –Integer: number(n) –Fixed-point: number(5,2), –Floating-point: number

Syntax - Data Types Date –Date:DD-MMM-YY HH:MI:SS –Timestamp (fractional seconds precision) with 6 as default value Large object (LOB): max 4 gigabytes for digitized sounds, images, and binary files

Syntax - Editor L or LIST - displays most current SQL statements from buffer Line number - changes the current line number to the entered line number and shows the listed line number LIST line number or nn nn - show the indicated line number text or between the nn and nn

Syntax - Editor A or APPEND text - adds the entered text to the end of the current line I or INPUT text – create a new line after the current line C or CHANG/old text/new text/ - replaces an existing text string (old text) in the line with a new text string (new text) DEL or DELETE - deletes the current line START filename – execute the contents of the SQL Plus command file

Syntax - Editor SAVE file name - saves the most current SQL statements to a file (filename.sql) GET file name - retrieves SQL statements from the file name (filename.sql) R or / - runs the most current statements SPOOL file name - saves SQL statements, its query, and other results to a file SPOOL OFF - terminates SPOOL

Spool File - Menu SPOOL file –Select File –Select Spool –Select Spool file –Type drive (such as a:) –Type file name (such as f1) –Select spool file (*.lst) SPOOL off –File –Spool –Spool off

Save File Menu Select File Select Save –Select Create to create a *.sql file –Select Replace to replace a *.sql file –Select Append to append a *.sql file

Syntax - View Table Structure View all tables –SELECT TABLE_NAME FROM USER_TABLES; –SELECT TABLE_NAME FROM ALL_TABLES; View field definitions of a table –DESCRIBE table name –DESCRIBE student; View all constraints of a table –SELECT CONSTRAINT_NAME, TABLE_NAME, CONSTRAINT_TYPE FROM USER_CONSTRAINTS; –SELECT CONSTRAINT_NAME, CONSTRAINT_TYPE FROM USER_CONSTRAINTS WHERE TABLE_NAME = ‘student’;

Oracle Constraint Type Identifier Primary key: p Foreign key: r Check condition: c Not null: n Unique: u

Error Message Type for the Internet addresshttp://otn.oracle.com Click ‘Search’ Check ‘Oracle Technology Network Documentation’ box Type ‘ORA-error messages’ in the search field Click ‘Search icon’

Create A New Table CREATE TABLE student (stuid char(5) NOT NULL, stuname char(10), major char(10), credit number(3), CONSTRAINT pkstudent PRIMARY KEY (stuid));

Create A New Table CREATE TABLE faculty (facid char(5) NOT NULL, facname char(10), dept char(10), rank char(10) check (rank in (‘F’,’Aso’, ‘Ast’)), CONSTRAINT pkfaculty PRIMARY KEY (facid));

Create A New Table CREATE TABLE class (course# char(5) NOT NULL, facid char(5), sched char(10), room char(10), CONSTRAINT pkclass PRIMARY KEY (course#), CONSTRAINT fkclassfaculty FOREIGN KEY (facid) REFERENCES faculty (facid));

Create A New Table CREATE TABLE enrollment (course# char(5) NOT NULL, stuid char(5) NOT NULL, grade char(10), CONSTRAINT pkenroll PRIMARY KEY (course#, stuid), CONSTRAINT fkenrollclass FOREIGN KEY (course#) REFERENCES class (course#), CONSTRAINT fkenrollstudent FOREIGN KEY (stuid) REFERENCES student (stuid));

Delete A Record or A Table DELETE FROM tablename –DELETE FROM student; DROP TABLE tablename –DROP TABLE student;

Create A New User CREATE USER username IDENTIFIED BY password –CREATE USER tsai IDENTIFIED BY tsai GRANT privilege1, privilege2,…TO username or role name –GRANT CREATE USER, CREATE TABLE, DROP TABLE TO tsai; (current user’s schema – user level) GRANT role name TO username –GRANT DBA TO tsai; (any user’s schema –DBA level)

Delete An User REVOKE privilege FROM role name –REVOKE CREATE USER form tsai; REVOKE role name FROM username –REVOKE DBA from tsai; DROP USER username –DROP USER tsai;

Input Data Into A Table The ampersand (&) signal the SQL compiler to prompt the user for a value that is then substituted into the query &prompt_variable is the name of the attribute for which the user is prompted to specify a value Example INSERT INTO student VALUES (&stuid, &stuname, &major, &credit);

Load Data Into A Table Tsaitest.dat file contains 11111,Ching,MIS, ,Anderson,MIS, ,Martin,ACT,300 Tsaitest.ctl contains –LOAD DATA –INFILE ‘tsaitest.dat’ –APPEND –INTO TABLE student –FIELDS TERMINATED BY ‘,’ –(stuid, stuname, major, credit) The following command should be issued in command line –SQLLDR USERID=tsai/tsai CONTROL= tsaitest.ctl LOG=tsaitest.LOG Tsaitest.dat, tsaitest.ctl, and tsaitest.log have to be in the same directory such as C:

Export Data Program MS-DOS Prompt Type exp user name/password (such as exp nancy/nancy) Specify export file (such as a:extf1.dmp where a: is the drive) Answer the questions to execute the expert program

Import Data Program MS-DOS Prompt Type imp user name/password (such as imp nancy/nancy) Specify Import file name (such as a:extf1.dmp) Answer the questions to execute the import program

Process for Oracle Homework Use notepad to prepare the sql codes for creating tables, data, problems, and control files Save each control file in an individual file with the ctl as file extension Save each table data in an individual file with the dat as the file extension Use copy and paste to move the sql codes of create table from notepad to oracle then press / to run Copy every data file and control file in the root of C drive

Process for Oracle Homework Type sqlldr statement at C:> to load the data into each table (one at the time) Use copy and paste to move the sql codes of problem from notepad to oracle then press / to run Use save command to store the sql solution for each problem Use spool to put every problem together Use get command to get the saved solution of each problem and press / to run Use spool off to turn off the spooling Use Word to add the question before each solution and print the saved spool file

Process for Oracle Homework Use Imp and exp to import and export records and tables between each work session