SlideShare a Scribd company logo
Creating a Database Chapter 13
DDL - D ata  D efinition  L anguage Define or create a new table Remove a table Change definition/structure of an existing table Define a virtual table(view) Make index Control physical storage of data
DDL consists of Create – Defining or creating database objects Drop – Removing an existing database object Alter – Changing definition of a database object
Create Table Define a new table Prepare to accept data  Creator becomes owner Table must have legal SQL name Name not already existing
Create Table (contd.)-Column Definitions Column name(mandatory)- unique for the table but can be repeated in other tables Data Type(mandatory)- also require size, if not given –default…(domain can be used) Required data- NOT NULL if required Default value- optional default value Constraints:Primary key,Foreign key,Unique,Check
Create table example create table  classmaster ( classid  varchar2(4) primary key, classname  varchar2(15) not null unique, intake  number(3));
Create table example Create table  classmaster2 ( classid  varchar2(4) , classname  varchar2(15) not null , intake  number(3), doa  date default '01-JUL-10', primary key(classid), unique(classname), check (intake between 0 and 100), Constraint  fk_clm_clname  foreign key(classname)  references classmaster(classname)  ) ;
Create table example Create table  studentmaster (  regno  varchar2(4) primary key, classid  varchar2(14) constraint  fk_sm_clsmstr   references  classmaster(classid) on delete set null, sfname   varchar2(20) not null, slname   varchar2(20) not null, DOB  date, DOA  date default ’01-JUL-10’, AdmStatus  char(1) check (admstatus in ('A','C','P')), freeship  char(1) check (freeship in ('Y','N')), check( doa>dob)); );
Creating table from another table Create table emp_copy as select * from emp; This command will create 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 table with selected columns and rows: Create table emp_fewcopy as select empno,ename,sal from emp where sal>1000;
Constraints Details of constraints can be obtained from the table user_constraints If constraint name is not declared dbms provides a name on its own
Removing a table DROP TABLE <table_name>; drop table classmaster2; Example:
Changing table definition Add a column definition to the table Drop a column Change the default value for 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 ALTER TABLE statement can:
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
Dropping a column Alter table classmaster drop intake; This statement drops the column named intake from the table classmaster.
Change 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;
Add or drop primary key for a column alter table  girls  add primary key (name); alter table  girls  drop primary key ; (Column_name) (Table_name)
Add or drop foreign key for a column alter table  emp  drop constraint   FK_DEPTNO ; Table altered alter table  emp  add constraint   fk_deptno  foreign key(deptno) references dept(deptno); Table altered
How to know constraint name select  constraint_name,constraint_type  from  user_constraints  where table_name='STUDENTMASTER'; CONSTRAINT_NAME   C ------------------------------ - SYS_C002715    C SYS_C002716  C SYS_C002717  C SYS_C002718  C SYS_C002719  P fk_sm_clsmstr R
Add or drop UNIQUE constraint for a column alter table  girls  add constraint   un_name  unique(name); Table altered alter table  girls  drop constraint   un_name ; Table altered
Add or drop CHECK constraint for a column alter table  girls  add constraint  chk_loc check(locality in  ('BORIVALI',‘KANDIVALI'); Table altered alter table  girls  drop constraint  chk_loc; Table altered
Add or drop NOT NULL constraint for a column alter table  girls  modify  locality not null; Table altered Get the constraint name from user_constraints alter table  girls  drop constraint  SYS_C002763 ; Table altered
Creating assertions and domains Create assertion <assertion_name> Check (check_condition) Create domain <domain_name>  <data type> check (check_condition) Drop assertion <assertion_name> Drop domain <domain_name> To alter the definitions of assertions or domains they must be first dropped and then recreated.
Creating  and Dropping Alias/Synonyms A synonym or alias is a name defined  by the user that stands for the name of some other table. Create synonym employee for emp; Synonym created Drop synonym employee; Synonym dropped
Indexes Provides rapid access to rows of a table based on values of one or more columns Stores data values and pointers to the rows where those values occur Data values arranged in ascending or descending order Presence of index transparent to user
Advantages- Speeds the execution of statements with search conditions referring to indexed columns Good for tables with more queries and less frequent change
Disadvantages X  Consumes additional disk space X must be updated when a row is added or indexed column is updated-additional overhead X Not worth when a column contains wide range of values or large number of null values DBMS automatically creates index on columns with unique constraint
Example Indexes For creating indexes create unique index ind_stm_sfname on studentmaster(sfname); create unique index ind_stm_slname_desc on studentmaster(slname desc); For removing indexes Drop index ind_stm_slname_desc ; To view details of indexes  - user_indexes
Types of Indexes Normal Function based B-tree Hash Bit map
Database structure Single database architecture Multi database architecture Multi location architecture Databases on multiple servers
Single database architecture DBMS supports one system wide database Tables in various applications can reference one another No choice is to be made as only one database-easy access Database grows huge as more and more applications are added Managing databases becomes difficult Examples- Oracle,DB2
Multi database architecture Each database assigned unique name Each database dedicated to particular application Divides data management tasks into smaller , manageable chunks Requires no overall coordination New application added as a new database,no need to disturb existing db Users remember structure of their db easily
Multi database architecture(contd.) Individual db become unconnected Table in one db cannot contain a foreign key reference to table in another db Cross db queries usually not supported Where ever allowed extended notation- db_name.owner.table_name Commands used to connect to other db Connect db_name Use db_name
Multi Location Architecture Supports multiple dbs by using system’s directory structure to organize them Each application has own database Each db in same directory has unique name Dbs may have same name in different directories Flexible-suited for applications where user needs his/her own applications in separate dbs
Multi Location Architecture(contd.) Disadvantages same as that of multi db. No master db to keep track of all dbs Gaining access to db objects difficult as directory name is to be specified
Databases on multiple servers Databases on a network Databases associated with named servers on a network Within one server db’s with different names Mapping of server names to physical server locations done by network software Mapping of db names to physical files on a server done by dbms
THANKS
Ad

More Related Content

What's hot (20)

Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
PadamNepal1
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
Smriti Jain
 
Basic Concept of Database
Basic Concept of DatabaseBasic Concept of Database
Basic Concept of Database
Marlon Jamera
 
1.4 data independence
1.4 data independence1.4 data independence
1.4 data independence
BHARATH KUMAR
 
Database systems
Database systemsDatabase systems
Database systems
Dhani Ahmad
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
SomeshwarMoholkar
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
Nishant Munjal
 
Html frames
Html framesHtml frames
Html frames
eShikshak
 
3 Level Architecture
3 Level Architecture3 Level Architecture
3 Level Architecture
Adeel Rasheed
 
Relational model
Relational modelRelational model
Relational model
Dabbal Singh Mahara
 
Components and Advantages of DBMS
Components and Advantages of DBMSComponents and Advantages of DBMS
Components and Advantages of DBMS
Shubham Joon
 
Advantages of DBMS
Advantages of DBMSAdvantages of DBMS
Advantages of DBMS
harshith singh
 
File and directory
File and directoryFile and directory
File and directory
Sunil Kafle
 
Lecture 01 introduction to database
Lecture 01 introduction to databaseLecture 01 introduction to database
Lecture 01 introduction to database
emailharmeet
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
Megha yadav
 
Structure of dbms
Structure of dbmsStructure of dbms
Structure of dbms
Megha yadav
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
Madhuri Kavade
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
webhostingguy
 
Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)
AakankshaR
 
File systems versus a dbms
File systems versus a dbmsFile systems versus a dbms
File systems versus a dbms
RituBhargava7
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
PadamNepal1
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
Smriti Jain
 
Basic Concept of Database
Basic Concept of DatabaseBasic Concept of Database
Basic Concept of Database
Marlon Jamera
 
1.4 data independence
1.4 data independence1.4 data independence
1.4 data independence
BHARATH KUMAR
 
Database systems
Database systemsDatabase systems
Database systems
Dhani Ahmad
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
Nishant Munjal
 
3 Level Architecture
3 Level Architecture3 Level Architecture
3 Level Architecture
Adeel Rasheed
 
Components and Advantages of DBMS
Components and Advantages of DBMSComponents and Advantages of DBMS
Components and Advantages of DBMS
Shubham Joon
 
File and directory
File and directoryFile and directory
File and directory
Sunil Kafle
 
Lecture 01 introduction to database
Lecture 01 introduction to databaseLecture 01 introduction to database
Lecture 01 introduction to database
emailharmeet
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
Megha yadav
 
Structure of dbms
Structure of dbmsStructure of dbms
Structure of dbms
Megha yadav
 
Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)
AakankshaR
 
