SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Linguagem sql
Linguagem sqlLinguagem sql
Linguagem sql
Tic Eslc
 

La actualidad más candente (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
 

Destacado (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
 

Similar a data constraints,group by

MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
webhostingguy
 
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
AmIt Prasad
 
Introduction sql
Introduction sqlIntroduction sql
Introduction sql
sagarasuri
 

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

Más 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
 

Último

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

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.