12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using <strong>SQL</strong> Data Definition Language Statementshire_date DATE DEFAULT SYSDATE CONSTRAINT my_emp_hire_date_nn NOT NULL,job_idVARCHAR2(10) CONSTRAINT my_emp_job_nn NOT NULL,salaryNUMBER(8,2) CONSTRAINT emy_mp_salary_nn NOT NULL,commission_pct NUMBER(2,2),manager_id NUMBER(6),department_id NUMBER(4),CONSTRAINT my_emp_salary_min CHECK (salary > 0),CONSTRAINT my_emp_email_uk UNIQUE (email));6.6.2 Creating and Modifying an Index With <strong>SQL</strong>To create, modify, or drop an index, use the <strong>SQL</strong> CREATE, ALTER, or DROP INDEXstatement as shown in Example 6–23.Example 6–23Creating, Modifying, and Dropping an Index-- create a new index on the employees table using the email columnCREATE INDEX email_ixON employees (email);-- disable the indexALTER INDEX email_ixRENAME TO my_email_ix;-- drop the indexDROP INDEX my_email_ix;-- create an index on a single column to make queries faster on that columnCREATE INDEX emp_last_name_ix ON employees (last_name);DROP INDEX emp_last_name_ix;-- create an index on two columns to make queries faster on the first column-- or both columnsCREATE INDEX emp_mgr_id_ix ON employees (employee_id, manager_id);DROP INDEX emp_mgr_id_ix;-- a function-based index precalculates the result and speeds up queries that-- use the function for searching or sorting, in this case UPPER(last_name)CREATE INDEX emp_upper_last_name_ix ON employees (UPPER(last_name));DROP INDEX emp_upper_last_name_ix;6.6.3 Creating and Modifying a Constraint With <strong>SQL</strong>To add or a modify a constraint on a table, use the <strong>SQL</strong> ALTER statement as shown inExample 6–24.Example 6–24Creating and Altering a Constraint-- add a constraint a new constraintALTER TABLE my_employeesADD CONSTRAINT ...-- remove the constraint on email in the my_employees tableALTER TABLE my_employeesDROP UNIQUE (email);6-16 <strong>SQL</strong> <strong>Developer</strong> Online Help

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

Saved successfully!

Ooh no, something went wrong!