File systems versus a dbms
File systems versus a dbmsFile systems versus a dbms
File systems versus a dbms
RituBhargava7
 

Viewers also liked (20)

Steps of-creating-a-database
Steps of-creating-a-databaseSteps of-creating-a-database
Steps of-creating-a-database
AIMS Education
 
Base1
Base1Base1
Base1
tclanton4
 
Creating database
Creating databaseCreating database
Creating database
Hitesh Kumar Markam
 
Databases
DatabasesDatabases
Databases
guestf77c65c
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Process
mussawir20
 
Database design process
Database design processDatabase design process
Database design process
Tayyab Hameed
 
Database Design Slide 1
Database Design Slide 1Database Design Slide 1
Database Design Slide 1
ahfiki
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
Pongsakorn U-chupala
 
Types dbms
Types dbmsTypes dbms
Types dbms
Avnish Shaw
 
Types of databases
Types of databasesTypes of databases
Types of databases
PAQUIAAIZEL
 
Views
ViewsViews
Views
Rahul Gupta
 
Practical auto layout
Practical auto layoutPractical auto layout
Practical auto layout
Inferis
 
Farhim NEW
Farhim NEWFarhim NEW
Farhim NEW
Farhim Shaikh
 
Sql wksht-2
Sql wksht-2Sql wksht-2
Sql wksht-2
Mukesh Tekwani
 
