SlideShare una empresa de Scribd logo
1 de 6
Descargar para leer sin conexión
Database System Sunita M. Dol
Page 1
HANDOUT#01
Aim:
Implementation of SQL DDL commands- CREATE, ALTER, DROP and constraints on
relations link Primary Key, Foreign Key and Check
Theory:
The SQL(Structured Query Language) Language has several parts:
1. Data-definition language (DDL). The SQL DDL provides commands for defining
relation schemas, deleting relations, and modifying relation schemas.
2. Interactive data-manipulation language (DML). The SQL DML includes a query
language based on both the relational algebra and the tuple relational calculus. It
includes also commands to insert tuples into, delete tuples from, and modify tuples in
the database.
3. View definition. The SQL DDL includes commands for defining views.
4. Transaction control. SQL includes commands for specifying the beginning and
ending of transactions.
5. Embedded SQL and dynamic SQL. Embedded and dynamic SQL define how SQL
statements can be embedded within general-purpose programming languages, such as
C, C++, Java, PL/I, Cobol, Pascal, and Fortran.
6. Integrity. The SQL DDL includes commands for specifying integrity constraints that
the data stored in the database must satisfy. Updates that violate integrity constraints
are disallowed.
7. Authorization. The SQL DDL includes commands for specifying access rights to
relations and views.
Domain Types in SQL:
char(n). Fixed length character string, with user-specified length n.
varchar(n). Variable length character strings, with user-specified maximum length
n.
int. Integer (a finite subset of the integers that is machine-dependent).
smallint. Small integer (a machine-dependent subset of the integer domain type).
numeric(p,d). Fixed point number, with user-specified precision of p digits, with n
digits to the right of decimal point.
real, double precision. Floating point and double-precision floating point numbers,
with machine-dependent precision.
float(n). Floating point number, with user-specified precision of at least n digits.
Database System Sunita M. Dol
Page 2
DDL
Data Definition Language (DDL) allows the specification of not only a set of relations but also
information about each relation, including:
The schema for each relation.
The domain of values associated with each attribute.
Integrity constraints
The set of indices to be maintained for each relations.
Security and authorization information for each relation.
The physical storage structure of each relation on disk.
Following are the DDL commands
CREATE
ALTER
DROP
CREATE Command
An SQL relation is defined using the create table command:
create table r (A1 D1, A2 D2, ..., An Dn,
(integrity-constraint1),
...,
(integrity-constraintk))
• r is the name of the relation
• each Ai is an attribute name in the schema of relation r
• Di is the data type of values in the domain of attribute Ai
Constraints on relations
• primary key (Aj1 , Aj2, . . . , Ajm ): The primary-key specification says that
attributes Aj1 , Aj2, . . . , Ajm form the primary key for the relation. The primary
key attributes are required to be nonnull and unique
• foreign key (Ak1 , Ak2, . . . , Akn ) references s: The foreign key specification
says that the values of attributes (Ak1 , Ak2, . . . , Akn ) for any tuple in the relation
must correspond to values of the primary key attributes of some tuple in relation s.
• not null: The not null constraint on an attribute specifies that the null value is not
allowed for that attribute; in other words, the constraint excludes the null value
from the domain of that attribute.
• check(P): The check clause specifies a predicate P that must be satisfied by every
tuple in the relation.
ALTER Command
The Oracle ALTER TABLE statement is used to add, modify, or drop/delete columns in a table.
Database System Sunita M. Dol
Page 3
Add column in table
To ADD A COLUMN in a table, the Oracle ALTER TABLE syntax is:
ALTER TABLE table_name
ADD column_name column-definition;
Add multiple columns in table
To ADD MULTIPLE COLUMNS to an existing table, the Oracle ALTER TABLE
syntax is:
ALTER TABLE table_name
ADD (column_1 column-definition,
column_2 column-definition,
...
column_n column_definition);
Modify column in table
To MODIFY A COLUMN in an existing table, the Oracle ALTER TABLE syntax is:
ALTER TABLE table_name
MODIFY column_name column_type;
Modify Multiple columns in table
To MODIFY MULTIPLE COLUMNS in an existing table, the Oracle ALTER TABLE
syntax is:
ALTER TABLE table_name
MODIFY (column_1 column_type,
column_2 column_type,
...
column_n column_type);
Drop column in table
To DROP A COLUMN in an existing table, the Oracle ALTER TABLE syntax is:
ALTER TABLE table_name
DROP COLUMN column_name;
DROP Command
To remove a relation from an SQL database, we use the drop table command. The drop
table command deletes all information about the dropped relation from the database. The
command
drop table r
is a more drastic action than
Database System Sunita M. Dol
Page 4
delete from r
The latter retains relation r, but deletes all tuples in r. The former deletes not only all
tuples of r, but also the schema for r. After r is dropped, no tuples can be inserted into r
unless it is re-created with the create table command.
Queries and Output:
CREATE Command and Adding Constraints on Relation
SQL> create table branch
2 (branch_name char(15),
3 branch_city char(15),
4 assets numeric(16,2),
5 primary key(branch_name),
6 check(assets>=0));
Table created.
SQL> desc branch;
Name Null? Type
----------------------------------------- -------- ----------------------------
BRANCH_NAME NOT NULL CHAR(15)
BRANCH_CITY CHAR(15)
ASSETS NUMBER(16,2)
SQL> create table account
2 (account_number char(10),
3 branch_name char(15),
4 balance numeric(12,2),
5 primary key(account_number),
6 foreign key(branch_name)references branch,
7 check(balance>=0));
Table created.
SQL> desc account;
Name Null? Type
----------------------------------------- -------- ----------------------------
ACCOUNT_NUMBER NOT NULL CHAR(10)
BRANCH_NAME CHAR(15)
BALANCE NUMBER(12,2)
Database System Sunita M. Dol
Page 5
SQL> create table student(roll_no char(10),first_name char(30),middle_name
char(30),last_name char(3
0),address char(50),city char(20),pincode numeric(6,0),state char(20),mobile_number integer);
Table created.
ALTER Command
SQL> desc student;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROLL_NO CHAR(10)
FIRST_NAME CHAR(30)
MIDDLE_NAME CHAR(30)
LAST_NAME CHAR(30)
ADDRESS CHAR(50)
CITY CHAR(20)
PINCODE NUMBER(6)
STATE CHAR(20)
MOBILE_NUMBER NUMBER(38)
SQL> alter table student drop column mobile_number;
Table altered.
SQL> desc student;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROLL_NO CHAR(10)
FIRST_NAME CHAR(30)
MIDDLE_NAME CHAR(30)
LAST_NAME CHAR(30)
ADDRESS CHAR(50)
CITY CHAR(20)
PINCODE NUMBER(6)
STATE CHAR(20)
DROP Command
SQL> desc student;
Name Null? Type
Database System Sunita M. Dol
Page 6
----------------------------------------- -------- ----------------------------
ROLL_NO CHAR(10)
FIRST_NAME CHAR(30)
MIDDLE_NAME CHAR(30)
LAST_NAME CHAR(30)
ADDRESS CHAR(50)
CITY CHAR(20)
PINCODE NUMBER(6)
STATE CHAR(20)
MOBILE_NUMBER VARCHAR2(10)
SQL> drop table student;
Table dropped.
SQL> desc student;
ERROR:
ORA-04043: object student does not exist
Conclusion:
We have studied the various DDL command
a. CREATE Command
b. ALTER Command
c. DROP Command and
d. Constraints like Primary Key, Foreign Key and Check
References:
• Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) sixth edition.
• Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) fifth edition.
• http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/
• http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/
• http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/

