DBS Chapter1

Embed Size (px)

Citation preview

  • 8/18/2019 DBS Chapter1

    1/16

    DATABASE SYSTEMChapter 1 - Introduction

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    2/16

    WHAT IS A DATA

    Database is a co

    of related data.

    What is data then?

    Data is a collection

    and figures that caprocessed to produinformation.

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    3/16

    DATABASE MANAGEMENT S

    Database management system stores data inway that it becomes easier to retrieve, manipand produce information

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    4/16

    3 TIER ARCHIT

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

    • Database (Data) Tier : Database, queries, relatioand their constraints.

    • Application (Middle) Tier − Application layer sits acts as a mediator between the end-user and tlayer consists of application server and the progthe database. End-users must be unaware of andatabase beyond the application. At the other tier is not aware of any other user beyond the ap

    User (Presentation) Tier − End-users operate on thknow nothing about any existence of the datablayer. At this layer, multiple views of the databasby the application. All views are generated by areside in the application tier.

  • 8/18/2019 DBS Chapter1

    5/16

    SOME DATABASE TERMIN

    • Table: A table is a matrix with data. A table in a database looks like a simp

    • Column: One column (data element) contains data of one and the sameexample the column postcode.

    • Row: A row (= tuple, entry or record) is a group of related data, for exampone subscription.

    • Redundancy: Storing data twice, redundantly to make the system faster.

    • Primary Key: A primary key is unique. A key value can not occur twice in okey, you can find at most one row.

    • Foreign Key: A foreign key is the linking pin between two tables.

    • Compound Key: A compound key (composite key) is a key that consists ocolumns, because one column is not sufficiently unique.

    • Index: An index in a database resembles an index at the back of a book.

    • Referential Integrity: Referential Integrity makes sure that a foreign key vato an existing row.

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    6/16

    LET’S

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

    • Install WAMP server and run mysql from command prompt

    • SHOW DATABASES: Lists the databases that are accessible by the M

  • 8/18/2019 DBS Chapter1

    7/16

    MYSQL PRA

    Next, let’s add a new table called tutorials_tbl

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    8/16

    MYSQL PRACTICE – CREATE

    create table tutorials_tbl(

    tutorial_id INT NOT NULL AUTO_INCREMENT,

    tutorial_title VARCHAR(100) NOT NULL,

    tutorial_author VARCHAR(40) NOT NULL,

    submission_date DATE,

    PRIMARY KEY (tutorial_id)

    );

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    9/16

    MYSQL PRACTICE – INSERT INTO

    • insert is to add data

    • select * is to select all table contents

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    10/16

    SEARCH FROM TABLE AUTHOR NAME IS ‘S

    • Next, let’s change the tutorial title

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    11/16

    TRY THIS ON YOUR

    • Delete a row:

    DELETE FROM tutorials_tbl WHERE tutorial_id=2;

    • Add more rows with various data then use ORDER BY to sort

    SELECT * from tutorials_tbl ORDER BY tutorial_author ASC

    +-----------------+------------------+------------------------+-------------------------+

    | tutorial_id | tutorial_title | tutorial_author | submission_date |

    +-----------------+------------------+------------------------+-------------------------+| 2 | Learn MySQL | Abdul S | 2007-05-24 |

    | 1 | Learn PHP | John Poul | 2007-05-24 |

    | 3 | JAVA Tutorial | Sanjay | 2007-05-06 |

    +-----------------+------------------+------------------------+-------------------------+

    3 rows in set (0.42 sec)

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    12/16

    NUMERIC DATA• INT - A normal-sized integer that can be signed or unsigned. If signed, th

    range is from -2147483648 to 2147483647. If unsigned, the allowable rang4294967295. You can specify a width of up to 11 digits.

    • TINYINT - A very small integer that can be signed or unsigned. If signed, trange is from -128 to 127. If unsigned, the allowable range is from 0 to 25specify a width of up to 4 digits.

    • SMALLINT - A small integer that can be signed or unsigned. If signed, theis from -32768 to 32767. If unsigned, the allowable range is from 0 to 6553

    specify a width of up to 5 digits.• MEDIUMINT - A medium-sized integer that can be signed or unsigned. If s

    allowable range is from -8388608 to 8388607. If unsigned, the allowable r16777215. You can specify a width of up to 9 digits.

    • BIGINT - A large integer that can be signed or unsigned. If signed, the alfrom -9223372036854775808 to 9223372036854775807. If unsigned, the allfrom 0 to 18446744073709551615. You can specify a width of up to 20 dig

    • synonym for DECIMAL.PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    13/16

    NUMERIC DATA• FLOAT(M,D) - A floating-point number that cannot be unsigned. Y

    the display length (M) and the number of decimals (D). This is not will default to 10,2, where 2 is the number of decimals and 10 is thof digits (including decimals). Decimal precision can go to 24 plac

    • DOUBLE(M,D) - A double precision floating-point number that canunsigned. You can define the display length (M) and the number This is not required and will default to 16,4, where 4 is the number o

    Decimal precision can go to 53 places for a DOUBLE. REAL is a synDOUBLE.

    • DECIMAL(M,D) - An unpacked floating-point number that cannot unpacked decimals, each decimal corresponds to one byte. Deflength (M) and the number of decimals (D) is required. NUMERIC i

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    14/16

    DATE AN

    • DATE - A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12example, December 30th, 1973 would be stored as 1973-12-30.

    • DATETIME - A date and time combination in YYYY-MM-DD HH:MM:SS formbetween 1000-01-01 00:00:00 and 9999-12-31 23:59:59. For example, 3:30afternoon on December 30th, 1973 would be stored as 1973-12-30 15:30

    • TIMESTAMP - A timestamp between midnight, January 1, 1970 and someThis looks like the previous DATETIME format, only without the hyphens be

    numbers; 3:30 in the afternoon on December 30th, 1973 would be store19731230153000 ( YYYYMMDDHHMMSS ).

    • TIME - Stores the time in HH:MM:SS format.

    • YEAR(M) - Stores a year in 2-digit or 4-digit format. If the length is specifieexample YEAR(2)), YEAR can be 1970 to 2069 (70 to 69). If the length is sYEAR can be 1901 to 2155. The default length is 4.

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    15/16

    STRING

    • CHAR(M) - A fixed-length string between 1 and 255 characters in lengthexample CHAR(5)), right-padded with spaces to the specified length wDefining a length is not required, but the default is 1.

    • VARCHAR(M) - A variable-length string between 1 and 255 characters iexample VARCHAR(25). You must define a length when creating a VAR

    • BLOB or TEXT - A field with a maximum length of 65535 characters. BLOBLarge Objects" and are used to store large amounts of binary data, suc

    or other types of files. Fields defined as TEXT also hold large amounts of ddifference between the two is that sorts and comparisons on stored datsensitive on BLOBs and are not case sensitive in TEXT fields. You do not splength with BLOB or TEXT.

    • TINYBLOB or TINYTEXT - A BLOB or TEXT column with a maximum length ocharacters. You do not specify a length with TINYBLOB or TINYTEXT.

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016

  • 8/18/2019 DBS Chapter1

    16/16

    STRING

    • MEDIUMBLOB or MEDIUMTEXT - A BLOB or TEXT column with a maxlength of 16777215 characters. You do not specify a length withMEDIUMBLOB or MEDIUMTEXT.

    • LONGBLOB or LONGTEXT - A BLOB or TEXT column with a maximum4294967295 characters. You do not specify a length with LONGBLLONGTEXT.

    • ENUM - An enumeration, which is a fancy term for list. When definENUM, you are creating a list of items from which the value must (or it can be NULL). For example, if you wanted your field to contor "C", you would define your ENUM as ENUM ('A', 'B', 'C') and onlyvalues (or NULL) could ever populate that field.

    PRESIDENT UNIVERSITY - SANDY DARMOWINOTO 2016