12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using <strong>SQL</strong> Data Definition Language Statements-- you can use MIN to find the minimum salary for employees with manager 122SELECT MIN(salary) FROM employees WHERE manager_id = 122;-- this computes the minimum and maximum salary by job_id groups-- the job_ids groups are sorted in alphabetical orderSELECT MIN(salary), MAX(salary), job_id FROM employeesGROUP BY job_id ORDER BY job_id;6.6 Using <strong>SQL</strong> Data Definition Language StatementsData definition language (DDL) statements include CREATE, ALTER, and DROP fordefining database objects. When managing database objects, <strong>SQL</strong> <strong>Developer</strong> providesa simple and easy-to-use interface that can be utilized instead of <strong>SQL</strong> DDL statements.In this guide, some basic <strong>SQL</strong> DDL statements are used in the code examples and abrief description of some DDL statements are discussed here.This topic includes the following topics:■ Creating a Table With <strong>SQL</strong>■ Creating and Modifying an Index With <strong>SQL</strong>■ Creating and Modifying a Constraint With <strong>SQL</strong>■ Altering a Table With <strong>SQL</strong>■ Dropping a Table With <strong>SQL</strong>■ Creating and Dropping a Sequence■ Creating and Dropping a Synonym6.6.1 Creating a Table With <strong>SQL</strong>To create a database object, such as a table, use the <strong>SQL</strong> CREATE statement as shown inExample 6–21. When you create a table, you need to provide data types for eachcolumn. For more information about tables, see Managing Tables.Example 6–21Creating a Simple Table-- create a simple table for keeping track of birthdaysCREATE TABLE my_birthdays( first_name VARCHAR2(20),last_name VARCHAR2(25),bday_date DATE);Optionally, you can provide constraints as shown inExample 6–22. The use ofconstrains is discussed in Ensuring Data Integrity With Constraints.Example 6–22Creating a Table With Constraints-- create a table similar to the employees table in the HR schemaCREATE TABLE my_employees( employee_id NUMBER(6),first_name VARCHAR2(20),last_name VARCHAR2(25) CONSTRAINT my_emp_last_name_nn NOT NULL,emailVARCHAR2(25) CONSTRAINT my_emp_email_nn NOT NULL,phone_number VARCHAR2(20),<strong>SQL</strong>: Usage Information 6-15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!