SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
Data Definition Language
       24 November 2011
Bonus Time!
 Tampilkan gaji minimum, gaji maksimum, jumlah
 gaji, dan rata-rata gaji untuk     MIN(SALAR MAX(SALA   SUM(SALA   AVG(SALAR
                                    Y)        RY)        RY)        Y)

 setiap jenis pekerjaan.            4200
                                    12008
                                             9000
                                             12008
                                                         28800
                                                         12008
                                                                    5760
                                                                    12008
  SELECT MIN(salary), MAX(salary), SUM(salary),
                                    8300     8300        8300       8300
                                    5800     8200        36400      7280
    AVG(salary)                     11000    11000       11000      11000
  FROM employees                    4400     4400        4400       4400
                                    17000    17000       34000      17000
  GROUP BY job_id;                  2500     4200        64300      3215
                                    6900     9000        39600      7920
 19 rows retrieved                 12008    12008       12008      12008
                                    2500     3100        13900      2780

 only 1 if GROUP BY clause         10500
                                    13000
                                             14000
                                             13000
                                                         61000
                                                         13000
                                                                    12200
                                                                    13000
                                    10000    10000       10000      10000
 ommitted                           24000
                                    6100
                                             24000
                                             11500
                                                         24000
                                                         250500
                                                                    24000
                                                                    8350
                                    6000     6000        6000       6000
                                    2100     3600        55700      2785
                                    6500     6500        6500       6500
Bonus Time!
 Tampilkan jumlah orang yang memiliki jenis
 pekerjaan yang sama.
                                    COUNT(JOB_ID)   JOB_ID
  SELECT COUNT(job_id),             1               AC_ACCOUNT
                                    1               AC_MGR
    job_id                          1               AD_ASST

  FROM employees                    1
                                    2
                                                    AD_PRES
                                                    AD_VP
  GROUP BY job_id;                  5               FI_ACCOUNT
                                    1               FI_MGR

 19 rows retrieved, sesuai jenis   1
                                    5
                                                    HR_REP
                                                    IT_PROG
                                    1               MK_MAN
 pekerjaan yang ada dalam           1
                                    1
                                                    MK_REP
                                                    PR_REP

 tabel Employees                    5
                                    1
                                                    PU_CLERK
                                                    PU_MAN
                                    5               SA_MAN
 (field JOB_ID)                     30
                                    20
                                                    SA_REP
                                                    SH_CLERK
                                    20              ST_CLERK
              Kalkulus Relasional                                3
                                    5               ST_MAN
Bonus Time!
 Buat kueri yang menampilkan selisih antara gaji
 maksimum dengan gaji minimum. Beri label
 “Perbedaan Gaji”.
  SELECT MAX(salary) - MIN(salary) AS "Perbedaan
    gaji"
  FROM employees;

      Perbedaan gaji
      21900




               Kalkulus Relasional                  4
Tabel Movie
mID   Title                              Year   Director
101   Gone with the Wind                 1939   Victor Fleming
102   Star Wars                          1977   George Lucas
103   The Sound of Music                 1965   Robert Wise
104   E.T.                               1982   Steven Spielberg
105   Titanic                            1997   James Cameron
106   Show White                         1937
107   Avatar                             2009   James Cameron
108   Raiders of the Lost Ark            1982   Steven Spielberg




                   Kalkulus Relasional                             5
Tabel Reviewer
rID   Name
201   Sarah Martinez
202   Daniel Lewis
203   Brittany Harris
204   Mike Anderson
205   Chris Jackson
206   Elizabeth Thomas
207   James Cameron
208   Ashley White




                      Kalkulus Relasional   6
rID   mID Stars RatingDate
                        201   101   2   2011-01-22
Tabel Rating            201   101   4   2011-01-27
                        202   106   4
                        203   103   2   2011-01-20
                        203   108   4   2011-01-12
                        201   108   2   2011-01-30
                        204   101   3   2011-01-09
                        205   103   3   2011-01-27
                        205   104   2   2011-01-22
                        205   108   4
                        206   107   3   2011-01-15
                        206   106   5   2011-01-19
                        207   107   5   2011-01-20
                        208   104   3   2011-01-02

        Kalkulus Relasional                          7
