1 very basics on db access elke a. rundensteiner

17
1 Very basics on DB access Elke A. Rundensteiner

Upload: patrick-hunter

Post on 13-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Very basics on DB access Elke A. Rundensteiner

1

Very basics on DB access

Elke A. Rundensteiner

Page 2: 1 Very basics on DB access Elke A. Rundensteiner

2

DBMS?

Oracle Accounts already created Documentation: http://www.oracle.com

mySQL: To create an account, visit http://www.wpi.edu/Academics/CCC

Documentation: http://www.mysql.com Many other DBMS engines out there

Page 3: 1 Very basics on DB access Elke A. Rundensteiner

3

Oracle Version at WPI

The oracle server SID is WPI11GR2 (or, CS) Version: 11g 11.2.0.3.0 (64 bit version) System name is oracle.wpi.edu port is #1521

Problems: user names cannot have a “.” in them.

Page 4: 1 Very basics on DB access Elke A. Rundensteiner

How to set up path for Oracle

If you use CCC linux systems, then you need to source /usr/local/bin/csoraenv file to setup your shell to use oracle

On CCC, if your shell is set to /bin/tcsh, then run :

source /usr/local/bin/csoraenv On CCC, if your shell is set to /bin/bash, then run : source /usr/local/bin/oraenv To figure out what the type of shell that you use, type:

echo $SHELL From your shell prompt, type : echo $PATH

4

Page 5: 1 Very basics on DB access Elke A. Rundensteiner

5

How to set up Oracle Or, set environment variables by adding the needed

settings into your .cshrc file on the ccc.wpi.edu machine (which gets sourced automatically when you log on).

setenv ORACLE_BASE /usr/local/oracle11gr203setenv ORACLE_HOME /usr/local/oracle11gr203/product/11.2.0/db_1

setenv PATH ${PATH}:${ORACLE_HOME}/binsetenv ORACLE_SID WPI11GR2 setenv TWO_TASK ${ORACLE_SID}

Page 6: 1 Very basics on DB access Elke A. Rundensteiner

6

How to set up Oracle Or, set environment variables by adding the needed

settings into your .cshrc file on the ccc.wpi.edu machine (which gets sourced automatically when you log on).

setenv ORACLE_BASE /usr/local/oracle11gr203setenv ORACLE_HOME /usr/local/oracle11gr203/product/11.2.0/db_1

setenv PATH ${PATH}:${ORACLE_HOME}/binsetenv ORACLE_SID WPI11GR2 setenv TWO_TASK ${ORACLE_SID}

Page 7: 1 Very basics on DB access Elke A. Rundensteiner

7

How to set up Oracle

If in tcsh or csh shell, your .cshrc file would be:

setenv ORACLE_BASE /usr/local/oracle11gr203setenv ORACLE_HOME ${ORACLE_BASE}/product/11.2.0/db_1setenv PATH ${PATH}:${ORACLE_HOME}/binsetenv ORACLE_SID WPI11GR2 setenv TWO_TASK WPI11GR2setenv LD_LIBRARY_PATH ${ORACLE_HOME}/lib

Page 8: 1 Very basics on DB access Elke A. Rundensteiner

8

How to set up Oracle

If in bash shell, your .cshrc file would be:

setenv ORACLE_BASE=/usr/local/oracle11gr203setenv ORACLE_HOME=${ORACLE_BASE}/product/11.2.0/db_1setenv PATH=${PATH}:${ORACLE_HOME}/binsetenv ORACLE_SID=WPI11GR2 setenv TWO_TASK=WPI11GR2setenv LD_LIBRARY_PATH=${ORACLE_HOME}/lib

Page 9: 1 Very basics on DB access Elke A. Rundensteiner

9

How to set up Oracle (contd…)

If your path is empty, then add one additional line, as below, on top of your .cshrc file :

setenv PATH .

The rest is as on previous slide

Page 10: 1 Very basics on DB access Elke A. Rundensteiner

10

How to set up Oracle

After editing the file “.cshrc “Please run below: or log out and

back in:

source .cshrc

Or, log out and back in.

Page 11: 1 Very basics on DB access Elke A. Rundensteiner

11

Problems while setting up Oracle

Important – Set up Oracle immediately and see that it is working

you may run into problems, typically due to simple typos or minor setup issues

If you have identified a project partner, start working with him/her on this to help each other

If you get really stuck, please send a message to mywpi to show a screen-dump of what happens.

Page 12: 1 Very basics on DB access Elke A. Rundensteiner

12

Oracle introduction

Connecting sqlplus <userName>/<PASSWORD>

Change passwd using password command You will end up submitting your passwd; therefore don’t use password that you use for other

purposes.

Page 13: 1 Very basics on DB access Elke A. Rundensteiner

13

Oracle useful commands

These commands can be executed from SQL shell

SELECT * FROM cat; -- lists tables you have createdSELECT table_name FROM user_tables; -- as above.

DESCRIBE <tableName>; -- describes schema for table with name tableName

help index; -- shows list of help topics;help start; -- illustrates how to use command start

exit; -- exit from SQL shell

Page 14: 1 Very basics on DB access Elke A. Rundensteiner

14

Using Oracle from Windows

Multiple ways: Use aquastudio software from aquafold.com. connect

to --server: oracle.wpi.edu

port: 1521 (this is the default)SID: WPI11GR2

Download oracle client for windows. Connect using sqlplus client or other tools:sqlplus rundenst/rundenst@//oracle.wpi.edu:1521/cs.wpi.edu

Page 15: 1 Very basics on DB access Elke A. Rundensteiner

15

Working with the Data Server

Page 16: 1 Very basics on DB access Elke A. Rundensteiner

16

Basic SQL Commands

CREATE TABLE student(sNum INTEGER,sName VARCHAR (30)); -- creates table student with two columns

INSERT INTO student VALUES (1, ‘Joe’); -- insert one row into the student table

SELECT * FROM student; -- select all rows from student table

DELETE FROM student; -- delete all rows in the student table

DROP TABLE student; -- drop student table

Purge recyclebin; -- purge recyclebin tables that get created.

-- Only works if you are logged onto CCC1

Page 17: 1 Very basics on DB access Elke A. Rundensteiner

17

Saving your Interactive Session in SQLPlus

If you want to save your output to a file (for homework)

spool <fileName>

<executeCmds to create tables ...>

spool off;