CLASS EXERCISE, CHAPTER 9 DATA MANIPULATION with CONSTRAINTS

CLASS EXERCISE, CHAPTER 9 DATA MANIPULATION with CONSTRAINTS

<p>CLASS EXERCISE, CHAPTER 9 == DATA MANIPULATION with CONSTRAINTS</p><p>SQL> SET PAGESIZE 200</p><p>SQL> INSERT INTO depart (Dept#, Dname) 2 SELECT department_id, department_name 3 FROM departments 4* WHERE location_id = 1700 SQL> /</p><p>3 rows created.</p><p>SQL> commit;</p><p>Commit complete.</p><p>SQL> SELECT * FROM depart;</p><p>DEPT# DNAME CITY ------10 Administration 90 Executive 190 Contracting </p><p>SQL> SELECT * FROM locations 2 WHERE location_id IN (SELECT location_id 3 FROM departments );</p><p>LOCATION_ID STREET_ADDRESS POSTAL_CODE ------CITY STATE_PROVINCE CO ------1400 2014 Jabberwocky Rd 26192 Southlake Texas US</p><p>1500 2011 Interiors Blvd 99236 South San Francisco California US</p><p>1700 2004 Charade Rd 98199 Seattle Washington US</p><p>1800 147 Spadina Ave M5V 2L7 Toronto Ontario CA</p><p>2500 Magdalen Centre, The Oxford Science Park OX9 9ZB Oxford Oxford UK</p><p>SQL> UPDATE depart 2 SET City = 'Seattle';</p><p>3 rows updated.</p><p>SQL> SELECT * FROM depart;</p><p>DEPT# DNAME CITY ------10 Administration Seattle 90 Executive Seattle 190 Contracting Seattle </p><p>SQL> INSERT INTO depart (Dept#, Dname) 2 SELECT department_id, department_name 3 FROM departments 4 WHERE location_id = 1400;</p><p>1 row created.</p><p>SQL> UPDATE depart 2 SET City = 'Southlake' 3 WHERE City IS NULL;</p><p>1 row updated.</p><p>SQL> INSERT INTO depart (Dept#, Dname) 2 SELECT department_id, department_name 3 FROM departments 4 WHERE location_id = 1500;</p><p>1 row created.</p><p>SQL> UPDATE depart 2 SET City = 'South San Francisco' 3* WHERE City IS NULL ;</p><p>1 row updated.</p><p>SQL> INSERT INTO depart (Dept#, Dname) 2 SELECT department_id, department_name 3 FROM departments 4 WHERE location_id = 1800;</p><p>1 row created.</p><p>SQL> UPDATE depart 2 SET City = 'Toronto' 3* WHERE City IS NULL ;</p><p>1 row updated. SQL> commit;</p><p>Commit complete.</p><p>SQL> SELECT * FROM depart;</p><p>DEPT# DNAME CITY ------10 Administration Seattle 90 Executive Seattle 190 Contracting Seattle 20 Marketing Toronto 60 IT Southlake 50 Shipping South San Francisco </p><p>6 rows selected.</p><p>SQL> SELECT * FROM departments;</p><p>DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID ------10 Administration 200 1700 20 Marketing 201 1800 50 Shipping 124 1500 60 IT 103 1400 80 Sales 149 2500 90 Executive 100 1700 110 Accounting 205 190 Contracting 1700 </p><p>8 rows selected.</p><p>SQL> DESC employees Name Null? Type ------EMPLOYEE_ID NOT NULL NUMBER(6) FIRST_NAME VARCHAR2(20) LAST_NAME NOT NULL VARCHAR2(25) EMAIL NOT NULL VARCHAR2(25) PHONE_NUMBER VARCHAR2(20) HIRE_DATE NOT NULL DATE JOB_ID NOT NULL VARCHAR2(10) SALARY NUMBER(8,2) COMMISSION_PCT NUMBER(2,2) MANAGER_ID NUMBER(6) DEPARTMENT_ID NUMBER(4)</p><p>SQL> DESC empl Name Null? Type ------EMP# NOT NULL NUMBER(7) LNAME NOT NULL VARCHAR2(20) FNAME NOT NULL VARCHAR2(20) PAY NOT NULL NUMBER(7,2) SDATE NOT NULL DATE JOB VARCHAR2(15) DEPT# NOT NULL NUMBER(4)</p><p>SQL> INSERT INTO empl 2 SELECT employee_id, last_name, first_name, salary, hire_date, job_id, department_id 3 FROM employees 4 WHERE department_id NOT IN (80,110);</p><p>14 rows created.</p><p>SQL> COMMIT; Commit complete.</p><p>SQL> DESC cust Name Null? Type ------CUST# NOT NULL NUMBER(6) CUSTNAME NOT NULL VARCHAR2(30) CITY NOT NULL VARCHAR2(20) RATING CHAR(1) COMMENTS VARCHAR2(200) SALESREP# NUMBER(7)</p><p>SQL> INSERT INTO cust VALUES ( 2 501, 'ABC LTD.','Montreal','C',null,174); INSERT INTO cust VALUES ( * ERROR at line 1: ORA-02291: integrity constraint (OA301A40.CUST_SALESREP#_FK) violated - parent key not found </p><p>SQL> INSERT INTO cust VALUES ( 2* 501, 'ABC LTD.','Montreal','C',null,149); INSERT INTO cust VALUES ( * ERROR at line 1: ORA-02291: integrity constraint (OA301A40.CUST_SALESREP#_FK) violated - parent key not found </p><p>SQL> INSERT INTO cust VALUES ( 2* 501, 'ABC LTD.','Montreal','C',null,201)</p><p>1 row created.</p><p>SQL> INSERT INTO cust VALUES ( 2 502,'Black Giant','Ottawa','B',null,202);</p><p>1 row created. SQL> INSERT INTO cust VALUES ( 2* 503,'Mother Goose','London','B',null,202) SQL> /</p><p>1 row created.</p><p>SQL> COMMIT;</p><p>Commit complete.</p><p>SQL> DELETE FROM empl WHERE emp# = 202;</p><p>DELETE FROM empl * ERROR at line 1: ORA-02245: integrity constraint (OA301A40.CUST_SALESREP#_FK) violated – child records found </p><p>SQL> SELECT * FROM depart;</p><p>DEPT# DNAME CITY ------10 Administration Seattle 90 Executive Seattle 190 Contracting Seattle 20 Marketing Toronto 60 IT Southlake 50 Shipping South San Francisco </p><p>6 rows selected.</p><p>SQL> SELECT * FROM empl;</p><p>EMP# LNAME FNAME PAY SDATE ------JOB DEPT# ------100 King Steven 24000 17-JUN-87 AD_PRES 90 </p><p>101 Kochhar Neena 17000 21-SEP-89 AD_VP 90 </p><p>102 De Haan Lex 17000 13-JAN-93 AD_VP 90 </p><p>103 Hunold Alexander 9000 03-JAN-90 IT_PROG 60 </p><p>104 Ernst Bruce 6000 21-MAY-91 IT_PROG 60 </p><p>107 Lorentz Diana 4200 07-FEB-99 IT_PROG 60 </p><p>124 Mourgos Kevin 5800 16-NOV-99 ST_MAN 50 </p><p>141 Rajs Trenna 3500 17-OCT-95 ST_CLERK 50 </p><p>142 Davies Curtis 3100 29-JAN-97 ST_CLERK 50 </p><p>143 Matos Randall 2600 15-MAR-98 ST_CLERK 50 </p><p>144 Vargas Peter 2500 09-JUL-98 ST_CLERK 50 </p><p>200 Whalen Jennifer 4400 17-SEP-87 AD_ASST 10 </p><p>201 Hartstein Michael 13000 17-FEB-96 MK_MAN 20 </p><p>202 Fay Pat 6000 17-AUG-97 MK_REP 20 </p><p>14 rows selected.</p><p>SQL> SELECT * FROM cust;</p><p>CUST# CUSTNAME CITY R ------COMMENTS SALESREP# ------</p><p>501 ABC LTD. Montreal C </p><p>201 </p><p>502 Black Giant Ottawa B </p><p>202 </p><p>503 Mother Goose London B </p><p>202 </p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us