You are on page 1of 28

Activity in Computer Education

By: Camille Camila Salvadora


z
z

How to create a Database.


z

DDL- Data Definition Language

§ • Define or create a new table.


§ • Remove a table.
§ • Change structure of an existing table.
§ • Define a virtual table ( view).
§ • Make index.
§ • Control physical storage of data.
§
z

DDL CONSIST OF:

§ • Create – Defining or creating database objects.


§ • Drop – Removing an existing database
objects.
§ • Alter- Changing definition of a database
objects.
z
CREATE TABLE

• Define a new table.

• Prepare to accept data.

• Creator becomes owner.

• Table must have a legal SQL name.

• Name not already existing.


z
• COLUMN TABLE ( contd.) -
COLUMN DEFINITION

• Column Name ( mandatory) - unique for the table but can


be repeated for the other table.

• Data Type ( mandatory) - also require size if not given.

•Required Data- NOT FULL required

• Default Value- optional default value

• Constaints : Primary key, Foreign key, Unique , Check


z

CREATE TABLE EXAMPLE


Create table classmaster
( classid varchar2(4) primary key,
Classname varchar2(15) not null unique
Intake number (3)));
z
CREATING TABLE FROM OTHER TABLE

Create table emp_copy as select * from emp;


• This command will make a table named emp_copy with the same
structure and all records of the table emp.
• To create a table with the same structure without any records:
      Create table emp_str_copy as select * from emp where 1=2
• To create the table with the selected columns and rows:
       Create table emp_fewcopy as select empno,ename, sal from
emp where sal>1000;
z

CONSTRAINTS
• Detail of constraints can be obtained from the table
user_constraints
• If constraints name is not declared dbms provide a
name of it's own
REMOVING A TABLE
z

• DROP TABLE < table_name>;

Example: 
Drop table classmaster2;
z CHANGING TABLE DEFINITION

ALTER TABLE statement can: 


Ø Add a column definition to the table.

Ø Drop a column.

Ø Change the default value of a column.

Ø Add or drop a primary key for a table.

Ø Add or drop a foreign key for a table.

Ø Add or drop a unique constraint for a table.

Ø Add or drop a check constraint for a table

Ø Add or drop a not null constraint for a table


Ø
z
ADDING A COLUMN          

Alter table studentmaster add contact _no varchar2(20)

§ Usually not null not given or if given should be with a default


value.
§ If data already present, adding a column with not null will violate
not null constraint.
z

DROPPING A COLUMN

Alter table classmaster drop intake: 

This statement drops the column named intake from


the table classmaster
CHANGE
z
THE DEFAULT VALUE
FOR A COLUMN            

Ø Alter table girls modify locality default 'BORIVALI'; 


Ø Alter table classmaster modify classname default 'TYBScIT'
Ø Alter table classmaster modify classname default NULL; 
z

ADD OR DROP PRIMARY


KEY FOR A COLUMN
Ø Alter table girls add primary key (name);

        (table name)         (column_name)


Ø Alter table girls drop primary key;
z
ADD OR DROP FOREIGN KEY
TO A COLUMN

Ø Alter table emp drop constraint FK_DEPTNO;


Table altered
Ø Alter table emp add constraint fk_deptno foreign key (deptno)
references key (deptno);
Table altered
z

How to know constraint


name:
Ø Select constraint_name,constraint_type from
user_constraints where table_name=
'STUDENTMASTER';
Ø
z
Add or drop NOT NULL
constraint for a column

Ø Alter table girls modify locality not null;


Table altered
Get the constraints name from user_constraints
Ø Alter table girls drop constraints SYS_C002763;

Table altered
z

CREATING/DROPPING ALIAS
OR SYNONYMS
Ø A synonym or alias is a name defined by the user
that stands as a name of a people on the table
Ø Create synonym employee for emp; 

synonym created
Ø Drop synonym employee:

synonym dropped
INDEXES
z

§ Provides rapid access to row of a table based on values of one


or more columns.
§ Stores data values and pointers to the rows where those where
those values occur.
§ Data values arranged in ascending or descending order.
§ Presence of index transparent to user. 
z

ü Speeds the execution of statements


with search conditions referring to
ADVANTAGES index column.
ü Good for tables with more queries and
less frequent change.
z
DISADVANTAGES 

×  Consumes additional disk space.

× Must be updated when a row is added or


indexed column is updated –additional overhead

× Not worth when when a column contains wide


range of values or large number of null values 
z

TYPE OF INDEXES

§ Normal

§ Function based 

§ B-tree

§ Hash 

§ Bit map
z
DATA BASE STRUCTURE

Ø Single database architecture

Ø Multi-database architecture

Ø Multi-location architecture

Ø Database on multiple database


z

Ø DBMS supports one system wide database


Ø Tables on different applications can refference
to each other
SINGLE
DATABASE No choice is to be made by as only database-
Ø
easy access
ARCHITECTURE Ø Managing databases becomes difficult.
Ø Example; oracle,DB2
z

§ Each database assigned unique name. 


§ Each database dedicated to particular
application.

MULTI- § Divides data management into smaller


DATABASE chunks.
ARCHITECTURE § Requires no overall coordination.
§ New application added as a
new database.
§ Users remember structure of their db
easily
z

§ Supports multiple dbs by using system's directory


structure to organize them.

MULTI- § Each application has own database

LOCATION § Each db in same directory has unique name.


ARCHITECTURE § Dbs may have same name in different directories.
§ Flexible-suited for applications where user needs
his/her own application in separate db. 
z
Database on multiple servers 

§ Database on a network
§ Database associated with named servers on a network 
§ Within one servers db's in different name
§ Mapping of server names to physical server locations done by
network software 
§ Mapping of db namesto physical files on a server done by
dbms.
z

z THANKS!

You might also like