SQL Lab 1: Objective
SQL Lab 1: Objective
SQL Lab 1: Objective
Objective: A. Launch Oracle SQLPlus WorkSheet and connect it to Oracle Server B. Create tables C. Insert data D. Query single table
Upon launching Oracle SQL Plus WorkSheet, you will see a logon dialogue box and will be asked to enter your information in the box. Complete the logon dialogue box as the example below (not case sensitive): Username: USER2 Password: LCORU2 (Leon Chen Oracle User 2) Service: IS4420 You user ID and password will be like user1(password= LCORU1)...user30(password= LCORU30), and are assigned as below:
user1 user2 user3 user4 user5 user6 user7 user8 user9 user10 user11 user12 user13 user14 user15 user16 user17
ADAMS,MATTHEW CASON BOANTA,IRIS MONICA CAHOON,MICHAEL GARY CHUGG,WILLIAM NICHOLUS FOX,MICHAEL PATRICK HESS,JASON ROBERT KAPPOS,JESSICA MAE KEELING,KLAYTON THOMAS KENT,MICHAEL PAUL LEEFLANG,DEBRA MASON,STEPHEN L NEILSON,COREY WADE SCHULTZ,DAVID STOOKEY,JULIA LEE VAN RIJ,JOSHUA JACOB WELLING,KATHERINE ANN ZOBELL,DERRICK CALIE
Execute
Command window
B. Create tables
Input the following SQL command in the Command window and click the Execute button: CREATE TABLE CUSTOMER_T ( Customer_ID NUMBER(11,0) not null, Customer_Name varchar2(25) not null, Customer_Address varchar2(30), Customer_City varchar2(20), Customer_State varchar2(2), Zip varchar2(9), constraint Customer_PK primary key (Customer_ID) ); Do the same for the following SQL command. You can do it one by one or all together. CREATE TABLE ORDER_T ( Order_ID NUMBER(11,0) not null, Order_Date DATE not null, Customer_ID NUMBER(11,0), constraint Order_PK primary key (Order_ID), constraint Order_FK foreign key (Customer_ID) references CUSTOMER_T(Customer_ID) ); CREATE TABLE PRODUCT_T ( PRODUCT_ID INTEGER NOT NULL, PRODUCT_DESCRIPTION VARCHAR2(50), PRODUCT_FINISH VARCHAR2(20) CHECK (PRODUCT_FINISH IN ('Cherry', 'Natural Ash', 'White Ash', 'Red Oak', 'Natural Oak', 'Walnut')), STANDARD_PRICE DECIMAL(6,2), PRODUCT_LINE_ID INTEGER, constraint PRODUCT_PK primary key (PRODUCT_ID) ); CREATE TABLE ORDER_LINE_T (
ORDER_ID NUMBER(11,0) NOT NULL, PRODUCT_ID NUMBER(11,0) NOT NULL, ORDERED_QUANTITY NUMBER(11,0), constraint ORDER_LINE_PK primary key (Order_ID, PRODUCT_ID), constraint ORDER_LINE_FK1 foreign key (ORDER_ID) references ORDER_T(ORDER_ID), constraint ORDER_LINE_FK2 foreign key (PRODUCT_ID) references PRODUCT_T(PRODUCT_ID) ); You can use the following command to see the tables youve just created: select table_name from user_tables; If you want to know the structure of the table you created, use DESCRIBE or DESC as below: desc customer_t; You may already notice that most of the time SQL is not case sensitive. For example, CREATE is the same create. But some times SQL is sensitive. For example Red Oak is different from red oak.
insert into ORDER_T values(106, '10-OCT-04', 2); insert into ORDER_T values(107, '10-OCT-04', 1); PRODUCT_T ========== insert into PRODUCT_T values (1000, 'Office Desk', 'Cherry', 95.0, 10); insert into PRODUCT_T values (1001, 'Manager''s Desk', 'Red Oak', 199.0, 10); insert into PRODUCT_T values (2000, 'Office Chair', 'Cherry', 75.0, 20); insert into PRODUCT_T values (2001, 'Manager''s Desk', 'Natural Oak', 129.0, 20); insert into PRODUCT_T values (3000, 'Book Shelf', 'Natural Ash', 35.0, 30); insert into PRODUCT_T values (3001, 'Duplex Book Shelf', 'White Ash', 80.0, 30); insert into PRODUCT_T values (4000, 'Table Lamp', 'Natural Ash', 15.0, 40); insert into PRODUCT_T values (4001, 'Duplex Table Lamp', 'White Ash', 40.0, 40); insert into PRODUCT_T values (9999, 'Keyboard', 'Plastic', 20.0, 50); You should see an error message for the last insertion. Please try to figure out why, but you dont need to solve it. Carry on to next table. ORDER_LINE_T ============= insert into ORDER_LINE_T values (100, 4000, 1); insert into ORDER_LINE_T values (101, 1000, 2); insert into ORDER_LINE_T values (101, 2000, 2); insert into ORDER_LINE_T values (102, 3000, 1); insert into ORDER_LINE_T values (102, 2000, 1); insert into ORDER_LINE_T values (103, 4001, 1); insert into ORDER_LINE_T values (104, 2000, 1);
insert into ORDER_LINE_T values (105, 3001, 2); insert into ORDER_LINE_T values (106, 3000, 1); insert into ORDER_LINE_T values (106, 4000, 1); insert into ORDER_LINE_T values (107, 4001, 1);