SQL Practice

March 22, 2018 | Author: Gregory De La Rosa | Category: Sql, Oracle Database, Table (Database), Databases, Data


Comments



Description

Practice 1: Overview This practice covers the following topics: • Selecting all data from different tables • Describing the structure of tables • Performing arithmetic calculations and specifying column names • Using iSQL*Plus y l n O e Copyright © 2004, Oracle. All rights reserved. s U Practice 1: Overview This is the first of many practices in this course. The solutions (if you require them) can be found in Appendix A. Practices are intended to cover all topics that are presented in the corresponding lesson. I A & l a Note the following location for the lab files: E:\labs\SQL1\labs O n r te If you are asked to save any lab files, save them at this location. To start ISQL*Plus, start your browser. You need to enter a URL to access iSQL*Plus. The URL requires the host name, which your instructor will provide. Enter the following command, replacing the host name with the value that your instructor provides: n I e l c a http://<HOSTNAME:5561>/isqlplus In any practice, there may be exercises that are prefaced with the phrases “If you have time” or “If you want an extra challenge.” Work on these exercises only if you have completed all other exercises in the allocated time and would like a further challenge to your skills. Perform the practices slowly and precisely. You can experiment with saving and running command files. If you have any questions at any time, ask your instructor. r O Oracle Database 10g: SQL Fundamentals I 1-37 Practice 1 Part 1 Test your knowledge: 1. Initiate an iSQL*Plus session using the user ID and password that are provided by the instructor. 2. iSQL*Plus commands access the database. True/False 3. The following SELECT statement executes successfully: SELECT last_name, job_id, salary AS Sal FROM employees; True/False 4. The following SELECT statement executes successfully: SELECT * FROM job_grades; True/False 5. There are four coding errors in the following statement. Can you identify them? SELECT sal x 12 FROM employee_id, last_name ANNUAL SALARY employees; y l n O e Part 2 Note the following location for the lab files: E:\labs\SQL1\labs I A s U If you are asked to save any lab files, save them at this location. To start ISQL*Plus, start your browser. You need to enter a URL to access iSQL*Plus. The URL requires the host name, which your instructor will provide. Enter the following command, replacing the host name with the value that your instructor provides: & l a O http://<HOSTNAME:5561>/isqlplus n r te You have been hired as a SQL programmer for Acme Corporation. Your first task is to create some reports based on data from the Human Resources tables. 6. Your first task is to determine the structure of the DEPARTMENTS table and its contents. n I e r O l c a Oracle Database 10g: SQL Fundamentals I 1-38 Practice 1 (continued) 7. You need to determine the structure of the EMPLOYEES table. y l n O e I A s U O The HR department wants a query to display the last name, job code, hire date, and employee number for each employee, with employee number appearing first. Provide an alias STARTDATE for the HIRE_DATE column. Save your SQL statement to a file named lab_01_07.sql so that you can disperse this file to the HR department. & l a n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 1-39 Practice 1 (continued) 8. Test your query in the lab_01_07.sql file to ensure that it runs correctly. … y l n O e 9. The HR department needs a query to display all unique job codes from the EMPLOYEES table. I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 1-40 The HR department wants more descriptive column headings for its report on employees. complete the following exercises: 10. y l n … O e s U 11.Practice 1 (continued) Part 3 If you have time. respectively. The HR department has requested a report of all employees and their job IDs. I A & l a O n r te n I e l c a r O … Oracle Database 10g: SQL Fundamentals I 1-41 . Job. Copy the statement from lab_01_07. Name the column headings Emp #. Then run your query again. Display the last name concatenated with the job ID (separated by a comma and space) and name the column Employee and Title.sql to the iSQL*Plus text box. Employee. and Hire Date. create a query to display all the data from that table. Separate each column output by a comma. To familiarize yourself with the data in the EMPLOYEES table. complete the following exercise: 12. … y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 1-42 .Practice 1 (continued) If you want an extra challenge. Name the column title THE_OUTPUT. I A & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 2-32 . including statements that use the WHERE clause and the ORDER BY clause. s U Practice 2: Overview In this practice. you build more reports. All rights reserved. Oracle. You make the SQL statements more reusable and generic by including ampersand substitution.Practice 2: Overview This practice covers the following topics: • Selecting data and changing the order of the rows that are displayed • Restricting rows by using the WHERE clause • Sorting rows by using the ORDER BY clause • Using substitution variables to add flexibility to your SQL SELECT statements y l n O e Copyright © 2004. Place your SQL statement in a text file named lab_02_03. The HR departments needs to find high-salary and low-salary employees.000. Due to budget issues. the HR department needs a report that displays the last name and salary of employees who earn more than $12. Run your query.000 to $12. Create a report that displays the last name and department number for employee number 176. 3. 2.Practice 2 The HR department needs your assistance with creating some queries. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 2-33 .sql.000. Place your SQL statement in a text file named lab_02_01. 1.sql to display the last name and salary for any employee whose salary is not in the range of $5.sql. Modify lab_02_01. 000 and $12. Run the statement in lab_02_06. Label the columns Employee and Monthly Salary.sql to display the last name and salary of employees who earn between $5.sql. Create a report to display the last name. and start date for the employees with the last names of Matos and Taylor. 5. I A & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 2-34 .sql. Modify lab_02_03. job ID. Order the query in ascending order by start date.sql as lab_02_06.Practice 2 (continued) 4. Resave lab_02_03.000 and are in department 20 or 50. Display the last name and department number of all employees in departments 20 or 50 in ascending alphabetical order by name. respectively. y l n O e s U 6. 8.Practice 2 (continued) 7. The HR department needs a report that displays the last name and hire date for all employees who were hired in 1994.sql. Sort data in descending order of salary and commissions. (You can use the query that you created in practice exercise 1 and modify it. the report displays the following results: I A & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 2-35 .) Save this query to a file named lab_02_10. They would like a report that displays the last name and salary of employees who earn more than an amount that the user specifies after a prompt. If you enter 12000 when prompted. Create a report to display the last name. salary. Members of the HR department want to have more flexibility with the queries that you are writing. Create a report to display the last name and job title of all employees who do not have a manager. y l n O e s U 10. 9. and commission of all employees who earn commissions. The HR department wants the ability to sort the report on a selected column. salary.Practice 2 (continued) 11. Create a query that prompts the user for a manager ID and generates the employee ID. sorted by employee ID: y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 2-36 . The HR department wants to run reports based on a manager. last name. sorted by employee last name: manager ID = 201. and department for that manager’s employees. sorted by salary: manager ID = 124. You can test the data with the following values: manager ID = 103. sql. and commission for all employees whose commission amount is 20%. or $7. salary.Practice 2 (continued) If you have time.500. 13.sql to display the last name. Resave lab_02_06.500. Modify lab_02_06. Rerun the statement in lab_02_15. complete the following exercises: 14.000. $3. job. y l n O e I A s U O 15. Display the last name. and salary for all employees whose job is sales representative or stock clerk and whose salary is not equal to $2.sql as lab_02_15. If you want an extra challenge. complete the following exercises: 12. Display all employee last names in which the third letter of the name is a.sql. Display the last name of all employees who have both an a and an e in their last name. & l a n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 2-37 . s U Practice 3: Overview of Part 1 Part 1 of this lesson’s practice provides a variety of exercises using different functions that are available for character. All rights reserved. I A O For Part 1. complete questions 1–6 at the end of this lesson. Oracle. & l a n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 3-25 . number. and date data types. and date functions • Performing calculations of years and months of service for an employee y l n O e Copyright © 2004. character.Practice 3: Overview of Part 1 This practice covers the following topics: • Writing a query that displays the current date • Creating queries that require the use of numeric. Place your SQL statement in a text file named lab_03_02.sql to add a column that subtracts the old salary from the new salary.5% (expressed as a whole number) for each employee.Practice 3 Part 1 1. & l a O … n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 3-62 . Write a query to display the current date. Run the revised query. and salary increased by 15. Modify your query lab_03_02. 3. Save the contents of the file as lab_03_04. last name. Label the column New Salary. Run your query in the file lab_03_02. salary. … y l n O e I A s U 4.sql. The HR department needs a report to display the employee number.sql.sql. Label the column Increase. Label the column Date. 2. For example. A.Practice 3 (continued) 5. then the output should show all employees whose last name starts with the letter H. if the user enters H when prompted for a letter. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 3-63 . Give each column an appropriate label. Write a query that displays the last name (with the first letter uppercase and all other letters lowercase) and the length of the last name for all employees whose name starts with the letters J. Sort the results by the employees’ last names. Rewrite the query so that the user is prompted to enter a letter that starts the last name. or M. For each employee. Round the number of months up to the closest whole number. The HR department wants to find the length of employment for each employee. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 3-64 . display the last name and calculate the number of months between today and the date on which the employee was hired. Note: Your results will differ. Order your results by the number of months employed. Label the column MONTHS_WORKED.Practice 3 (continued) 6. & l a n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 3-61 . s U Practice 3: Overview of Part 2 Part 2 of this lesson’s practice provides a variety of exercises using different functions that are available for character. the results are evaluated from the innermost function to the outermost function. complete exercises 7–14. character. and date functions • Using concatenation with functions • Writing case-insensitive queries to test the usefulness of character functions • Performing calculations of years and months of service for an employee • Determining the review date for an employee y l n O e Copyright © 2004. and date data types. number. Oracle.Practice 3: Overview of Part 2 This practice covers the following topics: • Creating queries that require the use of numeric. All rights reserved. I A O Remember that for nested functions. For Part 2. … y l n O e If you have time. Create a query to display the last name and salary for all employees. Label the column SALARY. I A & l a s U O … n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 3-65 . Format the salary to be 15 characters long. Label the column Dream Salaries.Practice 3 (continued) Part 2 7. left-padded with the $ symbol. Create a report that produces the following for each employee: <employee last name> earns <salary> monthly but wants <3 times salary>. complete the following exercises: 8. Label the column REVIEW. 2000. the Thirty-First of July. starting with Monday. Display each employee’s last name. Display the last name. hire date. hire date.” … y l n 10.Practice 3 (continued) 9. and salary review date. and day of the week on which the employee started. Format the dates to appear in the format similar to “Monday. which is the first Monday after six months of service. Label the column DAY. Order the results by the day of the week. O e I A & l a … s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 3-66 . complete the following exercises: 11. Create a query that displays the employees’ last names and commission amounts. I A & l a O n r te … n I e r O l c a Oracle Database 10g: SQL Fundamentals I 3-67 . If an employee does not earn commission. … y l n O e s U 12. Each asterisk signifies a thousand dollars. Create a query that displays the first eight characters of the employees’ last names and indicates the amounts of their salaries with asterisks. Label the column EMPLOYEES_AND_THEIR_SALARIES.Practice 3 (continued) If you want an extra challenge. Sort the data in descending order of salary.” Label the column COMM. show “No Commission. Using the DECODE function.Practice 3 (continued) 13. Rewrite the statement in the preceding exercise using the CASE syntax. Oracle Database 10g: SQL Fundamentals I 3-68 . write a query that displays the grade of all employees based on the value of the column JOB_ID. using the following data: Job Grade AD_PRES A ST_MAN B IT_PROG C SA_REP D ST_CLERK E None of the above 0 y l n O e I A & l a s U O n r te n I e l c a r O 14. All rights reserved. Oracle. s U Practice 4: Overview At the end of this practice. you should be familiar with using group functions and selecting groups of data. I A & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 4-25 .Practice 4: Overview This practice covers the following topics: • Writing queries that use the group functions • Grouping by rows to achieve more than one result • Restricting groups by using the HAVING clause y l n O e Copyright © 2004. sum. Circle either True or False.Practice 4 Determine the validity of the following three statements. respectively. True/False 2. Resave lab_04_04. True/False 3.sql as lab_04_05.sql. and average salary for each job type. 1.sql. Sum. Label the columns Maximum. lowest. Run the statement in lab_04_05. Find the highest. Group functions include nulls in calculations. sum. True/False The HR department needs the following reports: 4. The WHERE clause restricts rows prior to inclusion in a group calculation.sql. maximum. and average salary of all employees. Round your results to the nearest whole number.sql to display the minimum. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 4-26 . Place your SQL statement in a text file named lab_04_04. Modify the query in lab_04_04. and Average. Group functions work across many rows to produce one result per group. 5. Minimum. Exclude any groups where the minimum salary is $6. Save the script to a file named lab_04_06.sql. complete the following exercises: 9. & l a O n r te If you have time. Sort the output in descending order of salary. Exclude anyone whose manager is not known. Label the column DIFFERENCE. Label the column Number of Managers.Practice 4 (continued) 6. y l n 7. Create a report to display the manager number and the salary of the lowest-paid employee for that manager. Find the difference between the highest and lowest salaries. Generalize the query so that the user in the HR department is prompted for a job title. n I e r O l c a Oracle Database 10g: SQL Fundamentals I 4-27 .000 or less. O e I A s U 8. Hint: Use the MANAGER_ID column to determine the number of managers. Write a query to display the number of people with the same job. Determine the number of managers without listing them. Create a query to display the total number of employees and. 1997. Create a matrix query to display the job. and 1998. 1996. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 4-28 . 11. 50. complete the following exercises: 10. and 90. the salary for that job based on department number. and the total salary for that job. giving each column an appropriate heading. 80. for departments 20. Create appropriate column headings. of that total.Practice 4 (continued) If you want an extra challenge. the number of employees hired in 1995. Oracle. I A & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 5-30 . s U Practice 5: Overview This practice is intended to give you practical experience in extracting data from more than one table using SQL:1999–compliant joins. All rights reserved.Practice 5: Overview This practice covers the following topics: • Joining tables using an equijoin • Performing outer and self-joins • Adding conditions y l n O e Copyright © 2004. Show the location ID. y l n O e I A … & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 5-31 . and department name for all employees. state or province. Write a query for the HR department to produce the addresses of all the departments.Practice 5 1. Use the LOCATIONS and COUNTRIES tables. street address. Write a query to display the last name. and country in the output. Use a NATURAL JOIN to produce the results. city. The HR department needs a report of all employees. 2. department number. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 5-32 . Place your SQL statement in a text file named lab_05_04. 4. and department name for all employees who work in Toronto. job. department number. respectively. The HR department needs a report of employees in Toronto.sql. and Mgr#. Manager. Label the columns Employee. Emp#.Practice 5 (continued) 3. Display the last name. Create a report to display employees’ last name and employee number along with their manager’s last name and manager number. Create a report for the HR department that displays employee last names.sql. Place your SQL statement in a text file named lab_05_05. Give each column an appropriate label. Save the script to a file named lab_05_06.sql to display all employees including King. Order the results by the employee number. y l n O e I A & l a s U O n r te … n I e r O l c a Oracle Database 10g: SQL Fundamentals I 5-33 .sql. Modify lab_05_04.Practice 5 (continued) 5. department numbers. and all the employees who work in the same department as a given employee.sql. who has no manager. … 6. Run the query in lab_05_05. The HR department wants to determine the names of all employees who were hired after Davies. The HR department needs a report on job grades and salaries. department name.Practice 5 (continued) 7. first show the structure of the JOB_GRADES table. … If you want an extra challenge. Then create a query that displays the name. job. complete the following exercises: O e y l n 8. To familiarize yourself with the JOB_GRADES table. I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 5-34 . Create a query to display the name and hire date of any employee hired after employee Davies. salary. and grade for all employees. Save the script to a file named lab5_09. The HR department needs to find the names and hire dates for all employees who were hired before their managers. along with their managers’ names and hire dates.sql. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 5-35 .Practice 5 (continued) 9. & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 6-20 . s U Practice 6: Overview In this practice. Oracle. I A Paper-Based Questions You may want to create the inner query first for these questions. Make sure that it runs and produces the data that you anticipate before you code the outer query.Practice 6: Overview This practice covers the following topics: • Creating subqueries to query values based on unknown criteria • Using subqueries to find out which values exist in one set of data and not in another y l n O e Copyright © 2004. All rights reserved. you write complex queries using nested SELECT statements. sql. For example. Write a query that displays the employee number and last name of all employees who work in a department with any employee whose last name contains a u. Create a report that displays the employee number.Practice 6 1. if the user enters Zlotkey. find all employees who work with Zlotkey (excluding Zlotkey). The HR department needs a query that prompts the user for an employee last name. Run your query. 2. and salary of all employees who earn more than the average salary. Sort the results in order of ascending salary. & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 6-21 . y l n O e I A s U 3. last name. The query then displays the last name and hire date of any employee in the same department as the employee whose name they supply (excluding that employee). Place your SQL statement in a text file named lab_06_03. Create a report for HR that displays the last name and salary of every employee who reports to King. The HR department needs a report that displays the last name. Resave lab_06_03. Save this to a file named lab_06_04. and job ID for every employee in the Executive department. Modify the query in lab_06_03. department number.sql. and job ID of all employees whose department location ID is 1700. Create a report for HR that displays the department number. last name.sql as lab_06_07. & l a O n r te n I e If you have time.sql. y l n O e I A s U 6.Practice 6 (continued) 4. 5. last name. Run the statement in lab_06_07. and salary of all employees who earn more than the average salary and who work in a department with any employee whose last name contains a u.sql to display the employee number. Modify the query so that the user is prompted for a location ID. r O l c a Oracle Database 10g: SQL Fundamentals I 6-22 .sql. complete the following exercise: 7. Practice 7: Overview In this practice. you write queries using the set operators. All rights reserved. you use the set operators to create reports: • Using the UNION operator • Using the INTERSECTION operator • Using the MINUS operator y l n O e Copyright © 2004. I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 7-24 . Oracle.Practice 7: Overview In this practice. n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 7-25 . 50. Display the country ID and the name of the countries. y l n 3. Use set operators to create this report. Display job ID and department ID using set operators. Use set operators to create this report. 2. and 20. O e I A & l a s U O 4. they changed jobs but have now gone back to doing their original job). The HR department needs a list of countries that have no departments located in them. Create a report that lists the employee IDs and job IDs of those employees who currently have a job title that is the same as their job title when they were initially hired by the company (that is.Practice 7 1. in that order. The HR department needs a list of department IDs for departments that do not contain the job ID ST_CLERK. Produce a list of jobs for departments 10. regardless of whether or not they belong to a department .Last name and department ID of all the employees from the EMPLOYEES table. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 7-26 .Practice 7 (continued) 5. regardless of whether or not they have employees working in them Write a compound query to accomplish this. The HR department needs a report with the following specifications: .Department ID and department name of all the departments from the DEPARTMENTS table. you add rows to the MY_EMPLOYEE table. and control your transactions. s U Practice 8: Overview In this practice. All rights reserved.Practice 8: Overview This practice covers the following topics: • Inserting rows into the tables • Updating and deleting rows in the table • Controlling transactions y l n O e Copyright © 2004. update and delete data from the table. Oracle. I A & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 8-40 . and delete employee data. Create an INSERT statement to add the first row of data to the MY_EMPLOYEE table from the following sample data. update. As a prototype. Do not list the columns in the INSERT clause. Confirm your addition to the table. 2.sql script to build the MY_EMPLOYEE table to be used for the lab. Run the statement in the lab_08_01. 3. Do not enter all rows yet. prior to giving the statements to the HR department. & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 8-41 . 1. This time. you use the MY_EMPLOYEE table. Describe the structure of the MY_EMPLOYEE table to identify the column names. ID LAST_NAME FIRST_NAME USERID SALARY 1 Patel Ralph rpatel 895 2 Dancs Betty bdancs 860 3 Biri Ben bbiri 1100 4 Newman Chad cnewman 750 5 Ropeburn Audrey aropebur I A y l n O e s U 1550 4.Practice 8 The HR department wants you to create SQL statements to insert. Populate the MY_EMPLOYEE table with the second row of sample data from the preceding list. list the columns explicitly in the INSERT clause. 5. Insert data into the MY_EMPLOYEE table. Practice 8 (continued) 6. Delete Betty Dancs from the MY_EMPLOYEE table. 14. Verify your changes to the table.sql to load rows into the MY_EMPLOYEE table. 9. Confirm your changes to the table. 8. Save this script to a file named lab_08_06. Change the salary to $1. 7. y l n O e I A 13. 12. Change the last name of employee 3 to Drexler.000 for all employees who have a salary less than $900. 11. 10. Confirm your additions to the table. Concatenate the first letter of the first name and the first seven characters of the last name to produce the user ID. Make the data additions permanent. Write an insert statement in a dynamic reusable script file named loademp.sql. & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 8-42 . Populate the table with the next two rows of sample data by running the insert statement in the script that you created. Update and delete data in the MY_EMPLOYEE table. 17. Run the statements in the script. y l n O e 23. Confirm that the table is empty. 20. Empty the entire table. Mark an intermediate point in the processing of the transaction. 22.Practice 8 (continued) 15. 19. Commit all pending changes. Confirm your addition to the table. Populate the table with the last row of sample data by using the statements in the script that you created in step 6. 21. 18. Control data transaction to the MY_EMPLOYEE table. Confirm that the new row is still intact. Make the data addition permanent. 16. Discard the most recent DELETE operation without discarding the earlier INSERT operation. & l a I A s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 8-43 . and then execute the command file to create the table. All rights reserved. Oracle. Create the syntax in the command file. Confirm that the new table was added to the database. I A & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 9-37 . s U Practice 9: Overview Create new tables by using the CREATE TABLE statement.Practice 9: Overview This practice covers the following topics: • Creating new tables • Creating a new table by using the CREATE TABLE AS syntax • • Verifying that tables exist Dropping tables y l n O e Copyright © 2004. 3.Practice 9 1. Place the syntax in a script called lab_09_01. Place the syntax in a script called lab_09_03.sql.sql. Confirm that the table is created. Populate the DEPT table with data from the DEPARTMENTS table. Create the DEPT table based on the following table instance chart. Include only columns that you need. Confirm that the table is created. Create the EMP table based on the following table instance chart. Column Name ID NAME Key Type Primary key Nulls/Unique FK Table FK Column Data type NUMBER VARCHAR2 Length 7 25 2. then execute the statement in the script to create the table. and then execute the statement in the script to create the table. y l n Column Name ID LAST_NAME FIRST_NAME Key Type I A Nulls/Unique FK Table FK Column Data type NUMBER Length 7 r e nt na 25 s U DEPT ID VARCHAR2 NUMBER 25 7 I e l c a r O l& VARCHAR2 O O e DEPT_ID Oracle Database 10g: SQL Fundamentals I 9-38 . LAST_NAME. and DEPT_ID. respectively. 5. Create the EMPLOYEES2 table based on the structure of the EMPLOYEES table. Name the columns in your new table ID. FIRST_NAME. FIRST_NAME.Practice 9 (continued) 4. LAST_NAME. SALARY. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 9-39 . and DEPARTMENT_ID columns. Include only the EMPLOYEE_ID. SALARY . Drop the EMP table. Complete questions 7–10 at the end of this lesson. & l a I A O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 10-41 . Oracle.Practice 10: Overview of Part 2 This practice covers the following topics: • Creating sequences • Using sequences • Creating nonunique indexes • Creating synonyms y l n O e Copyright © 2004. and a synonym. All rights reserved. an index. s U Practice 10: Overview of Part 2 Part 2 of this lesson’s practice provides you with a variety of exercises in creating and using a sequence. y l n O e … I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 10-42 . The staff in the HR department wants to hide some of the data in the EMPLOYEES table. 2. write a query for the HR department to display all employee names and department numbers. Display the contents of the EMPLOYEES_VU view.Practice 10 Part 1 1. They want a view called EMPLOYEES_VU based on the employee numbers. and department numbers from the EMPLOYEES table. … 3. employee names. Confirm that the view works. Using your EMPLOYEES_VU view. They want the heading for the employee name to be EMPLOYEE. 6. and department numbers for all employees in department 50. do not allow an employee to be reassigned to another department through the view.Practice 10 4. Display the structure and contents of the DEPT50 view. Create a view named DEPT50 that contains the employee numbers. Test your view. employee last names. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 10-43 . EMPLOYEE. Department 50 needs access to its employee data. 5. For security purposes. You have been asked to label the view columns EMPNO. Attempt to reassign Matos to department 80. and DEPTNO. Confirm your additions. 10. Create a synonym for your EMPLOYEES table.000. write a script to insert two rows in the DEPT table. Add two departments: Education and Administration. Name the sequence DEPT_ID_SEQ. 8. Run the commands in your script. You need a sequence that can be used with the primary key column of the DEPT table. Be sure to use the sequence that you created for the ID column. 9. Have your sequence increment by 10. y l n O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 10-44 . The sequence should start at 200 and have a maximum value of 1. Create a nonunique index on the NAME column in the DEPT table. Name your script lab_10_08.Practice 10 Part 2 7. To test your sequence.sql. Call it EMP. Oracle. s U Practice 11: Overview In this practice. All rights reserved. I A & l a O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 11-21 . you query the dictionary views to find information about objects in your schema.Practice 11: Overview This practice covers the following topics: • Querying the dictionary views for table and column information • Querying the dictionary views for constraint information • Querying the dictionary views for view information • Querying the dictionary views for sequence information • Querying the dictionary views for synonym information • Adding a comment to a table and querying the dictionary views for comment information y l n O e Copyright © 2004. For example. search condition. constraint name. as well as whether nulls are allowed. the following output results: 2. Create a script that reports the column name. data types. Prompt the user to enter the table name. You must join the USER_CONSTRAINTS and USER_CONS_COLUMNS tables to obtain all of this information. the following output results: y l n O e I A s U 3. and status for a specified table. n I e r O l c a Oracle Database 10g: SQL Fundamentals I 11-22 . & l a O n r te 4.Practice 11 1. Save this script in a file named lab_11_01. Then query the USER_TAB_COMMENTS view to verify that the comment is present. Prompt the user to enter the table name.sql.sql. Save the script in a file named lab_11_02. For example. if the user enters DEPARTMENTS. For a specified table. Give appropriate aliases to the columns DATA_PRECISION and DATA_SCALE. and data types’ lengths. Add a comment to the DEPARTMENTS table. constraint type. create a script that reports the column names. if the user enters DEPARTMENTS. Find the names of all synonyms that are in your schema. Name the script lab_11_06. Find the names of your sequences. Write a query in a script to display the following information about your sequences: sequence name. use the iSQL*Plus command SET LONG n. O e I A & l a s U O n r te n I e r O l c a Oracle Database 10g: SQL Fundamentals I 11-23 . Also. Run the statement in your script. Note: Another view already exists. Note: To see more contents of a LONG column. and last number.sql. y l n 6. you will see the DEPT50 view. if you completed practice 10. Create a report that retrieves view information: the view name and text from the USER_VIEWS data dictionary view. The EMP_DETAILS_VIEW was created as part of your schema. where n is the value of the number of characters of the LONG column that you want to see. maximum value. increment size. You need to determine the names and definitions of all of the views in your schema.Practice 11 5.
Copyright © 2024 DOKUMEN.SITE Inc.