Más contenido relacionado

La actualidad más candente (19)

STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
SQL
SQLSQL
SQL
 
Integrity and security
Integrity and securityIntegrity and security
Integrity and security
 
ch3
ch3ch3
ch3
 
SQL
SQLSQL
SQL
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
SQL
SQLSQL
SQL
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
Database queries
Database queriesDatabase queries
Database queries
 
12 SQL
12 SQL12 SQL
12 SQL
 
Lab
LabLab
Lab
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013
 
Sql basics
Sql  basicsSql  basics
Sql basics
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 

Similar a Assignment#01

Similar a Assignment#01 (20)

12 SQL
12 SQL12 SQL
12 SQL
 
Ankit
AnkitAnkit
Ankit
 
3. DDL.pdf
3. DDL.pdf3. DDL.pdf
3. DDL.pdf
 
Oracle 11g SQL Overview
Oracle 11g SQL OverviewOracle 11g SQL Overview
Oracle 11g SQL Overview
 
Sql
SqlSql
Sql
 
SQL2.pptx
SQL2.pptxSQL2.pptx
SQL2.pptx
 
chapter-14-sql-commands.pdf
chapter-14-sql-commands.pdfchapter-14-sql-commands.pdf
chapter-14-sql-commands.pdf
 
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...
 
Adbms
AdbmsAdbms
Adbms
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
 
lovely
lovelylovely
lovely
 
6_SQL.pdf
6_SQL.pdf6_SQL.pdf
6_SQL.pdf
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Module02
Module02Module02
Module02
 
