SQL Tutorial CPSC 608 Database System. Connecting to Oracle Your username is identical to your UNIX account To access your Oracle account, you need to.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Advertisements

CC SQL Utilities.
Virtual training week 4 structured query language (SQL)
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
Introduction to Structured Query Language (SQL)
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Oracle Data Definition Language (DDL)
Introduction to SQL J.-S. Chou Assistant Professor.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
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.
Introduction to MySQL Lab no. 10 Advance Database Management System.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Concepts of Database Management Seventh Edition
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
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.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
SQL ACTION QUERIES AND TRANSACTION CONTROL CS 260 Database Systems.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
A Guide to SQL, Sixth Edition 1 Chapter 5 Updating Data.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Dept. of Computer & Information Sciences
3 A Guide to MySQL.
Fundamentals of DBMS Notes-1.
CS 3630 Database Design and Implementation
Chapter 5 Introduction to SQL.
SQL and SQL*Plus Interaction
Chapter 1 Introduction.
SQL in Oracle.
JDBC.
Using SQL*Plus.
ORACLE SQL Developer & SQLPLUS Statements
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
Chapter 1 Introduction.
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
Oracle Data Definition Language (DDL)
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Chapter 1 Introduction.
Contents Preface I Introduction Lesson Objectives I-2
Chapter 2: Creating And Modifying Database Tables
Using SQL*Plus.
Introduction to Oracle
SQL (Structured Query Language)
Presentation transcript:

SQL Tutorial CPSC 608 Database System

Connecting to Oracle Your username is identical to your UNIX account To access your Oracle account, you need to change the initial password assigned to by the system To access Oracle you need to be logged onto a Solaris 2.5 workstation You need to add the following line : source /usr/local/bin/SystemLogin in your.login file

Connecting to Oracle To generate a new password, enter the command “orapasswd” at the unix prompt. This program will generate a new Oracle password for you > orapasswd The new password for is WU8vn23r

Connecting to Oracle When connecting to SQL use the full Oracle login as given by the orapasswd command as follows: >sqlplus SQL*Plus: Release Production on Wed Feb 9 18:54: (c) Copyright 1999 Oracle Corporation. All rights reserved. Enter user-name: Enter password: Connected to: Oracle8i Enterprise Edition Release Production With the Partitioning and Java options PL/SQL Release Production SQL>

Connecting to Oracle You can change the password to your own liking by typing the following command at the command prompt SQL> alter user identified by You are now ready to begin work in SQL environment To exit just type quit or exit at the command prompt SQL> exit Note: When a user exits the system automatically commits all changes

On line help Oraview online help in Xwindows environment At the prompt the user can enter two types of command SQL statements to access database SQL*Plus commands,for editing and storing SQL statements and formatting query results. To get online help for SQL*Plus commands SQL> help [topic]

Some Useful SQL commands To set pause at the beginning of the each page SQL> set pause on; To view operating system files without getting out of SQL SQL>!ls

Database Relation/Table Operations Create table describe alter table insert into drop table

Create table create table Course( Cnochar(3) not null, Cnamevarchar2(22), Cdescpvarchar2(25), Crednumber(5), Clabfeenumber(5,2), Cdeptchar(3) );

Important Data type char(n):fixed -length character string of length n. Max = 255 varchar2(n): variable length character string having a maximum of n characters. Max = 2000 date: holds a date field. Usually specified in string format, such as ‘12 - DEC- 1999’ number(n,d): real value occupying n spaces with d digits after the decimal point. Integer(n): integer value occupying n spaces.

Example create table Weather( cityvarchar2(13), noon number(3,1), midnightnumber(3,1), precipitationnumber, primary key(city,precipitation) ); create table Zipcodes( zipnumber(5) primary key, cityvarchar2(30) );

Example create table Customer( cnonumber(5) primary key, cnamevarchar2(30), streetvarchar2(30), zipnumber(5) refference zipcodes, phonechar(12) );

describe SQL> create table Course( Cno char(3) not null, Cname varchar2(22), Cdescp varchar2(25), Cred number(5), Clabfee number(5,2), Cdept char(3) ); Table created. SQL> describe Course Name Null? Type CNO NOT NULL CHAR(3) CNAME VARCHAR2(22) CDESCP VARCHAR2(25) CRED NUMBER(5) CLABFEE NUMBER(5,2) CDEPT CHAR(3)

Table Modifying Alter table Course modify( Cdeptchar(6) ); alter table Course drop Cdescp; drop table Course; To see the list of all the tables that you have created select table_name, table_type from user_catalog; To insert a row into a table insert into Course values (‘614’, ‘Computer Architecture’, ‘Pipelining and memory’, 3,150.00, ‘th’);

Deletion To delete a particular row from the table delete from Course where Cname = ‘intro to cs’ To update a particular column value for a particular row update Course set Clabfee = clabfee*10 where cdept = ‘phil’

The select statement Basic form select from where

SQL queries Query 1: Display entire course table. Select * from Course;

Note The changes made to the database using insert, delete and update can be reversed if necessary. Oracle SQL provides two commands : Commit & rollback. The changes made to the database can be made permanent by using commit. The changes made to the database since last commit can be reversed using roll back. There are some actions that force commit. One is exit. Others are create table, drop table, alter table

Comparison Operators = equal to < less than > greater than <= less than or equal to >= greater than or equal to !=, ^=,<> not equal

Query Display all information about any course with a zero labfee. Select * from Course where Clabfee=0.00

Query Display all information about courses having course name values which follows “Database” in alphabetic sequence. select * from course where Cname > ‘Database’;

Sorting the result Table Display the entire Course table. Sort the output display by the clabfee values select * from Course order by Clabfee;

Sorting the result Table Display the department id and name of every course. Sort the result by department id. Within each department, sort by course name. Select Cdept, Cname from Course order by Cdept, Cname;

Boolean Connectors: AND - OR - NOT Display all information about any three credit philosophy course which has a lab fee which is strictly between zero and one hundred dollars. Select * from Course where Clabfee > 0 and Clabfee < 1000 and Cdept = ‘phil’ and Cred = 3;

Logical test against a list of values Display the course number, description and credit for any course which is worth 2, 6, or 9 credits. Select Cno, Cdescp, Cred from Course where Cred in (2,6,9);

Logical test against a list of values Display the course name and lab fee of any course with a lab fee less than $100 or greater than $200. Select Cname, Clabfee from Course where Clabfee not between 100 and 200;

Pattern Matching When you wish to retrieve information from rows having similar but not necessarily equal, values in a given column. The format is: where column-name like pattern Two special wildcard “-” : represent exactly one character “%” : represent character string of any length (including zero)

Query Display the course number and name of all introductory course. Select Cno, Cname from Course where Cname like ‘intro%’;