SlideShare une entreprise Scribd logo
1  sur  71
DBMS Owned By
MySQL, Open Source RDMS
MS Access Microsoft
Oracle Oracle Corporation(ORDMS)
Sybase SAP Company
SQL Server Microsoft (RDMS)
Postgresql Open Source RDMS
Informix IBM(RDMS)
Primary Key
Foreign Key
Unique
Check
NOT NULL/NULL
Defined at Column Level
Defined at Table Level
UNIQUE
NOT NULL
NOT COMPULSORY
CANNOT LONG/LONG RAW DATA TYPE
ONLY ONE PER TABLE
COMBINE UPTO 16 COLOUMNS
IN A COMPOSITE PRIMARY KEY
<Column Name> <Data type> (<Size>) PRIMARY KEY
EX:
CREATE TABLE LBS_CS2(
NAME VARCHAR2(25) PRIMARY KEY
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
);
PRIMARY KEY (<Column Name> , <Column Name> )
EX:
CREATE TABLE LBS_CS2(
NO INT,
NAME VARCHAR2(25),
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
PRIMARY KEY(NO,NAME)
);
Parent must be UNIQUE OR PRIMARY KEY
Child may have DUPLICATE/NULL
 Constraint specify on child not in parent
Parent can delete only if child not exist
Parent cannot modify if child exist
<Column Name> <Data type> (<Size>)
REFERENCES <TABLE NAME>[(<Column Name>)]
[ON DELETE CASCADE]
EX:
CREATE TABLE LBS_CS2(
ROLL_NO INT,
NAME VARCHAR2(25),
BRANCH_CODE VARCHAR2(25) REFERENCES BRANCH,
- - - - - - - - - - - - - - - - - -
PRIMARY KEY(NO,NAME)
);
EX:
CREATE TABLE LBS_CS2(
ROLL_NO INT,
NAME VARCHAR2(25),
BRANCH_CODE VARCHAR2(25)
REFERENCES BRANCH (BRANCH_ID),
- - - - - - - - - - - - - - - - - -
PRIMARY KEY(NO,NAME)
);
FOREIGN KEY(<Column Name>[ <Column Name>] )
REFERENCES
<TABLE NAME> [(<Column Name> <Column Name>] )]
[ON DELETE SET NULL]
EX:
CREATE TABLE LBS_CS2(
ROLL_NO INT,
NAME VARCHAR2(25),
FOREIGN KEY (BRANCH_CODE) REFERENCES BRANCH(BRANCH_ID),
- - - - - - - - - - - - - - - - - -
PRIMARY KEY(NO,NAME)
);
<Column Name> <Data type> (<Size>) UNIQUE
EX:
CREATE TABLE LBS_CS2(
ROLL_NUM INT UNIQUE,
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
);
UNIQUE (<Column Name> , <Column Name> )
EX:
CREATE TABLE LBS_CS2(
NO INT,
NAME VARCHAR2(25),
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
UNIQUE(NO,NAME)
);
<Column Name> <Data type> (<Size>) NOT NULL
EX:
CREATE TABLE LBS_CS2(
ROLL_NUM INT NOT NULL,
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
);
<Column Name> <Data type> (<Size>) CHECK (<Logical Expression>)
EX:
CREATE TABLE LBS_CS2(
ROLL_NUM INT CHECK (ROLL_NUM > 0)
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
);
CHECK(<Logical Expression>)
EX:
CREATE TABLE LBS_CS2(
ROLL_NO INT,
NAME VARCHAR2(25),
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
CHECK(ROLL_NUM > 0),
CHECK (NAME LIKE ‘C%’)
);
EX:
• ALTER TABLE CS2 ADD PRIMARY KEY(ROLL_NUM)
•ALTER TABLE CS2 ADD FOREIGN KEY (BRANCH_CODE)
REFERENCES BRANCH(BRANCH_ID).
•ALTER TABLE CS2 DROP PRIMARY KEY
<Column Name> <Data type> (<Size>) DEFAULT <value>
EX:
CREATE TABLE LBS_CS2(
ROLL_NO INT,
NAME VARCHAR2(25) DEFAULT ‘STUDENT’,
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
CHECK(ROLL_NUM > 0),
CHECK (NAME LIKE ‘C%’)
);
LOGICAL OPERATORS
•AND
•OR
EX:
SELECT NAME,ROUND(MARK)
FROM CS2
WHERE NAME LIKE ‘C%’ AND MARK >50 OR MARK <10;
RANGE SEARCHING
•BETWEEN
EX:
SELECT NAME
FROM CS2
WHERE TO_CHAR(DOB,’MM’) BETWEEN 01 AND 04;
EX:
SELECT NAME
FROM CS2
WHERE TO_CHAR(DOB,’YY’) NOT BETWEEN 91 AND 94;
PATTERN MATCHING
•LIKE predicate
‘%’ : include zero length
‘_ ‘: match on a single character
IN or NOT IN predicate
EX:
SELECT FNAME,LNAME,ADDRESS
FROM CS2
WHERE FNAME IN (‘EBI’,’ANOOP’,’VIKAS’,’NAVIN’);
EX:
SELECT FNAME,LNAME,ADDRESS
FROM CS2
WHERE FNAME NOT IN (‘EBI’,’ANOOP’,’VIKAS’,’NAVIN’);
DATE MANIPULATION
AGGREGATE FUNCTION
FUNCTION USE
AVG() AVERAGE
MIN() MINIMUM
COUNT() COUNTING
COUNT(*) COUNTING
MAX() MAXIMUM
SUM() TOTAL
ABS() ABSOLUTE
POWER() POWER
ROUND() ROUNDED
SQRT() SQUARE ROOT
EXTRACT()
GREATEST()
LEAST()
EXTRACT({YEAR| MONTH|DAY|HOUR|MINUTE|SECOND|
TIMEZONE_HOUR|TIMEZONE_MINUTE|
TIMEZONE_REGION |TIMEZONE_ABBR}
FROM {DATE |INTERVAL VALUE}
)
EX:
SELECT EXTRACT (YEAR FROM DATE ’2013-09-10’)
YEAR,EXTRACT (MONTH FROM SYSDATE) MONTH
FROM DUAL;
GREATEST(expr1,expr2. . . .expr_n)
LEAST(expr1,expr2. . . .expr_n)
NO NAME ADDRE
SS
AGE MARK
1 RESHMA.S.R AAA 45 45
2 RESHMA.S.S BBB 35 30
3 REVATHI.B.R CCC 11 68
4 ROSYLIN DDD 75 75
5 RUBEENA EEE 70 62
6 S. APARNA FFF 56 48
SELECT <Column Name 1> <Column Name 2> . .<Column Name N>
AGGREGATE_FUNCTION (<EXPRESSION>)
FROM TABLE NAME
WHERE <Condition>
GROUP BY<ColumnName 1> <Column Name 2>.<ColumnNameN >
Subqueries can be used with the SELECT, INSERT,
UPDATE, and DELETE statements along with the
operators like =, <, >, >=, <=, IN, BETWEEN etc.
RULES:
• must be enclosed within
parentheses.
•can have only one column in the
SELECT clause, unless multiple
columns are in the main query for
the subquery to compare its
selected columns.
•An ORDER BY cannot be used in
a subquery, although the main
query can use an ORDER BY.
•The GROUP BY can be used to
perform the same function as the
ORDER BY in a subquery.
•Subqueries that return more than
one row can only be used with
multiple value operators, such as the
IN operator.
•The BETWEEN operator cannot be
used with a subquery; however, the
BETWEEN operator can be used within
the subquery.
Subqueries with the SELECT Statement
SQL> SELECT *
FROM CUSTOMERSWHERE ID IN (SELECT ID
FROM CUSTOMERS
WHERE SALARY > 4500) ;
Subqueries with the INSERT Statement:
Subqueries with the UPDATE Statement:
output
Subqueries with the DELETE Statement:
Just one more
data constraints,group by

