07 Creating Managing Tables
07 Creating Managing Tables
Chapter Content :
Create Table
What is Table ? Columns
Two Dimensional Structure consists of rows and columns used to store data
Y ( rows ) Employee
Employee Number Employee Name Employee Job Salary
7788 SCOTT Analyst 200
Rows 7789 alen Sales 100
X ( Columns )
Chapter 07 : Creating and Managing Tables
)
Chapter 07 : Creating and Managing Tables
Naming Rules
1. Maximum number of Character = 30 ( length = 30 )
2. A-Z , a –z , 0-9 ( it must start with character )
3. # $ _
4. Can not be Oracle key word
Chapter 07 : Creating and Managing Tables
Data Type
Number : Employee Number , id number
Salary , Quantity , Commission , Size , Weight , Height
Number ( n ) : Number (2) , Number ( 4 ) Number ( 38 ) = Integer , Number = Number (38 )
Number (m,n) : Number ( 7 , 2 ) 9999.99
Characters : Name , Address , Job , Description , Location
Varchar2(n) : Varchar2(30) varchar2(32000)
Char (m) : Char(30) char(2000)
Constraint Types :
not null : Required ( Must be entered ) Ex., Constraint emp_name_nn not null
Check : Condition or Rule on your column Ex. Constraint emp_sal_ck check ( sal>0 )
unique : No Duplication in values Ex. Constraint emp_id_UQ Unique ( ID)
Foreign Key :
Primary Key :
Chapter 07 : Creating and Managing Tables
alter table emp add constraint emp_sal_ck check ( sal > 1000) ;
alter table emp disable constraint emp_sal_ck ;
alter table emp enable constraint emp_sal_ck ;
alter table emp rename constraint emp_sal_ck to emp_sal_check ;
alter table emp drop constraint emp_sal_check ;
Managing Tables
Rename :
Rename old_name to new_name rename emp2 to emp3
Truncate :
data removed permanent
Storage area removed permanent
Keep Table definition
Drop :
data removed permanent
Storage area removed permanent
Definition Removed from database
Drop table table_name Drop Table dept2
Chapter 07 : Creating and Managing Tables
SQL Practice
A : text varchar2
“*”: not null constraint
O : Optional
# : Primary key
Chapter 07 : Creating and Managing Tables
SQL Practice
Chapter 07 : Creating and Managing Tables
SQL Practice
Chapter 07 : Creating and Managing Tables
SQL Practice
Chapter 07 : Creating and Managing Tables
SQL Practice