Where do They Come From?
 Kenapa terbagi ke dalam tiga tabel?
 Kenapa masing-masing tabel memiliki jumlah kolom
  tertentu?
 Kenapa urutan kolomnya seperti itu?




              Kalkulus Relasional                    8
Data Integrity dan Consistency
 Bagaimana jika ada judul film yang berubah?
 Bagaimana jika ada data reviewer yang dihapus?
 Bagaimana jika ada reviewer yang iseng mereview film
  yang tidak pernah ada?




              Kalkulus Relasional                        9
Data Definition, Constraints,
and Schema Changes
  Used to CREATE, DROP, and ALTER the descriptions
   of the tables (relations) of a database
  Constraint-ku ada lima,
   macam-macam jenisnya
     PRIMARY KEY
     FOREIGN KEY
     UNIQUE
     NOT NULL
     CHECK


Slide 8-10
Tipe Data
 CHAR(n)
 VARCHAR(n)
    Oracle: VARCHAR2(n)
 INTEGER
    SQLite: INT
    NUMBER(n[,d])
    NUM(n[,d])
 DECIMAL


              Kalkulus Relasional   11
Tipe Data
 DATE
    TIME
    TIMESTAMP
 ISO Format
    'YYYY/MM/DD'
    Easily sortable
       20/10/1984, 28/06/1980, 29/02/1980, 30/11/1982
        1980/02/29, 1980/06/28, 1982/11/30, 1984/10/20
 No ambiguity
   12/11/1980: Dec or Nov?
               Kalkulus Relasional                   12
CHAR vs VARCHAR
 Fixed length
    Lebih cepat diakses
    Boros space
 Variable length
    Lebih hemat ruang
    Lebih lambat diakses (diatasi dengan INDEX)




               Kalkulus Relasional                 13
CREATE TABLE
  Specifies a new base relation by giving it a name,
   and specifying each of its attributes and their data
   types (INTEGER, FLOAT, DECIMAL(i,j),
   CHAR(n), VARCHAR(n))
  A constraint NOT NULL may be specified on an
   attribute
     CREATE TABLE DEPARTMENT
         (     DNAME      VARCHAR(10) NOT NULL,
               DNUMBER    INTEGER     NOT NULL,
               MGRSSN     CHAR(9),
               MGRSTARTDATE     CHAR(9) );

Slide 8-14
CREATE TABLE
  In SQL2, can use the CREATE TABLE command for
   specifying the primary key attributes, secondary keys, and
   referential integrity constraints (foreign keys).
  Key attributes can be specified via the PRIMARY KEY and
   UNIQUE phrases

       CREATE TABLE DEPT
       ( DNAME VARCHAR(10) NOT NULL,
          DNUMBER      INTEGER     NOT NULL,
          MGRSSN       CHAR(9),
          MGRSTARTDATE       CHAR(9),
          PRIMARY KEY (DNUMBER),
          UNIQUE (DNAME),
          FOREIGN KEY (MGRSSN) REFERENCES EMP );
Slide 8-15
Bonus Time: Tabel Movie
mID   Title                              Year   Director
101   Gone with the Wind                 1939   Victor Fleming
102   Star Wars                          1977   George Lucas
103   The Sound of Music                 1965   Robert Wise
104   E.T.                               1982   Steven Spielberg
105   Titanic                            1997   James Cameron
106   Show White                         1937
107   Avatar                             2009   James Cameron
108   Raiders of the Lost Ark            1982   Steven Spielberg




                   Kalkulus Relasional                             16
Bonus Time: CREATE TABLE
Movie
CREATE TABLE Movie (
   mID INT,
   title VARCHAR(20),
   year NUMBER(4),
   director VARCHAR(20)
);




              Kalkulus Relasional   17
Tabel Reviewer
rID   Name
201   Sarah Martinez
202   Daniel Lewis
203   Brittany Harris
204   Mike Anderson
205   Chris Jackson
206   Elizabeth Thomas
207   James Cameron
208   Ashley White




                      Kalkulus Relasional   18
rID   mID Stars RatingDate
                        201   101   2   2011-01-22
Tabel Rating            201   101   4   2011-01-27
                        202   106   4
                        203   103   2   2011-01-20
                        203   108   4   2011-01-12
                        201   108   2   2011-01-30
                        204   101   3   2011-01-09
                        205   103   3   2011-01-27
                        205   104   2   2011-01-22
                        205   108   4
                        206   107   3   2011-01-15
                        206   106   5   2011-01-19
                        207   107   5   2011-01-20
                        208   104   3   2011-01-02

        Kalkulus Relasional                          19
