SlideShare a Scribd company logo
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/

More Related Content

What's hot

STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
VENNILAV6
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
SQL
SQLSQL
Integrity and security
Integrity and securityIntegrity and security
Integrity and security
Surendra Karki Chettri
 
ch3
ch3ch3
SQL
SQLSQL
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
Smriti Jain
 
SQL
SQLSQL
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
KV(AFS) Utarlai, Barmer (Rajasthan)
 
Database queries
Database queriesDatabase queries
Database queries
IIUM
 
12 SQL
12 SQL12 SQL
Lab
LabLab
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
 
Sql commands
Sql commandsSql commands
Sql commands
Prof. Dr. K. Adisesha
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
Dr. C.V. Suresh Babu
 
Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013
Prosanta Ghosh
 
Sql basics
Sql  basicsSql  basics
Sql basics
Genesis Omo
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables

What's hot (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 to Assignment#01

12 SQL
12 SQL12 SQL
Ankit
AnkitAnkit
3. DDL.pdf
3. DDL.pdf3. DDL.pdf
3. DDL.pdf
Sunita Milind Dol
 
Oracle 11g SQL Overview
Oracle 11g SQL OverviewOracle 11g SQL Overview
Oracle 11g SQL Overview
Prathap Narayanappa
 
Sql
SqlSql
SQL2.pptx
SQL2.pptxSQL2.pptx
SQL2.pptx
RareDeath
 
chapter-14-sql-commands.pdf
chapter-14-sql-commands.pdfchapter-14-sql-commands.pdf
chapter-14-sql-commands.pdf
study material
 
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
 
Adbms
AdbmsAdbms
Adbms
jass12345
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
ARVIND SARDAR
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
lovely
lovelylovely
lovely
love0323
 
6_SQL.pdf
6_SQL.pdf6_SQL.pdf
6_SQL.pdf
LPhct2
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
SomeshwarMoholkar
 
SQL Query
SQL QuerySQL Query
SQL Query
Imam340267
 
Module02
Module02Module02
Module02
Sridhar P
 
Structure Query Language (SQL).pptx
Structure Query Language (SQL).pptxStructure Query Language (SQL).pptx
Structure Query Language (SQL).pptx
NalinaKumari2
 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
Nalina Kumari
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
Sherif Gad
 

Similar to 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
 

More from Sunita Milind Dol

Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
Unit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writingUnit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writing
Sunita Milind Dol
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
Unit Number 1 - Introduction to Research
Unit Number 1 - Introduction to ResearchUnit Number 1 - Introduction to Research
Unit Number 1 - Introduction to Research
Sunita Milind Dol
 
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
Unit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writingUnit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writing
Sunita Milind Dol
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
Unit Number 1 : Introduction to Research
Unit Number 1 : Introduction to ResearchUnit Number 1 : Introduction to Research
Unit Number 1 : Introduction to Research
Sunita Milind Dol
 
9.Joins.pdf
9.Joins.pdf9.Joins.pdf
9.Joins.pdf
Sunita Milind Dol
 
8.Views.pdf
8.Views.pdf8.Views.pdf
8.Views.pdf
Sunita Milind Dol
 
7. Nested Subqueries.pdf
7. Nested Subqueries.pdf7. Nested Subqueries.pdf
7. Nested Subqueries.pdf
Sunita Milind Dol
 
6. Aggregate Functions.pdf
6. Aggregate Functions.pdf6. Aggregate Functions.pdf
6. Aggregate Functions.pdf
Sunita Milind Dol
 
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
Sunita Milind Dol
 
4. DML.pdf
4. DML.pdf4. DML.pdf
4. DML.pdf
Sunita Milind Dol
 
2. SQL Introduction.pdf
2. SQL Introduction.pdf2. SQL Introduction.pdf
2. SQL Introduction.pdf
Sunita Milind Dol
 
1. University Example.pdf
1. University Example.pdf1. University Example.pdf
1. University Example.pdf
Sunita Milind Dol
 
Assignment12
Assignment12Assignment12
Assignment12
Sunita Milind Dol
 
Assignment11
Assignment11Assignment11
Assignment11
Sunita Milind Dol
 

More from Sunita Milind Dol (20)

Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
 
Unit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writingUnit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writing
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
 
Unit Number 1 - Introduction to Research
Unit Number 1 - Introduction to ResearchUnit Number 1 - Introduction to Research
Unit Number 1 - Introduction to Research
 
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
 
Unit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writingUnit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writing
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
 
Unit Number 1 : Introduction to Research
Unit Number 1 : Introduction to ResearchUnit Number 1 : Introduction to Research
Unit Number 1 : Introduction to Research
 
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
 

Recently uploaded

spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
amsjournal
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 

Recently uploaded (20)

spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 

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/