CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP...

25
CS 3630 Database Design and Implementation

Transcript of CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP...

Page 1: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

CS 3630 Database Design and Implementation

Page 2: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Your Oracle Account• UserName is the same as your UWP username• Followed by @EDDB• Not case sensitive

• Initial Password: UWPUserName1 (all lower case)

Example: yangq1• Password is case sensitive

• Reset password• Email to HelpDesk at [email protected] from

your UWP email account if you forget your new password

2

Page 3: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Oracle Client SQL*Plus

• SQL*Plus

• Oracle 11.2.0.1.0

• All labs in Ullrich Hall

• Not available from home or any other lab on campus

3

Page 4: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Structured Query Language (SQL)

• One language for Relational Databases

• ANSI Standard

• Oracle: SQL*Plus

• MS SQL Server: Transact-SQL

• IBM DB2

• MySQL

• Sybase

...4

Page 5: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Structured Query Language (SQL)

• Case insensitive (like VB)• Free style (like C++ and Java)• Statement terminator – semicolon (like C++ and Java)• Programming Rule: Style

Each clause of a query on a separate line• When creating tables

Each field on a separate line

Each table constraint on a separate line

5

Page 6: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Structured Query Language (SQL)

• DDL (Data Definition Language)

Create Table (user) ...

Drop Table (user) ...

Alter Table (user) ...

• DML (Data Manipulation language)

Select * From Branch …

Insert into Branch ...

Update branch ...

Delete from BRANCH ... 6

Page 7: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Change Your Oracle Passwordinside Oracle

-- Oracle Command Prompt

SQL>

-- Change your password

-- Remember your new password!

SQL> Alter User yourUserName identified by newPassword;

-- Every ANSI SQL standard command ends with ;

7

Page 8: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Oracle Data Types

• Char(size)

fixed length string

up to 2000 bytes

default is 1 byte

blanks are padded on right when fewer chars entered

• Varchar2(size)

variable size string

up to 2000 bytes

must specify the limit (size)

• Varchar(size)

same as Varchar2(size)

better to use Varchar2

8

Page 9: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Oracle Data Types

• Integer, int, smallint

• Float

• Date

Valid dates from 1-Jan-4712 B.C. to 31-Dec-4712 A.D.

Default format: DD-MON-YY

23-Mar-09

Including time

9

Page 10: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Oracle Data Types

• Number(l, d) l: length (total) d: decimal digits number (5, 2): largest value is 999.99 • Decimal(l, d), Numeric(l, d) same as number(l, d) SQL standard • blob: binary large object, up to 4 GB• clob: character large object, up to 4 GB• raw(size): raw binary data, up to 2000 bytes • ...

10

Page 11: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Create a Table

SQL> Create Table Test1 (

C1 char(5) Primary Key,

C2 Varchar2(50),

C3 Integer,

C4 Date);

11

Page 12: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Show Table Schema

SQL> Describe Test1

Or

SQL> Desc Test1

Describe is a SQL*Plus command and no semicolon is required.

12

Page 13: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Insert Records

Insert into Test1

Values (‘cs363', ‘s1', 44, ‘28-feb-12’);

Insert into Test1

Values (‘cs334', ‘s2', 45, ‘29-feb-12’);

One record at a time!

Single quotes for string

Date is entered as string

in the default format

13

Page 14: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Retrieve Records

Select * From test1;

-- Each clause on a separate line

Select *

From Test1;

-- to start a comment line

14

Page 15: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Entity Integrity

Insert into Test1

Values (‘cs363', ‘q2', 17, ‘2-Mar-12’);

PK must be Unique!

15

Page 16: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Null Values

Insert into Test1

Values (‘cs387', ‘q2', 17, null);

Null is a key word, not a string!

NULL, null and Null are the same

SQL is not case sensitive

16

Page 17: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Entity Integrity

Insert into Test1

Values (null, ‘q2', 17, ‘2-Mar-12’);

PK cannot be null!

17

Page 18: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Command Commit

• DDL commands are sent back to server and executed there

• DML commands are executed at client site

• Use commit to send results back to server

18

Page 19: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Update Records

Update test1

Set c3 = 50

Where c1 = ‘cs363’;

-- Each clause on a separate line

19

Page 20: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Delete Records

Delete from test1

Where c1 = ‘cs363’;

-- select to check

Delete from test1;

-- select to check

-- desc to check

20

Page 21: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Drop Table

Drop table test1;

Desc test1

-- to check

ERROR:

ORA-04043: object test1 does not exist

21

Page 22: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Log out

SQL> exit

22

Page 23: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Remember Your Password!

23

Page 24: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Quiz2

Any Questions?

24

Page 25: CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed by @EDDB Not case sensitive Initial.

Assignment62

Any Questions?

25