DROP TABLE
  Used to remove a relation (base table) and its
   definition
  The relation can no longer be used in queries, updates,
   or any other commands since its description no longer
   exists
  Example:

     DROP TABLE DEPENDENT;



Slide 8-20
ALTER TABLE
  Used to add an attribute to one of the base relations
  The new attribute will have NULLs in all the tuples of the
   relation right after the command is executed; hence, the
   NOT NULL constraint is not allowed for such an attribute
  Example:

     ALTER TABLE EMPLOYEE ADD JOB VARCHAR(12);

  The database users must still enter a value for the new
     attribute JOB for each EMPLOYEE tuple. This can be done
     using the UPDATE command.
Slide 8-21
REFERENTIAL INTEGRITY
OPTIONS
  We can specify RESTRICT, CASCADE, SET NULL or SET
     DEFAULT on referential integrity constraints (foreign keys)

     CREATE TABLE DEPT
     ( DNAME       VARCHAR(10)    NOT NULL,
        DNUMBER INTEGER      NOT NULL,
        MGRSSN     CHAR(9),
        MGRSTARTDATE CHAR(9),
        PRIMARY KEY (DNUMBER),
        UNIQUE (DNAME),
        FOREIGN KEY (MGRSSN) REFERENCES EMP
     ON DELETE SET DEFAULT ON UPDATE CASCADE );

Slide 8-22
REFERENTIAL INTEGRITY
OPTIONS (continued)
             CREATE TABLE EMP
                (      ENAME VARCHAR(30) NOT NULL,
                       ESSN CHAR(9),
                       BDATE DATE,
                       DNO INTEGER DEFAULT 1,
                       SUPERSSN     CHAR(9),
                       PRIMARY KEY (ESSN),
                       FOREIGN KEY (DNO) REFERENCES DEPT
                  ON DELETE SET DEFAULT ON UPDATE CASCADE,
                       FOREIGN KEY (SUPERSSN) REFERENCES EMP
                  ON DELETE SET NULL ON UPDATE CASCADE );




Slide 8-23
Additional Data Types in SQL2
and SQL-99
 Has DATE, TIME, and TIMESTAMP data types
  DATE:
        Made up of year-month-day in the format yyyy-mm-dd
  TIME:
        Made up of hour:minute:second in the format hh:mm:ss
  TIME(i):
        Made up of hour:minute:second plus i additional digits
         specifying fractions of a second
        format is hh:mm:ss:ii...i
  TIMESTAMP:
        Has both DATE and TIME components
Slide 8-24
Additional Data Types in SQL2
and SQL-99 (cont.)
     INTERVAL:
              Specifies a relative value rather than an absolute
               value
              Can be DAY/TIME intervals or YEAR/MONTH
               intervals
              Can be positive or negative when added to or
               subtracted from an absolute value, the result is an
               absolute value




Slide 8-25
Pustaka
 Elmasri dan Navathe, "Foundation of Database System"
 http://tjerdastangkas.blogspot.com/search/label/ikd312




               Kalkulus Relasional                         26
Kamis, 24 November 2011

Weitere ähnliche Inhalte

Andere mochten auch

Career Avenues in HR field
Career Avenues in HR fieldCareer Avenues in HR field
Career Avenues in HR fieldRajendra Sabnis
 
Improve Executive Speeches with 10 Fast Tips
Improve Executive Speeches with 10 Fast TipsImprove Executive Speeches with 10 Fast Tips
Improve Executive Speeches with 10 Fast TipsMarian Madonia, CSP
 
Comox.april.2013.writing#3
Comox.april.2013.writing#3Comox.april.2013.writing#3
Comox.april.2013.writing#3Faye Brownlie
 
April.Prince Rupert.middle
April.Prince Rupert.middleApril.Prince Rupert.middle
April.Prince Rupert.middleFaye Brownlie
 
Carteles art nouveau redux
Carteles art nouveau reduxCarteles art nouveau redux
Carteles art nouveau reduxalmudenaresad
 