Structure Query Language (SQL).pptx
Structure Query Language (SQL).pptxStructure Query Language (SQL).pptx
Structure Query Language (SQL).pptx
 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 

Más de Sunita Milind Dol (20)

9.Joins.pdf
9.Joins.pdf9.Joins.pdf
9.Joins.pdf
 
8.Views.pdf
8.Views.pdf8.Views.pdf
8.Views.pdf
 
7. Nested Subqueries.pdf
7. Nested Subqueries.pdf7. Nested Subqueries.pdf
7. Nested Subqueries.pdf
 
6. Aggregate Functions.pdf
6. Aggregate Functions.pdf6. Aggregate Functions.pdf
6. Aggregate Functions.pdf
 
5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf
 
4. DML.pdf
4. DML.pdf4. DML.pdf
4. DML.pdf
 
2. SQL Introduction.pdf
2. SQL Introduction.pdf2. SQL Introduction.pdf
2. SQL Introduction.pdf
 
1. University Example.pdf
1. University Example.pdf1. University Example.pdf
1. University Example.pdf
 
Assignment12
Assignment12Assignment12
Assignment12
 
Assignment11
Assignment11Assignment11
Assignment11
 
Assignment10
Assignment10Assignment10
Assignment10
 
Assignment9
Assignment9Assignment9
Assignment9
 
Assignment8
Assignment8Assignment8
Assignment8
 
Assignment7
Assignment7Assignment7
Assignment7
 
Assignment6
Assignment6Assignment6
Assignment6
 
Assignment5
Assignment5Assignment5
Assignment5
 
Assignment4
Assignment4Assignment4
Assignment4
 
Assignment3
Assignment3Assignment3
Assignment3
 
Assignment2
Assignment2Assignment2
Assignment2
 
Assignment1
Assignment1Assignment1
Assignment1
 

Último

Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 

Último (20)

Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 