Creating Database 2010
Creating Database 2010Creating Database 2010
Creating Database 2010
tgushi12
 
It test
It testIt test
It test
shaikhanaas
 
New: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPNew: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPP
Rupesh Kumar
 
PROJECT MANAGEMENT - (2016) SEM-VI - PRACTICAL (SLIP) QUESTIONS
PROJECT MANAGEMENT - (2016) SEM-VI - PRACTICAL (SLIP) QUESTIONSPROJECT MANAGEMENT - (2016) SEM-VI - PRACTICAL (SLIP) QUESTIONS
PROJECT MANAGEMENT - (2016) SEM-VI - PRACTICAL (SLIP) QUESTIONS
Satyendra Singh
 
GIS
GISGIS
GIS
poonam.rwalia
 
Step by step how to create database with phpmyadmin
Step by step how to create database with phpmyadminStep by step how to create database with phpmyadmin
Step by step how to create database with phpmyadmin
Fathimah Azkiya
 
Steps of-creating-a-database
Steps of-creating-a-databaseSteps of-creating-a-database
Steps of-creating-a-database
AIMS Education
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Process
mussawir20
 
Database design process
Database design processDatabase design process
Database design process
Tayyab Hameed
 
Database Design Slide 1
Database Design Slide 1Database Design Slide 1
Database Design Slide 1
ahfiki
 
Types of databases
Types of databasesTypes of databases
Types of databases
PAQUIAAIZEL
 
Practical auto layout
Practical auto layoutPractical auto layout
Practical auto layout
Inferis
 
Creating Database 2010
Creating Database 2010Creating Database 2010
Creating Database 2010
tgushi12
 
New: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPNew: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPP
Rupesh Kumar
 
PROJECT MANAGEMENT - (2016) SEM-VI - PRACTICAL (SLIP) QUESTIONS
PROJECT MANAGEMENT - (2016) SEM-VI - PRACTICAL (SLIP) QUESTIONSPROJECT MANAGEMENT - (2016) SEM-VI - PRACTICAL (SLIP) QUESTIONS
PROJECT MANAGEMENT - (2016) SEM-VI - PRACTICAL (SLIP) QUESTIONS
Satyendra Singh
 
Step by step how to create database with phpmyadmin
Step by step how to create database with phpmyadminStep by step how to create database with phpmyadmin
Step by step how to create database with phpmyadmin
Fathimah Azkiya
 
Ad

Similar to Creating a database (20)