Color naming 65,274,705,768 pixels
Color naming 65,274,705,768 pixels Color naming 65,274,705,768 pixels
Color naming 65,274,705,768 pixels nmoroney
 
isd314-06-association-mining
isd314-06-association-miningisd314-06-association-mining
isd314-06-association-miningAnung Ariwibowo
 
Cценарий лучшей презентации стартапа
Cценарий лучшей презентации стартапаCценарий лучшей презентации стартапа
Cценарий лучшей презентации стартапаGregory Sitnin
 
Embedding Research in Society: Supporting Agricultural Innovation in a Global...
Embedding Research in Society: Supporting Agricultural Innovation in a Global...Embedding Research in Society: Supporting Agricultural Innovation in a Global...
Embedding Research in Society: Supporting Agricultural Innovation in a Global...LINKInnovationStudies
 
OpenSplice DDS: The Open Source Middleware Accelerating Wall Street
OpenSplice DDS: The Open Source Middleware Accelerating Wall StreetOpenSplice DDS: The Open Source Middleware Accelerating Wall Street
OpenSplice DDS: The Open Source Middleware Accelerating Wall StreetAngelo Corsaro
 
Visita granada 3er ciclo 2016
Visita granada 3er ciclo 2016Visita granada 3er ciclo 2016
Visita granada 3er ciclo 2016XXX XXX
 
Ifmasv Roundtable Sj City College09 May12
Ifmasv Roundtable   Sj City College09 May12Ifmasv Roundtable   Sj City College09 May12
Ifmasv Roundtable Sj City College09 May12AndyFuhrman
 
White Paper: The Value Of Bim For Lifecycle Management In Critical Facilities...
White Paper: The Value Of Bim For Lifecycle Management In Critical Facilities...White Paper: The Value Of Bim For Lifecycle Management In Critical Facilities...
White Paper: The Value Of Bim For Lifecycle Management In Critical Facilities...AndyFuhrman
 
Reviving keynes animal spirits for your business
Reviving keynes animal spirits for your businessReviving keynes animal spirits for your business
Reviving keynes animal spirits for your businessJAYARAMAN IYER
 
Raspberry PiとActiveMQで作るセンサーライト
Raspberry PiとActiveMQで作るセンサーライトRaspberry PiとActiveMQで作るセンサーライト
Raspberry PiとActiveMQで作るセンサーライトTakayuki Konishi
 
Stream Processing with DDS and CEP
Stream Processing with  DDS and CEPStream Processing with  DDS and CEP
Stream Processing with DDS and CEPAngelo Corsaro
 
Errenazimenduko pintura. Leonardo.ppt
Errenazimenduko pintura. Leonardo.pptErrenazimenduko pintura. Leonardo.ppt
Errenazimenduko pintura. Leonardo.pptasunasenjo
 

Andere mochten auch (20)

ikh323-06
ikh323-06ikh323-06
ikh323-06
 
Career Avenues in HR field
Career Avenues in HR fieldCareer Avenues in HR field
Career Avenues in HR field
 
Improve Executive Speeches with 10 Fast Tips
Improve Executive Speeches with 10 Fast TipsImprove Executive Speeches with 10 Fast Tips
Improve Executive Speeches with 10 Fast Tips
 
Comox.april.2013.writing#3
Comox.april.2013.writing#3Comox.april.2013.writing#3
Comox.april.2013.writing#3
 
April.Prince Rupert.middle
April.Prince Rupert.middleApril.Prince Rupert.middle
April.Prince Rupert.middle
 
Carteles art nouveau redux
Carteles art nouveau reduxCarteles art nouveau redux
Carteles art nouveau redux
 
ikp321-02
ikp321-02ikp321-02
ikp321-02
 
Color naming 65,274,705,768 pixels
Color naming 65,274,705,768 pixels Color naming 65,274,705,768 pixels
Color naming 65,274,705,768 pixels
 
isd314-06-association-mining
isd314-06-association-miningisd314-06-association-mining
isd314-06-association-mining
 
Cценарий лучшей презентации стартапа
Cценарий лучшей презентации стартапаCценарий лучшей презентации стартапа
Cценарий лучшей презентации стартапа
 
Embedding Research in Society: Supporting Agricultural Innovation in a Global...
Embedding Research in Society: Supporting Agricultural Innovation in a Global...Embedding Research in Society: Supporting Agricultural Innovation in a Global...
Embedding Research in Society: Supporting Agricultural Innovation in a Global...
 
