Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 15

Data Definition Language

(DDL)
Create Table
CREATE TABLE [schema.] table_name
[(relational_properties [,relational_properties, …])]
[physical_properties]
[table_properties];

relational_properties
[ column datatype [ DEFAULT expression ] [
column_ref_constraint ] [
[ column_constraint ] [… ] ] ]

physical_properties
[ [ PCTFREE value ]
[ PCTUSED value ]
[ INITRANS value ]
[ MAXTRANS value ] ]
[ TABLESPACE tablespace ]
table_properties
{ ENABLE / DISABLE }
[ VALIDATE ] [ NOVALIDATE ]
{ UNIQUE ( column [ , column , …] ) / PRIMARY KEY /
CONSTRAINT constraint }
Create Table

CREATE table demo_temporary_tab(


temporary_id number(5) not null,
temporary_name varchar2(30) not null,
temporary_address varchar2(30),
temporary_phone number(15) not null,
temporary_city varchar2(25),
temporary_country varchar2(25) not null,
temporary_comments varchar2(40));
Create Index
CREATE [UNIQUE] [BITMAP] INDEX
[schema.] index_name
ON table_index_clause ;

table_index_clause
[schema.] table_name [table_alias]
(column / column_expression [ASC] [DESC] , …… ) index_attributes

index_attributes
{[PCTFREE value]
[PCTUSED value]
[TABLESPACE tablespace / DEFAULT]
[NOSORT / REVERSE]
paralle_clause}

paralle_clause
NOPARALLEL / PARALLEL [integer]
Create Index

CREATE index demo_temp_tab_temporary_name


ON demo_temporary_tab (temporary_name);

Index created.
The CREATE SEQUENCE
Statement

CREATE SEQUENCE [schema . ] sequence_name


[{INCREMENT BY} / {START WITH} value]
[{MAXVALUE value} / NOMAXVALUE]
[{MINVALUE value} / NOMINVALUE]
[CYCLE / NOCYCLE]
[{CACHE value} / NOCACHE]
[ORDER / NOORDER];
Create Sequence

CREATE SEQUENCE row_id_genarator;

CREATE SEQUENCE row_id_genarator2 INCREMENT BY 10;


Create View Statement

CREATE [OR REPLACE] [[NO] FORCE] VIEW [schema.] view_name


AS subquery [with_clause];

with_clause
WITH {READ ONLY} / {CHECK OPTION [CONSTRAINT constraint]}
Create View

CREATE OR REPLACE VIEW Employee_One_View


AS
SELECT Name, Address, Job
FROM Employee_One;
Drop Statements

The DROP Statements

•To discard a table use the DROP TABLE Statement


DROP TABLE [schema.] table [CASCADE CONSTRAINTS] ;

•To discard an index use the DROP INDEX Statement


DROP INDEX [schema.] index;

•To discard a sequence use the DROP SEQUENCE Statement


DROP SEQUENCE [schema.] sequence_name ;

•To discard a view use the DROP VIEW Statement


DROP VIEW [ schema . ] view ;
Alter Table

The ALTER TABLE Statement

ALTER TABLE [schema.] table {


ADD (add_column_options , …)} / {Modify (modify_column_options , …)}
[anable_disable_clause] ;

add_column_options
[column datatype [DEFAULT expression] [column_ref_constraint ]
[[column_constraint] […]]]

modify_column_options
column [datatype] [DEFAULT expression] [column_constraint , …]
Alter Table

ALTER table demo_temporary_tab add(


temporary_account number(10));

Table altered.
Transaction

The time between two commits.

A commit command confirms all DML-commands.

A rollback command undoes all DML-commands and restarts the


transaction.

 Example:

SQL> COMMIT;
SQL> ROLLBACK;

You might also like