Database models and DBMS languages
Database models and DBMS languagesDatabase models and DBMS languages
Database models and DBMS languages
DivyaKS12
 
SQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) commandSQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) command
sonali sonavane
 
STRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGESTRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGE
SarithaDhanapal
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL
Rc Os
 
Module 3
Module 3Module 3
Module 3
cs19club
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.ppt
DrRShaliniVISTAS
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
HudaRaghibKadhim
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
SQl data base management and design
SQl     data base management  and designSQl     data base management  and design
SQl data base management and design
franckelsania20
 
Introduction to database and sql fir beginers
Introduction to database and sql fir beginersIntroduction to database and sql fir beginers
Introduction to database and sql fir beginers
reshmi30
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
SQL Queries - DDL Commands
SQL Queries - DDL CommandsSQL Queries - DDL Commands
SQL Queries - DDL Commands
ShubhamBauddh
 
Lab
LabLab
Lab
neelam_rawat
 
DBMS.pdf
DBMS.pdfDBMS.pdf
DBMS.pdf
Rishab Saini
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
NETsolutions Asia: NSA – Thailand, Sripatum University: SPU
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
Abrar ali
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
prathap kumar
 
Database models and DBMS languages
Database models and DBMS languagesDatabase models and DBMS languages
Database models and DBMS languages
DivyaKS12
 
SQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) commandSQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) command
sonali sonavane
 
STRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGESTRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGE
SarithaDhanapal
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL
Rc Os
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.ppt
DrRShaliniVISTAS
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
SQl data base management and design
SQl     data base management  and designSQl     data base management  and design
SQl data base management and design
franckelsania20
 
Introduction to database and sql fir beginers
Introduction to database and sql fir beginersIntroduction to database and sql fir beginers
Introduction to database and sql fir beginers
reshmi30
 
SQL Queries - DDL Commands
SQL Queries - DDL CommandsSQL Queries - DDL Commands
SQL Queries - DDL Commands
ShubhamBauddh
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
Abrar ali
 
Ad

Recently uploaded (20)

puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 