OpenSplice DDS: The Open Source Middleware Accelerating Wall Street
OpenSplice DDS: The Open Source Middleware Accelerating Wall StreetOpenSplice DDS: The Open Source Middleware Accelerating Wall Street
OpenSplice DDS: The Open Source Middleware Accelerating Wall Street
 
Visita granada 3er ciclo 2016
Visita granada 3er ciclo 2016Visita granada 3er ciclo 2016
Visita granada 3er ciclo 2016
 
Ifmasv Roundtable Sj City College09 May12
Ifmasv Roundtable   Sj City College09 May12Ifmasv Roundtable   Sj City College09 May12
Ifmasv Roundtable Sj City College09 May12
 
ikh323-02
ikh323-02ikh323-02
ikh323-02
 
White Paper: The Value Of Bim For Lifecycle Management In Critical Facilities...
White Paper: The Value Of Bim For Lifecycle Management In Critical Facilities...White Paper: The Value Of Bim For Lifecycle Management In Critical Facilities...
White Paper: The Value Of Bim For Lifecycle Management In Critical Facilities...
 
Reviving keynes animal spirits for your business
Reviving keynes animal spirits for your businessReviving keynes animal spirits for your business
Reviving keynes animal spirits for your business
 
Raspberry PiとActiveMQで作るセンサーライト
Raspberry PiとActiveMQで作るセンサーライトRaspberry PiとActiveMQで作るセンサーライト
Raspberry PiとActiveMQで作るセンサーライト
 
Stream Processing with DDS and CEP
Stream Processing with  DDS and CEPStream Processing with  DDS and CEP
Stream Processing with DDS and CEP
 
Errenazimenduko pintura. Leonardo.ppt
Errenazimenduko pintura. Leonardo.pptErrenazimenduko pintura. Leonardo.ppt
Errenazimenduko pintura. Leonardo.ppt
 

Ähnlich wie ikd312-07-ddl

Hcb presentation 15th jotc maputo fev2012
Hcb presentation 15th jotc maputo fev2012Hcb presentation 15th jotc maputo fev2012
Hcb presentation 15th jotc maputo fev2012josematola
 
Ppt compressed sensing a tutorial
Ppt compressed sensing a tutorialPpt compressed sensing a tutorial
Ppt compressed sensing a tutorialTerence Gao
 
2012 740 stober_ppt
2012 740 stober_ppt2012 740 stober_ppt
2012 740 stober_pptmarykdan
 
Cumberland-Atlantic-counties-data-demographics-uez
Cumberland-Atlantic-counties-data-demographics-uezCumberland-Atlantic-counties-data-demographics-uez
Cumberland-Atlantic-counties-data-demographics-uezfianacone
 
Union-county-data-demographics-uez
Union-county-data-demographics-uezUnion-county-data-demographics-uez
Union-county-data-demographics-uezfianacone
 
A Function by Any Other Name is a Function
A Function by Any Other Name is a FunctionA Function by Any Other Name is a Function
A Function by Any Other Name is a FunctionJason Strate
 
R graphics by Novi Reandy Sasmita
R graphics by Novi Reandy SasmitaR graphics by Novi Reandy Sasmita
R graphics by Novi Reandy Sasmitabeasiswa
 

Ähnlich wie ikd312-07-ddl (10)

Map info data dictionary version 1
Map info data dictionary version 1Map info data dictionary version 1
Map info data dictionary version 1
 
Cube rollup slides
Cube rollup slidesCube rollup slides
Cube rollup slides
 
Hcb presentation 15th jotc maputo fev2012
Hcb presentation 15th jotc maputo fev2012Hcb presentation 15th jotc maputo fev2012
Hcb presentation 15th jotc maputo fev2012
 
Ppt compressed sensing a tutorial
Ppt compressed sensing a tutorialPpt compressed sensing a tutorial
Ppt compressed sensing a tutorial
 
2012 740 stober_ppt
2012 740 stober_ppt2012 740 stober_ppt
2012 740 stober_ppt
 
Cumberland-Atlantic-counties-data-demographics-uez
Cumberland-Atlantic-counties-data-demographics-uezCumberland-Atlantic-counties-data-demographics-uez
Cumberland-Atlantic-counties-data-demographics-uez
 
