Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spring 2011 ITCS3160: Database Design and Implementation Hands-on Learning.

Similar presentations


Presentation on theme: "Spring 2011 ITCS3160: Database Design and Implementation Hands-on Learning."— Presentation transcript:

1 Spring 2011 ITCS3160: Database Design and Implementation Hands-on Learning

2 Connect to the Oracle database http://coit-ora01.uncc.edu:8080/isqlplus/ User name: your 49er account ( e.g. nzhou is mine) Password(default): qwe123

3 Tasks CREATE TABLE - creates a new table ALTER TABLE - modifies a table DROP TABLE - deletes a table CREATE INDEX - creates an index (search key) (next time hands-on learning) DROP INDEX - deletes an index SELECT - extracts data from a database UPDATE - updates data in a database DELETE - deletes data from a database INSERT INTO - inserts new data into a database

4 Raghu Ramakrishnan Example Instances R1S1 S2 We will use these instances of the Sailors and Reserves relations in our examples. bidbnamecolor 101interlakeblue 102interlakered 103clippergreen 104marinered B1

5 Step1: CREATE TABLE Sailors ( sid int, sname varchar(35), rating int, age int, PRIMARY KEY (sid) ) Or CREATE TABLE Sailors ( sid int, sname varchar(35), rating int, age int, ) ALTER TABLE Sailors ADD PRIMARY KEY (sid)

6 Step2: CREATE TABLE Reserve ( ….. ) CREATE TABLE Boats ( …… )

7 Step3: INSERT INTO table_name VALUES (value1, value2, value3,...) Or INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) INSERT ALL INTO table_name (column1, …) VALUES (v1, v2, …) SELECT * FROM dual;

8 alter table table_name modify ( column_name data_type) Data_type: int, float, numeric(9,2), double precision

9 UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value DELETE FROM table_name WHERE some_column=some_value DELETE FROM table_name or DELETE * FROM table_name DROP TABLE table_name

10 Step4: SELECT column_name(s) FROM table_name SELECT * FROM table_name SELECT * FROM table A, table B A SELECT statement on multiple tables without a proper JOIN condition will lead to a cartesian product.(i.e. No.Of Output rows = No.of rows in table1 X No of rows in table2.... SELECT * FROM table A, table B where …. (see the difference, try different join)

11 Select the ‘name’ of the boat that ‘dustin’ reserves (think about it a little bit and then click next)

12 select bname from boats b, reserves r, sailors s where s.sname = 'dustin' and r.sid = s.sid and b.bid = r.bid

13 Step5: SELECT column_name(s) FROM table_name Where …


Download ppt "Spring 2011 ITCS3160: Database Design and Implementation Hands-on Learning."

Similar presentations


Ads by Google