SlideShare a Scribd company logo
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

More Related Content

DOCX
Demand & supply
PPT
Seminar Saham
PDF
Data reporting and visualization contest' 09
PDF
Analisis Teknikal Saham 2
PPTX
May 2012 - Marketing Roundtable - Jeff Ewald
XLS
Vertical format for trading account, profit and loss account & balance sheet
PDF
Analyzing professional writing from multiple sources via keystroke logging wi...
PDF
R graphics by Novi Reandy Sasmita
Demand & supply
Seminar Saham
Data reporting and visualization contest' 09
Analisis Teknikal Saham 2
May 2012 - Marketing Roundtable - Jeff Ewald
Vertical format for trading account, profit and loss account & balance sheet
Analyzing professional writing from multiple sources via keystroke logging wi...
R graphics by Novi Reandy Sasmita

Viewers also liked (20)

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

Similar to ikd312-07-ddl (10)

DOCX
Map info data dictionary version 1
PDF
Cube rollup slides
PPTX
Hcb presentation 15th jotc maputo fev2012
PDF
Ppt compressed sensing a tutorial
PPTX
2012 740 stober_ppt
PDF
Cumberland-Atlantic-counties-data-demographics-uez
PDF
Union-county-data-demographics-uez
PDF
A Function by Any Other Name is a Function
PDF
R graphics by Novi Reandy Sasmita
Map info data dictionary version 1
Cube rollup slides
Hcb presentation 15th jotc maputo fev2012
Ppt compressed sensing a tutorial
2012 740 stober_ppt
Cumberland-Atlantic-counties-data-demographics-uez
Union-county-data-demographics-uez
A Function by Any Other Name is a Function
R graphics by Novi Reandy Sasmita
Ad

More from Anung Ariwibowo (20)

PDF
ikp213-unifikasi
PDF
ikp213-06-horn-clause
PDF
ikp213-01-pendahuluan
PDF
ikd312-05-sqlite
PDF
ikd312-05-kalkulus-relasional
PDF
ikd312-04-aljabar-relasional
PDF
ikd312-03-design
PDF
ikd312-02-three-schema
PDF
ikp213-02-pendahuluan
PDF
ikh311-08
PDF
ikh311-07
PDF
ikh311-06
PDF
ikh311-05
PDF
ikp321-svn
PDF
ikh311-04
PDF
ikp321-05
PDF
imsakiyah-jakarta-1433-09
PDF
ikh311-03
PDF
ikp321-04
PDF
ikp321-03
ikp213-unifikasi
ikp213-06-horn-clause
ikp213-01-pendahuluan
ikd312-05-sqlite
ikd312-05-kalkulus-relasional
ikd312-04-aljabar-relasional
ikd312-03-design
ikd312-02-three-schema
ikp213-02-pendahuluan
ikh311-08
ikh311-07
ikh311-06
ikh311-05
ikp321-svn
ikh311-04
ikp321-05
imsakiyah-jakarta-1433-09
ikh311-03
ikp321-04
ikp321-03

Recently uploaded (20)

PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
1. Introduction to Computer Programming.pptx
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
August Patch Tuesday
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Getting started with AI Agents and Multi-Agent Systems
Univ-Connecticut-ChatGPT-Presentaion.pdf
Zenith AI: Advanced Artificial Intelligence
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Web App vs Mobile App What Should You Build First.pdf
DP Operators-handbook-extract for the Mautical Institute
gpt5_lecture_notes_comprehensive_20250812015547.pdf
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Enhancing emotion recognition model for a student engagement use case through...
1. Introduction to Computer Programming.pptx
TLE Review Electricity (Electricity).pptx
Developing a website for English-speaking practice to English as a foreign la...
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
August Patch Tuesday
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles – August ’25 Week III
Final SEM Unit 1 for mit wpu at pune .pptx
A contest of sentiment analysis: k-nearest neighbor versus neural network
A comparative study of natural language inference in Swahili using monolingua...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Getting started with AI Agents and Multi-Agent Systems

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