Mathur
MathurMathur
Mathur
 
Union-county-data-demographics-uez
Union-county-data-demographics-uezUnion-county-data-demographics-uez
Union-county-data-demographics-uez
 
A Function by Any Other Name is a Function
A Function by Any Other Name is a FunctionA Function by Any Other Name is a Function
A Function by Any Other Name is a Function
 
R graphics by Novi Reandy Sasmita
R graphics by Novi Reandy SasmitaR graphics by Novi Reandy Sasmita
R graphics by Novi Reandy Sasmita
 

Mehr von Anung Ariwibowo (20)

ikp213-unifikasi
ikp213-unifikasiikp213-unifikasi
ikp213-unifikasi
 
ikp213-06-horn-clause
ikp213-06-horn-clauseikp213-06-horn-clause
ikp213-06-horn-clause
 
ikp213-01-pendahuluan
ikp213-01-pendahuluanikp213-01-pendahuluan
ikp213-01-pendahuluan
 
ikd312-05-sqlite
ikd312-05-sqliteikd312-05-sqlite
ikd312-05-sqlite
 
ikd312-05-kalkulus-relasional
ikd312-05-kalkulus-relasionalikd312-05-kalkulus-relasional
ikd312-05-kalkulus-relasional
 
ikd312-04-aljabar-relasional
ikd312-04-aljabar-relasionalikd312-04-aljabar-relasional
ikd312-04-aljabar-relasional
 
ikd312-03-design
ikd312-03-designikd312-03-design
ikd312-03-design
 
ikd312-02-three-schema
ikd312-02-three-schemaikd312-02-three-schema
ikd312-02-three-schema
 
ikp213-02-pendahuluan
ikp213-02-pendahuluanikp213-02-pendahuluan
ikp213-02-pendahuluan
 
ikh311-08
ikh311-08ikh311-08
ikh311-08
 
ikh311-07
ikh311-07ikh311-07
ikh311-07
 
ikh311-06
ikh311-06ikh311-06
ikh311-06
 
ikh311-05
ikh311-05ikh311-05
ikh311-05
 
ikp321-svn
ikp321-svnikp321-svn
ikp321-svn
 
ikh311-04
ikh311-04ikh311-04
ikh311-04
 
ikp321-05
ikp321-05ikp321-05
ikp321-05
 
imsakiyah-jakarta-1433-09
imsakiyah-jakarta-1433-09imsakiyah-jakarta-1433-09
imsakiyah-jakarta-1433-09
 
ikh311-03
ikh311-03ikh311-03
ikh311-03
 
ikp321-04
ikp321-04ikp321-04
ikp321-04
 
ikp321-03
ikp321-03ikp321-03
ikp321-03
 