Contenu connexe

Tendances (19)

Les11
Les11Les11
Les11
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
Les11 Including Constraints
Les11 Including ConstraintsLes11 Including Constraints
Les11 Including Constraints
 
Les12
Les12Les12
Les12
 
Les10
Les10Les10
Les10
 
Sql
SqlSql
Sql
 
Les09
Les09Les09
Les09
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
Les13
Les13Les13
Les13
 
Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
Sql
SqlSql
Sql
 
Sql commands
Sql commandsSql commands
Sql commands
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
 
Oracle
OracleOracle
Oracle
 
Oracle Training in Kochi | Trivandrum |Thrissur
Oracle Training in Kochi | Trivandrum |ThrissurOracle Training in Kochi | Trivandrum |Thrissur
Oracle Training in Kochi | Trivandrum |Thrissur
 
Linguagem sql
Linguagem sqlLinguagem sql
Linguagem sql
 

En vedette

En vedette (9)

Tabakoa (jon alaine)
Tabakoa (jon alaine)Tabakoa (jon alaine)
Tabakoa (jon alaine)
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms users
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancy
 
Data
DataData
Data
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms users
 
Lect5 v2
Lect5 v2Lect5 v2
Lect5 v2
 
Litteraturformidling
LitteraturformidlingLitteraturformidling
Litteraturformidling
 
