• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
data constraints,group by
 

data constraints,group by

on

  • 372 views

contains topics about

contains topics about
data constraints
group by
aggregate function
subqueries

Statistics

Views

Total Views
372
Views on SlideShare
372
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    data constraints,group by data constraints,group by Presentation Transcript

    • 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