Assignment#01

  • 1. Database System Sunita M. Dol Page 1 HANDOUT#01 Aim: Implementation of SQL DDL commands- CREATE, ALTER, DROP and constraints on relations link Primary Key, Foreign Key and Check Theory: The SQL(Structured Query Language) Language has several parts: 1. Data-definition language (DDL). The SQL DDL provides commands for defining relation schemas, deleting relations, and modifying relation schemas. 2. Interactive data-manipulation language (DML). The SQL DML includes a query language based on both the relational algebra and the tuple relational calculus. It includes also commands to insert tuples into, delete tuples from, and modify tuples in the database. 3. View definition. The SQL DDL includes commands for defining views. 4. Transaction control. SQL includes commands for specifying the beginning and ending of transactions. 5. Embedded SQL and dynamic SQL. Embedded and dynamic SQL define how SQL statements can be embedded within general-purpose programming languages, such as C, C++, Java, PL/I, Cobol, Pascal, and Fortran. 6. Integrity. The SQL DDL includes commands for specifying integrity constraints that the data stored in the database must satisfy. Updates that violate integrity constraints are disallowed. 7. Authorization. The SQL DDL includes commands for specifying access rights to relations and views. Domain Types in SQL: char(n). Fixed length character string, with user-specified length n. varchar(n). Variable length character strings, with user-specified maximum length n. int. Integer (a finite subset of the integers that is machine-dependent). smallint. Small integer (a machine-dependent subset of the integer domain type). numeric(p,d). Fixed point number, with user-specified precision of p digits, with n digits to the right of decimal point. real, double precision. Floating point and double-precision floating point numbers, with machine-dependent precision. float(n). Floating point number, with user-specified precision of at least n digits.
  • 2. Database System Sunita M. Dol Page 2 DDL Data Definition Language (DDL) allows the specification of not only a set of relations but also information about each relation, including: The schema for each relation. The domain of values associated with each attribute. Integrity constraints The set of indices to be maintained for each relations. Security and authorization information for each relation. The physical storage structure of each relation on disk. Following are the DDL commands CREATE ALTER DROP CREATE Command An SQL relation is defined using the create table command: create table r (A1 D1, A2 D2, ..., An Dn, (integrity-constraint1), ..., (integrity-constraintk)) • r is the name of the relation • each Ai is an attribute name in the schema of relation r • Di is the data type of values in the domain of attribute Ai Constraints on relations • primary key (Aj1 , Aj2, . . . , Ajm ): The primary-key specification says that attributes Aj1 , Aj2, . . . , Ajm form the primary key for the relation. The primary key attributes are required to be nonnull and unique • foreign key (Ak1 , Ak2, . . . , Akn ) references s: The foreign key specification says that the values of attributes (Ak1 , Ak2, . . . , Akn ) for any tuple in the relation must correspond to values of the primary key attributes of some tuple in relation s. • not null: The not null constraint on an attribute specifies that the null value is not allowed for that attribute; in other words, the constraint excludes the null value from the domain of that attribute. • check(P): The check clause specifies a predicate P that must be satisfied by every tuple in the relation. ALTER Command The Oracle ALTER TABLE statement is used to add, modify, or drop/delete columns in a table.
  • 3. Database System Sunita M. Dol Page 3 Add column in table To ADD A COLUMN in a table, the Oracle ALTER TABLE syntax is: ALTER TABLE table_name ADD column_name column-definition; Add multiple columns in table To ADD MULTIPLE COLUMNS to an existing table, the Oracle ALTER TABLE syntax is: ALTER TABLE table_name ADD (column_1 column-definition, column_2 column-definition, ... column_n column_definition); Modify column in table To MODIFY A COLUMN in an existing table, the Oracle ALTER TABLE syntax is: ALTER TABLE table_name MODIFY column_name column_type; Modify Multiple columns in table To MODIFY MULTIPLE COLUMNS in an existing table, the Oracle ALTER TABLE syntax is: ALTER TABLE table_name MODIFY (column_1 column_type, column_2 column_type, ... column_n column_type); Drop column in table To DROP A COLUMN in an existing table, the Oracle ALTER TABLE syntax is: ALTER TABLE table_name DROP COLUMN column_name; DROP Command To remove a relation from an SQL database, we use the drop table command. The drop table command deletes all information about the dropped relation from the database. The command drop table r is a more drastic action than
  • 4. Database System Sunita M. Dol Page 4 delete from r The latter retains relation r, but deletes all tuples in r. The former deletes not only all tuples of r, but also the schema for r. After r is dropped, no tuples can be inserted into r unless it is re-created with the create table command. Queries and Output: CREATE Command and Adding Constraints on Relation SQL> create table branch 2 (branch_name char(15), 3 branch_city char(15), 4 assets numeric(16,2), 5 primary key(branch_name), 6 check(assets>=0)); Table created. SQL> desc branch; Name Null? Type ----------------------------------------- -------- ---------------------------- BRANCH_NAME NOT NULL CHAR(15) BRANCH_CITY CHAR(15) ASSETS NUMBER(16,2) SQL> create table account 2 (account_number char(10), 3 branch_name char(15), 4 balance numeric(12,2), 5 primary key(account_number), 6 foreign key(branch_name)references branch, 7 check(balance>=0)); Table created. SQL> desc account; Name Null? Type ----------------------------------------- -------- ---------------------------- ACCOUNT_NUMBER NOT NULL CHAR(10) BRANCH_NAME CHAR(15) BALANCE NUMBER(12,2)
  • 5. Database System Sunita M. Dol Page 5 SQL> create table student(roll_no char(10),first_name char(30),middle_name char(30),last_name char(3 0),address char(50),city char(20),pincode numeric(6,0),state char(20),mobile_number integer); Table created. ALTER Command SQL> desc student; Name Null? Type ----------------------------------------- -------- ---------------------------- ROLL_NO CHAR(10) FIRST_NAME CHAR(30) MIDDLE_NAME CHAR(30) LAST_NAME CHAR(30) ADDRESS CHAR(50) CITY CHAR(20) PINCODE NUMBER(6) STATE CHAR(20) MOBILE_NUMBER NUMBER(38) SQL> alter table student drop column mobile_number; Table altered. SQL> desc student; Name Null? Type ----------------------------------------- -------- ---------------------------- ROLL_NO CHAR(10) FIRST_NAME CHAR(30) MIDDLE_NAME CHAR(30) LAST_NAME CHAR(30) ADDRESS CHAR(50) CITY CHAR(20) PINCODE NUMBER(6) STATE CHAR(20) DROP Command SQL> desc student; Name Null? Type
  • 6. Database System Sunita M. Dol Page 6 ----------------------------------------- -------- ---------------------------- ROLL_NO CHAR(10) FIRST_NAME CHAR(30) MIDDLE_NAME CHAR(30) LAST_NAME CHAR(30) ADDRESS CHAR(50) CITY CHAR(20) PINCODE NUMBER(6) STATE CHAR(20) MOBILE_NUMBER VARCHAR2(10) SQL> drop table student; Table dropped. SQL> desc student; ERROR: ORA-04043: object student does not exist Conclusion: We have studied the various DDL command a. CREATE Command b. ALTER Command c. DROP Command and d. Constraints like Primary Key, Foreign Key and Check References: • Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) sixth edition. • Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) fifth edition. • http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/ • http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/ • http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/