Your SlideShare is downloading. ×
data constraints,group by
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

data constraints,group by

253

Published on

contains topics about …

contains topics about
data constraints
group by
aggregate function
subqueries

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
253
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 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)
  • 2. Primary Key Foreign Key Unique Check NOT NULL/NULL
  • 3. Defined at Column Level Defined at Table Level
  • 4. UNIQUE NOT NULL NOT COMPULSORY CANNOT LONG/LONG RAW DATA TYPE ONLY ONE PER TABLE COMBINE UPTO 16 COLOUMNS IN A COMPOSITE PRIMARY KEY
  • 5. <Column Name> <Data type> (<Size>) PRIMARY KEY EX: CREATE TABLE LBS_CS2( NAME VARCHAR2(25) PRIMARY KEY - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - );
  • 6. PRIMARY KEY (<Column Name> , <Column Name> ) EX: CREATE TABLE LBS_CS2( NO INT, NAME VARCHAR2(25), - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PRIMARY KEY(NO,NAME) );
  • 7. 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
  • 8. <Column Name> <Data type> (<Size>) REFERENCES <TABLE NAME>[(<Column Name>)] [ON DELETE CASCADE]
  • 9. EX: CREATE TABLE LBS_CS2( ROLL_NO INT, NAME VARCHAR2(25), BRANCH_CODE VARCHAR2(25) REFERENCES BRANCH, - - - - - - - - - - - - - - - - - - PRIMARY KEY(NO,NAME) );
  • 10. EX: CREATE TABLE LBS_CS2( ROLL_NO INT, NAME VARCHAR2(25), BRANCH_CODE VARCHAR2(25) REFERENCES BRANCH (BRANCH_ID), - - - - - - - - - - - - - - - - - - PRIMARY KEY(NO,NAME) );
  • 11. FOREIGN KEY(<Column Name>[ <Column Name>] ) REFERENCES <TABLE NAME> [(<Column Name> <Column Name>] )] [ON DELETE SET NULL]
  • 12. EX: CREATE TABLE LBS_CS2( ROLL_NO INT, NAME VARCHAR2(25), FOREIGN KEY (BRANCH_CODE) REFERENCES BRANCH(BRANCH_ID), - - - - - - - - - - - - - - - - - - PRIMARY KEY(NO,NAME) );
  • 13. <Column Name> <Data type> (<Size>) UNIQUE EX: CREATE TABLE LBS_CS2( ROLL_NUM INT UNIQUE, - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - );
  • 14. UNIQUE (<Column Name> , <Column Name> ) EX: CREATE TABLE LBS_CS2( NO INT, NAME VARCHAR2(25), - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - UNIQUE(NO,NAME) );
  • 15. <Column Name> <Data type> (<Size>) NOT NULL EX: CREATE TABLE LBS_CS2( ROLL_NUM INT NOT NULL, - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - );
  • 16. <Column Name> <Data type> (<Size>) CHECK (<Logical Expression>) EX: CREATE TABLE LBS_CS2( ROLL_NUM INT CHECK (ROLL_NUM > 0) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - );
  • 17. CHECK(<Logical Expression>) EX: CREATE TABLE LBS_CS2( ROLL_NO INT, NAME VARCHAR2(25), - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CHECK(ROLL_NUM > 0), CHECK (NAME LIKE ‘C%’) );
  • 18. 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
  • 19. <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%’) );
  • 20. LOGICAL OPERATORS •AND •OR
  • 21. EX: SELECT NAME,ROUND(MARK) FROM CS2 WHERE NAME LIKE ‘C%’ AND MARK >50 OR MARK <10;
  • 22. 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;
  • 23. PATTERN MATCHING •LIKE predicate ‘%’ : include zero length ‘_ ‘: match on a single character
  • 24. 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’);
  • 25. DATE MANIPULATION
  • 26. AGGREGATE FUNCTION
  • 27. 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()
  • 28. EXTRACT({YEAR| MONTH|DAY|HOUR|MINUTE|SECOND| TIMEZONE_HOUR|TIMEZONE_MINUTE| TIMEZONE_REGION |TIMEZONE_ABBR} FROM {DATE |INTERVAL VALUE} )
  • 29. EX: SELECT EXTRACT (YEAR FROM DATE ’2013-09-10’) YEAR,EXTRACT (MONTH FROM SYSDATE) MONTH FROM DUAL;
  • 30. GREATEST(expr1,expr2. . . .expr_n) LEAST(expr1,expr2. . . .expr_n)
  • 31. 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
  • 32. 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 >
  • 33. Subqueries can be used with the SELECT, INSERT, UPDATE, and DELETE statements along with the operators like =, <, >, >=, <=, IN, BETWEEN etc.
  • 34. 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.
  • 35. •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.
  • 36. Subqueries with the SELECT Statement
  • 37. SQL> SELECT * FROM CUSTOMERSWHERE ID IN (SELECT ID FROM CUSTOMERS WHERE SALARY > 4500) ;
  • 38. Subqueries with the INSERT Statement:
  • 39. Subqueries with the UPDATE Statement:
  • 40. output
  • 41. Subqueries with the DELETE Statement:
  • 42. Just one more

×