Kürzlich hochgeladen

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Kürzlich hochgeladen (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

ikd312-07-ddl

  • 1. Data Definition Language 24 November 2011
  • 2. Bonus Time!  Tampilkan gaji minimum, gaji maksimum, jumlah gaji, dan rata-rata gaji untuk MIN(SALAR MAX(SALA SUM(SALA AVG(SALAR Y) RY) RY) Y) setiap jenis pekerjaan. 4200 12008 9000 12008 28800 12008 5760 12008 SELECT MIN(salary), MAX(salary), SUM(salary), 8300 8300 8300 8300 5800 8200 36400 7280 AVG(salary) 11000 11000 11000 11000 FROM employees 4400 4400 4400 4400 17000 17000 34000 17000 GROUP BY job_id; 2500 4200 64300 3215 6900 9000 39600 7920  19 rows retrieved 12008 12008 12008 12008 2500 3100 13900 2780  only 1 if GROUP BY clause 10500 13000 14000 13000 61000 13000 12200 13000 10000 10000 10000 10000 ommitted 24000 6100 24000 11500 24000 250500 24000 8350 6000 6000 6000 6000 2100 3600 55700 2785 6500 6500 6500 6500
  • 3. Bonus Time!  Tampilkan jumlah orang yang memiliki jenis pekerjaan yang sama. COUNT(JOB_ID) JOB_ID SELECT COUNT(job_id), 1 AC_ACCOUNT 1 AC_MGR job_id 1 AD_ASST FROM employees 1 2 AD_PRES AD_VP GROUP BY job_id; 5 FI_ACCOUNT 1 FI_MGR  19 rows retrieved, sesuai jenis 1 5 HR_REP IT_PROG 1 MK_MAN pekerjaan yang ada dalam 1 1 MK_REP PR_REP tabel Employees 5 1 PU_CLERK PU_MAN 5 SA_MAN (field JOB_ID) 30 20 SA_REP SH_CLERK 20 ST_CLERK Kalkulus Relasional 3 5 ST_MAN
  • 4. Bonus Time!  Buat kueri yang menampilkan selisih antara gaji maksimum dengan gaji minimum. Beri label “Perbedaan Gaji”. SELECT MAX(salary) - MIN(salary) AS "Perbedaan gaji" FROM employees; Perbedaan gaji 21900 Kalkulus Relasional 4
  • 5. Tabel Movie mID Title Year Director 101 Gone with the Wind 1939 Victor Fleming 102 Star Wars 1977 George Lucas 103 The Sound of Music 1965 Robert Wise 104 E.T. 1982 Steven Spielberg 105 Titanic 1997 James Cameron 106 Show White 1937 107 Avatar 2009 James Cameron 108 Raiders of the Lost Ark 1982 Steven Spielberg Kalkulus Relasional 5
  • 6. Tabel Reviewer rID Name 201 Sarah Martinez 202 Daniel Lewis 203 Brittany Harris 204 Mike Anderson 205 Chris Jackson 206 Elizabeth Thomas 207 James Cameron 208 Ashley White Kalkulus Relasional 6
  • 7. rID mID Stars RatingDate 201 101 2 2011-01-22 Tabel Rating 201 101 4 2011-01-27 202 106 4 203 103 2 2011-01-20 203 108 4 2011-01-12 201 108 2 2011-01-30 204 101 3 2011-01-09 205 103 3 2011-01-27 205 104 2 2011-01-22 205 108 4 206 107 3 2011-01-15 206 106 5 2011-01-19 207 107 5 2011-01-20 208 104 3 2011-01-02 Kalkulus Relasional 7
  • 8. Where do They Come From?  Kenapa terbagi ke dalam tiga tabel?  Kenapa masing-masing tabel memiliki jumlah kolom tertentu?  Kenapa urutan kolomnya seperti itu? Kalkulus Relasional 8
  • 9. Data Integrity dan Consistency  Bagaimana jika ada judul film yang berubah?  Bagaimana jika ada data reviewer yang dihapus?  Bagaimana jika ada reviewer yang iseng mereview film yang tidak pernah ada? Kalkulus Relasional 9
  • 10. Data Definition, Constraints, and Schema Changes  Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database  Constraint-ku ada lima, macam-macam jenisnya  PRIMARY KEY  FOREIGN KEY  UNIQUE  NOT NULL  CHECK Slide 8-10
  • 11. Tipe Data  CHAR(n)  VARCHAR(n)  Oracle: VARCHAR2(n)  INTEGER  SQLite: INT  NUMBER(n[,d])  NUM(n[,d])  DECIMAL Kalkulus Relasional 11
  • 12. Tipe Data  DATE  TIME  TIMESTAMP  ISO Format  'YYYY/MM/DD'  Easily sortable  20/10/1984, 28/06/1980, 29/02/1980, 30/11/1982 1980/02/29, 1980/06/28, 1982/11/30, 1984/10/20  No ambiguity  12/11/1980: Dec or Nov? Kalkulus Relasional 12
  • 13. CHAR vs VARCHAR  Fixed length  Lebih cepat diakses  Boros space  Variable length  Lebih hemat ruang  Lebih lambat diakses (diatasi dengan INDEX) Kalkulus Relasional 13
  • 14. CREATE TABLE  Specifies a new base relation by giving it a name, and specifying each of its attributes and their data types (INTEGER, FLOAT, DECIMAL(i,j), CHAR(n), VARCHAR(n))  A constraint NOT NULL may be specified on an attribute CREATE TABLE DEPARTMENT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9) ); Slide 8-14
  • 15. CREATE TABLE  In SQL2, can use the CREATE TABLE command for specifying the primary key attributes, secondary keys, and referential integrity constraints (foreign keys).  Key attributes can be specified via the PRIMARY KEY and UNIQUE phrases CREATE TABLE DEPT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9), PRIMARY KEY (DNUMBER), UNIQUE (DNAME), FOREIGN KEY (MGRSSN) REFERENCES EMP ); Slide 8-15
  • 16. Bonus Time: Tabel Movie mID Title Year Director 101 Gone with the Wind 1939 Victor Fleming 102 Star Wars 1977 George Lucas 103 The Sound of Music 1965 Robert Wise 104 E.T. 1982 Steven Spielberg 105 Titanic 1997 James Cameron 106 Show White 1937 107 Avatar 2009 James Cameron 108 Raiders of the Lost Ark 1982 Steven Spielberg Kalkulus Relasional 16
  • 17. Bonus Time: CREATE TABLE Movie CREATE TABLE Movie ( mID INT, title VARCHAR(20), year NUMBER(4), director VARCHAR(20) ); Kalkulus Relasional 17
  • 18. Tabel Reviewer rID Name 201 Sarah Martinez 202 Daniel Lewis 203 Brittany Harris 204 Mike Anderson 205 Chris Jackson 206 Elizabeth Thomas 207 James Cameron 208 Ashley White Kalkulus Relasional 18
  • 19. rID mID Stars RatingDate 201 101 2 2011-01-22 Tabel Rating 201 101 4 2011-01-27 202 106 4 203 103 2 2011-01-20 203 108 4 2011-01-12 201 108 2 2011-01-30 204 101 3 2011-01-09 205 103 3 2011-01-27 205 104 2 2011-01-22 205 108 4 206 107 3 2011-01-15 206 106 5 2011-01-19 207 107 5 2011-01-20 208 104 3 2011-01-02 Kalkulus Relasional 19
  • 20. DROP TABLE  Used to remove a relation (base table) and its definition  The relation can no longer be used in queries, updates, or any other commands since its description no longer exists  Example: DROP TABLE DEPENDENT; Slide 8-20
  • 21. ALTER TABLE  Used to add an attribute to one of the base relations  The new attribute will have NULLs in all the tuples of the relation right after the command is executed; hence, the NOT NULL constraint is not allowed for such an attribute  Example: ALTER TABLE EMPLOYEE ADD JOB VARCHAR(12);  The database users must still enter a value for the new attribute JOB for each EMPLOYEE tuple. This can be done using the UPDATE command. Slide 8-21
  • 22. REFERENTIAL INTEGRITY OPTIONS  We can specify RESTRICT, CASCADE, SET NULL or SET DEFAULT on referential integrity constraints (foreign keys) CREATE TABLE DEPT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9), PRIMARY KEY (DNUMBER), UNIQUE (DNAME), FOREIGN KEY (MGRSSN) REFERENCES EMP ON DELETE SET DEFAULT ON UPDATE CASCADE ); Slide 8-22
  • 23. REFERENTIAL INTEGRITY OPTIONS (continued) CREATE TABLE EMP ( ENAME VARCHAR(30) NOT NULL, ESSN CHAR(9), BDATE DATE, DNO INTEGER DEFAULT 1, SUPERSSN CHAR(9), PRIMARY KEY (ESSN), FOREIGN KEY (DNO) REFERENCES DEPT ON DELETE SET DEFAULT ON UPDATE CASCADE, FOREIGN KEY (SUPERSSN) REFERENCES EMP ON DELETE SET NULL ON UPDATE CASCADE ); Slide 8-23
  • 24. Additional Data Types in SQL2 and SQL-99 Has DATE, TIME, and TIMESTAMP data types  DATE:  Made up of year-month-day in the format yyyy-mm-dd  TIME:  Made up of hour:minute:second in the format hh:mm:ss  TIME(i):  Made up of hour:minute:second plus i additional digits specifying fractions of a second  format is hh:mm:ss:ii...i  TIMESTAMP:  Has both DATE and TIME components Slide 8-24
  • 25. Additional Data Types in SQL2 and SQL-99 (cont.)  INTERVAL:  Specifies a relative value rather than an absolute value  Can be DAY/TIME intervals or YEAR/MONTH intervals  Can be positive or negative when added to or subtracted from an absolute value, the result is an absolute value Slide 8-25
  • 26. Pustaka  Elmasri dan Navathe, "Foundation of Database System"  http://tjerdastangkas.blogspot.com/search/label/ikd312 Kalkulus Relasional 26