Transaction Management
Transaction Management Transaction Management
Transaction Management
 
Slide 2 data models
Slide 2 data modelsSlide 2 data models
Slide 2 data models
 

Similaire à data constraints,group by

Similaire à data constraints,group by (20)

MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
SQLQueries
SQLQueriesSQLQueries
SQLQueries
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
SESI 2 DATA DEFINITION LANGUAGE.pdf
SESI 2 DATA DEFINITION LANGUAGE.pdfSESI 2 DATA DEFINITION LANGUAGE.pdf
SESI 2 DATA DEFINITION LANGUAGE.pdf
 
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
Les01
Les01Les01
Les01
 
Sql ejercicio 1
Sql ejercicio 1Sql ejercicio 1
Sql ejercicio 1
 
Les09
Les09Les09
Les09
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
Sql
SqlSql
Sql
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Best sql plsql_material for B.TECH
Best sql plsql_material for B.TECH Best sql plsql_material for B.TECH
Best sql plsql_material for B.TECH
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
 
Introduction sql
Introduction sqlIntroduction sql
Introduction sql
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Les01
Les01Les01
Les01
 
SQL OUR NEEDS
SQL OUR NEEDSSQL OUR NEEDS
SQL OUR NEEDS
 

Plus de Visakh V

Functional dependency and normalization
Functional dependency and normalizationFunctional dependency and normalization
Functional dependency and normalizationVisakh V
 
Data base recovery
Data base recoveryData base recovery
Data base recoveryVisakh V
 
Relational algebra complete
Relational algebra completeRelational algebra complete
Relational algebra completeVisakh V
 
Memory Management
Memory ManagementMemory Management
Memory ManagementVisakh V
 
Slide 5 keys
Slide 5 keysSlide 5 keys
Slide 5 keysVisakh V
 
Slide 6 er strong & weak entity
Slide 6 er  strong & weak entitySlide 6 er  strong & weak entity
Slide 6 er strong & weak entityVisakh V
 
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaSlide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaVisakh V
 
Slide 1 introduction to dbms
Slide 1 introduction to dbmsSlide 1 introduction to dbms
Slide 1 introduction to dbmsVisakh V
 
Relational algebr
Relational algebrRelational algebr
Relational algebrVisakh V
 

Plus de Visakh V (9)

Functional dependency and normalization
Functional dependency and normalizationFunctional dependency and normalization
Functional dependency and normalization
 
Data base recovery
Data base recoveryData base recovery
Data base recovery
 
Relational algebra complete
Relational algebra completeRelational algebra complete
Relational algebra complete
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Slide 5 keys
Slide 5 keysSlide 5 keys
Slide 5 keys
 
Slide 6 er strong & weak entity
Slide 6 er  strong & weak entitySlide 6 er  strong & weak entity
Slide 6 er strong & weak entity
 
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaSlide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schema
 