Creating a database

  • 1. Creating a Database Chapter 13
  • 2. DDL - D ata D efinition L anguage Define or create a new table Remove a table Change definition/structure of an existing table Define a virtual table(view) Make index Control physical storage of data
  • 3. DDL consists of Create – Defining or creating database objects Drop – Removing an existing database object Alter – Changing definition of a database object
  • 4. Create Table Define a new table Prepare to accept data Creator becomes owner Table must have legal SQL name Name not already existing
  • 5. Create Table (contd.)-Column Definitions Column name(mandatory)- unique for the table but can be repeated in other tables Data Type(mandatory)- also require size, if not given –default…(domain can be used) Required data- NOT NULL if required Default value- optional default value Constraints:Primary key,Foreign key,Unique,Check
  • 6. Create table example create table classmaster ( classid varchar2(4) primary key, classname varchar2(15) not null unique, intake number(3));
  • 7. Create table example Create table classmaster2 ( classid varchar2(4) , classname varchar2(15) not null , intake number(3), doa date default '01-JUL-10', primary key(classid), unique(classname), check (intake between 0 and 100), Constraint fk_clm_clname foreign key(classname) references classmaster(classname) ) ;
  • 8. Create table example Create table studentmaster ( regno varchar2(4) primary key, classid varchar2(14) constraint fk_sm_clsmstr references classmaster(classid) on delete set null, sfname varchar2(20) not null, slname varchar2(20) not null, DOB date, DOA date default ’01-JUL-10’, AdmStatus char(1) check (admstatus in ('A','C','P')), freeship char(1) check (freeship in ('Y','N')), check( doa>dob)); );
  • 9. Creating table from another table Create table emp_copy as select * from emp; This command will create 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 table with selected columns and rows: Create table emp_fewcopy as select empno,ename,sal from emp where sal>1000;
  • 10. Constraints Details of constraints can be obtained from the table user_constraints If constraint name is not declared dbms provides a name on its own
  • 11. Removing a table DROP TABLE <table_name>; drop table classmaster2; Example:
  • 12. Changing table definition Add a column definition to the table Drop a column Change the default value for 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 ALTER TABLE statement can:
  • 13. 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
  • 14. Dropping a column Alter table classmaster drop intake; This statement drops the column named intake from the table classmaster.
  • 15. Change 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;
  • 16. Add or drop primary key for a column alter table girls add primary key (name); alter table girls drop primary key ; (Column_name) (Table_name)
  • 17. Add or drop foreign key for a column alter table emp drop constraint FK_DEPTNO ; Table altered alter table emp add constraint fk_deptno foreign key(deptno) references dept(deptno); Table altered
  • 18. How to know constraint name select constraint_name,constraint_type from user_constraints where table_name='STUDENTMASTER'; CONSTRAINT_NAME C ------------------------------ - SYS_C002715 C SYS_C002716 C SYS_C002717 C SYS_C002718 C SYS_C002719 P fk_sm_clsmstr R
  • 19. Add or drop UNIQUE constraint for a column alter table girls add constraint un_name unique(name); Table altered alter table girls drop constraint un_name ; Table altered
  • 20. Add or drop CHECK constraint for a column alter table girls add constraint chk_loc check(locality in ('BORIVALI',‘KANDIVALI'); Table altered alter table girls drop constraint chk_loc; Table altered
  • 21. Add or drop NOT NULL constraint for a column alter table girls modify locality not null; Table altered Get the constraint name from user_constraints alter table girls drop constraint SYS_C002763 ; Table altered
  • 22. Creating assertions and domains Create assertion <assertion_name> Check (check_condition) Create domain <domain_name> <data type> check (check_condition) Drop assertion <assertion_name> Drop domain <domain_name> To alter the definitions of assertions or domains they must be first dropped and then recreated.
  • 23. Creating and Dropping Alias/Synonyms A synonym or alias is a name defined by the user that stands for the name of some other table. Create synonym employee for emp; Synonym created Drop synonym employee; Synonym dropped
  • 24. Indexes Provides rapid access to rows of a table based on values of one or more columns Stores data values and pointers to the rows where those values occur Data values arranged in ascending or descending order Presence of index transparent to user
  • 25. Advantages- Speeds the execution of statements with search conditions referring to indexed columns Good for tables with more queries and less frequent change
  • 26. Disadvantages X Consumes additional disk space X must be updated when a row is added or indexed column is updated-additional overhead X Not worth when a column contains wide range of values or large number of null values DBMS automatically creates index on columns with unique constraint
  • 27. Example Indexes For creating indexes create unique index ind_stm_sfname on studentmaster(sfname); create unique index ind_stm_slname_desc on studentmaster(slname desc); For removing indexes Drop index ind_stm_slname_desc ; To view details of indexes - user_indexes
  • 28. Types of Indexes Normal Function based B-tree Hash Bit map
  • 29. Database structure Single database architecture Multi database architecture Multi location architecture Databases on multiple servers
  • 30. Single database architecture DBMS supports one system wide database Tables in various applications can reference one another No choice is to be made as only one database-easy access Database grows huge as more and more applications are added Managing databases becomes difficult Examples- Oracle,DB2
  • 31. Multi database architecture Each database assigned unique name Each database dedicated to particular application Divides data management tasks into smaller , manageable chunks Requires no overall coordination New application added as a new database,no need to disturb existing db Users remember structure of their db easily
  • 32. Multi database architecture(contd.) Individual db become unconnected Table in one db cannot contain a foreign key reference to table in another db Cross db queries usually not supported Where ever allowed extended notation- db_name.owner.table_name Commands used to connect to other db Connect db_name Use db_name
  • 33. Multi Location Architecture Supports multiple dbs by using system’s directory structure to organize them Each application has own database Each db in same directory has unique name Dbs may have same name in different directories Flexible-suited for applications where user needs his/her own applications in separate dbs
  • 34. Multi Location Architecture(contd.) Disadvantages same as that of multi db. No master db to keep track of all dbs Gaining access to db objects difficult as directory name is to be specified
  • 35. Databases on multiple servers Databases on a network Databases associated with named servers on a network Within one server db’s with different names Mapping of server names to physical server locations done by network software Mapping of db names to physical files on a server done by dbms
  翻译: