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 Statements6.6.4 Altering a Table With <strong>SQL</strong>To alter a database object, such as a table, use the <strong>SQL</strong> ALTER statement as shown inExample 6–25.Example 6–25Altering a Table-- add a new column to my_birthdaysALTER TABLE my_birthdaysADD (age NUMBER(3));-- rename the my_employees tableALTER TABLE my_employees RENAME to temp_employees;6.6.5 Dropping a Table With <strong>SQL</strong>To drop (remove completely) a table from the database use the <strong>SQL</strong> DROP statement asshown inExample 6–26. Be very careful when using the DROP statement to removedatabase objects.If you want to delete the rows in the table and keep the table, use the DELETEstatement. See "Deleting Data With the DELETE Statement" on page 6-8.Example 6–26Dropping a Table-- drop tables from the database-- use caution when use the DROP statement!DROP TABLE my_birthdays;DROP TABLE temp_employees;6.6.6 Creating and Dropping a SequenceExample 6–27 creates a sequence that can be used with the employees table. Thesequence could also be used with other tables. For more information on sequences, seeManaging Sequences.Example 6–27Creating a Sequence-- create a new sequence to use with the employees tableCREATE SEQUENCE new_employees_seq START WITH 1000 INCREMENT BY 1;-- to use the sequence, first initialize the sequence with NEXTVALSELECT new_employees_seq.NEXTVAL FROM DUAL;-- after initializing the sequence, use CURRVAL as the next value in the sequenceINSERT INTO employees VALUES(new_employees_seq.CURRVAL, 'Pilar', 'Valdivia', 'pilar.valdivia','555.111.3333', '01-SEP-05', 'AC_MGR', 9100, .1, 101, 110);-- query the employees table to check the current value of the sequence-- which was inserted used as employee_id in the previous INSERT statementSELECT employee_id, last_name FROM employees WHERE last_name = 'Valdivia';Example 6–28 drops the sequence that you previously created.<strong>SQL</strong>: Usage Information 6-17

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

Saved successfully!

Ooh no, something went wrong!