Slide 1 introduction to dbms
Slide 1 introduction to dbmsSlide 1 introduction to dbms
Slide 1 introduction to dbms
 
Relational algebr
Relational algebrRelational algebr
Relational algebr
 

Dernier

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Dernier (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

data constraints,group by

  • 1.
  • 2.
  • 3.
  • 4.
  • 5. DBMS Owned By MySQL, Open Source RDMS MS Access Microsoft Oracle Oracle Corporation(ORDMS) Sybase SAP Company SQL Server Microsoft (RDMS) Postgresql Open Source RDMS Informix IBM(RDMS)
  • 7.
  • 8.
  • 9. Defined at Column Level Defined at Table Level
  • 10. UNIQUE NOT NULL NOT COMPULSORY CANNOT LONG/LONG RAW DATA TYPE ONLY ONE PER TABLE COMBINE UPTO 16 COLOUMNS IN A COMPOSITE PRIMARY KEY
  • 11.
  • 12. <Column Name> <Data type> (<Size>) PRIMARY KEY EX: CREATE TABLE LBS_CS2( NAME VARCHAR2(25) PRIMARY KEY - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - );
  • 13. PRIMARY KEY (<Column Name> , <Column Name> ) EX: CREATE TABLE LBS_CS2( NO INT, NAME VARCHAR2(25), - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PRIMARY KEY(NO,NAME) );
  • 14. Parent must be UNIQUE OR PRIMARY KEY Child may have DUPLICATE/NULL  Constraint specify on child not in parent Parent can delete only if child not exist Parent cannot modify if child exist
  • 15.
  • 16. <Column Name> <Data type> (<Size>) REFERENCES <TABLE NAME>[(<Column Name>)] [ON DELETE CASCADE]
  • 17. EX: CREATE TABLE LBS_CS2( ROLL_NO INT, NAME VARCHAR2(25), BRANCH_CODE VARCHAR2(25) REFERENCES BRANCH, - - - - - - - - - - - - - - - - - - PRIMARY KEY(NO,NAME) );
  • 18. EX: CREATE TABLE LBS_CS2( ROLL_NO INT, NAME VARCHAR2(25), BRANCH_CODE VARCHAR2(25) REFERENCES BRANCH (BRANCH_ID), - - - - - - - - - - - - - - - - - - PRIMARY KEY(NO,NAME) );
  • 19. FOREIGN KEY(<Column Name>[ <Column Name>] ) REFERENCES <TABLE NAME> [(<Column Name> <Column Name>] )] [ON DELETE SET NULL]
  • 20. EX: CREATE TABLE LBS_CS2( ROLL_NO INT, NAME VARCHAR2(25), FOREIGN KEY (BRANCH_CODE) REFERENCES BRANCH(BRANCH_ID), - - - - - - - - - - - - - - - - - - PRIMARY KEY(NO,NAME) );
  • 21.
  • 22. <Column Name> <Data type> (<Size>) UNIQUE EX: CREATE TABLE LBS_CS2( ROLL_NUM INT UNIQUE, - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - );
  • 23. UNIQUE (<Column Name> , <Column Name> ) EX: CREATE TABLE LBS_CS2( NO INT, NAME VARCHAR2(25), - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - UNIQUE(NO,NAME) );
  • 24.
  • 25.
  • 26. <Column Name> <Data type> (<Size>) NOT NULL EX: CREATE TABLE LBS_CS2( ROLL_NUM INT NOT NULL, - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - );
  • 27.
  • 28. <Column Name> <Data type> (<Size>) CHECK (<Logical Expression>) EX: CREATE TABLE LBS_CS2( ROLL_NUM INT CHECK (ROLL_NUM > 0) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - );
  • 29. CHECK(<Logical Expression>) EX: CREATE TABLE LBS_CS2( ROLL_NO INT, NAME VARCHAR2(25), - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CHECK(ROLL_NUM > 0), CHECK (NAME LIKE ‘C%’) );
  • 30.
  • 31.
  • 32. EX: • ALTER TABLE CS2 ADD PRIMARY KEY(ROLL_NUM) •ALTER TABLE CS2 ADD FOREIGN KEY (BRANCH_CODE) REFERENCES BRANCH(BRANCH_ID). •ALTER TABLE CS2 DROP PRIMARY KEY
  • 33. <Column Name> <Data type> (<Size>) DEFAULT <value> EX: CREATE TABLE LBS_CS2( ROLL_NO INT, NAME VARCHAR2(25) DEFAULT ‘STUDENT’, - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CHECK(ROLL_NUM > 0), CHECK (NAME LIKE ‘C%’) );
  • 34.
  • 35.
  • 37. EX: SELECT NAME,ROUND(MARK) FROM CS2 WHERE NAME LIKE ‘C%’ AND MARK >50 OR MARK <10;
  • 38. RANGE SEARCHING •BETWEEN EX: SELECT NAME FROM CS2 WHERE TO_CHAR(DOB,’MM’) BETWEEN 01 AND 04; EX: SELECT NAME FROM CS2 WHERE TO_CHAR(DOB,’YY’) NOT BETWEEN 91 AND 94;
  • 39. PATTERN MATCHING •LIKE predicate ‘%’ : include zero length ‘_ ‘: match on a single character
  • 40.
  • 41.
  • 42.
  • 43. IN or NOT IN predicate EX: SELECT FNAME,LNAME,ADDRESS FROM CS2 WHERE FNAME IN (‘EBI’,’ANOOP’,’VIKAS’,’NAVIN’); EX: SELECT FNAME,LNAME,ADDRESS FROM CS2 WHERE FNAME NOT IN (‘EBI’,’ANOOP’,’VIKAS’,’NAVIN’);
  • 45.
  • 46.
  • 48. FUNCTION USE AVG() AVERAGE MIN() MINIMUM COUNT() COUNTING COUNT(*) COUNTING MAX() MAXIMUM SUM() TOTAL ABS() ABSOLUTE POWER() POWER ROUND() ROUNDED SQRT() SQUARE ROOT EXTRACT() GREATEST() LEAST()
  • 50. EX: SELECT EXTRACT (YEAR FROM DATE ’2013-09-10’) YEAR,EXTRACT (MONTH FROM SYSDATE) MONTH FROM DUAL;
  • 51. GREATEST(expr1,expr2. . . .expr_n) LEAST(expr1,expr2. . . .expr_n)
  • 52. NO NAME ADDRE SS AGE MARK 1 RESHMA.S.R AAA 45 45 2 RESHMA.S.S BBB 35 30 3 REVATHI.B.R CCC 11 68 4 ROSYLIN DDD 75 75 5 RUBEENA EEE 70 62 6 S. APARNA FFF 56 48
  • 53.
  • 54.
  • 55. SELECT <Column Name 1> <Column Name 2> . .<Column Name N> AGGREGATE_FUNCTION (<EXPRESSION>) FROM TABLE NAME WHERE <Condition> GROUP BY<ColumnName 1> <Column Name 2>.<ColumnNameN >
  • 56.
  • 57.
  • 58.
  • 59.
  • 60. Subqueries can be used with the SELECT, INSERT, UPDATE, and DELETE statements along with the operators like =, <, >, >=, <=, IN, BETWEEN etc.
  • 61. RULES: • must be enclosed within parentheses. •can have only one column in the SELECT clause, unless multiple columns are in the main query for the subquery to compare its selected columns. •An ORDER BY cannot be used in a subquery, although the main query can use an ORDER BY.
  • 62. •The GROUP BY can be used to perform the same function as the ORDER BY in a subquery. •Subqueries that return more than one row can only be used with multiple value operators, such as the IN operator. •The BETWEEN operator cannot be used with a subquery; however, the BETWEEN operator can be used within the subquery.
  • 63. Subqueries with the SELECT Statement
  • 64. SQL> SELECT * FROM CUSTOMERSWHERE ID IN (SELECT ID FROM CUSTOMERS WHERE SALARY > 4500) ;
  • 65. Subqueries with the INSERT Statement:
  • 66. Subqueries with the UPDATE Statement:
  • 68. Subqueries with the DELETE Statement:
  • 69.