Aplikime Te Bazave Te Te Dhenave 2

download Aplikime Te Bazave Te Te Dhenave 2

of 36

Transcript of Aplikime Te Bazave Te Te Dhenave 2

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    1/36

    Prof Dr Ermir [email protected]

    1

    mailto:[email protected]:[email protected]:[email protected]:[email protected]
  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    2/36

    SQL: standard language Data Definition Language (DDL)

    create, modify, delete tables

    specify constraints

    administer users, security, etc.

    Data Manipulation Language (DML) Specify queries to find tuples that satisfy criteria

    add, modify, remove tuples

    2

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    3/36

    CREATE TABLE ( , )

    INSERT INTO ()VALUES ()

    DELETE FROM WHERE

    UPDATE SET =

    WHERE

    SELECT FROM

    WHERE

    3

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    4/36

    Creates the Students table. Note: the type (domain) of

    each field is specified, andenforced by the DBMS

    whenever tuples are added or

    modified.

    Another example: the Enrolledtable holds information aboutcourses students take.

    CREATE TABLE Students(sid CHAR(20),name CHAR(20),login CHAR(10),

    age INTEGER,gpa FLOAT)

    CREATE TABLE Enrolled(sid CHAR(20),cid CHAR(20),grade CHAR(2))

    4

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    5/36

    Can insert a single tuple using:

    INSERT INTO Students (sid, name, login, age, gpa)VALUES (53688, Smith, smith@ee, 18, 3.2)

    Can delete all tuples satisfying some condition(e.g., name = Smith):

    DELETEFROM Students SWHERES.name = Smith

    Powerful variants of these commands are available;more later! 5

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    6/36

    Keys are a way to associate tuples in differentrelations

    Keys are one form of integrity constraint (IC)

    sid name login age gpa

    53666 Jones jones@cs 18 3.4

    53688 Smith smith@eecs 18 3.2

    53650 Smith smith@math 19 3.8

    sid cid grade

    53666 Carnatic101 C

    53666 Reggae203 B53650 Topology112 A

    53666 History105 B

    EnrolledStudents

    6

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    7/36

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    8/36

    A Foreign Key is a field whose values are keysin another relation.

    sid name login age gpa

    53666 Jones jones@cs 18 3.4

    53688 Smith smith@eecs 18 3.2

    53650 Smith smith@math 19 3.8

    sid cid grade

    53666 Carnatic101 C

    53666 Reggae203 B53650 Topology112 A

    53666 History105 B

    EnrolledStudents

    8

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    9/36

    Foreign key: Set of fields in one relation that isused to `refer to a tuple in another relation.

    Must correspond to primary key of the secondrelation.

    Like a `logical pointer.

    E.g. sidis a foreign key referring to Students:

    Enrolled(sid: string, cid: string,grade: string) If all foreign key constraints are enforced, referential

    integrityis achieved (i.e., no dangling references.)

    9

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    10/36

    Only students listed in the Students relation shouldbe allowed to enroll for courses.

    CREATE TABLE Enrolled(sid CHAR(20), cid CHAR(20), grade CHAR(2),PRIMARY KEY (sid,cid),FOREIGN KEY (sid) REFERENCES Students )

    sid name login age gpa

    53666 Jones jones@cs 18 3.4

    53688 Smith smith@eecs 18 3.2

    53650 Smith smith@math 19 3.8

    sid cid grade

    53666 Carnatic101 C

    53666 Reggae203 B

    53650 Topology112 A

    53666 History105 B

    EnrolledStudents

    10

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    11/36

    IC: condition that must be true for anyinstanceof the database; e.g., domain constraints. ICs are specified when schema is defined.

    ICs are checked when relations are modified. A legalinstance of a relation is one that

    satisfies all specified ICs. DBMS should not allow illegal instances.

    If the DBMS checks ICs, stored data is morefaithful to real-world meaning. Avoids data entry errors, too!

    11

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    12/36

    Remember Students and Enrolled; sidin Enrolled is a foreign key thatreferences Students.

    What should be done if an Enrolled tuple with a non-existent student id isinserted? (Reject it!)

    What should be done if a Students tuple is deleted? Also delete all Enrolled tuples that refer to it.

    Disallow deletion of a Students tuple that is referred to. Set sid in Enrolled tuples that refer to it to a default sid. (In SQL, also: Set sid in Enrolled tuples that refer to it to a special value null,

    denoting `unknownor `inapplicable.) Similar if primary key of Students tuple is updated.

    sid name login age gpa

    53666 Jones jones@cs 18 3.4

    53688 Smith smith@eecs 18 3.2

    53650 Smith smith@math 19 3.8

    sid cid grade

    53666 Carnatic101 C

    53666 Reggae203 B

    53650 Topology112 A53666 History105 B

    Enrolled Students

    12

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    13/36

    The most widely used relational querylanguage.

    Current std is SQL99; SQL92 is a basic subset

    To find all 18 year old students, we can write:SELECT *FROM Students SWHERE S.age=18

    To find just names and logins, replace the first line:

    SELECT S.name, S.login

    sid name login age gpa

    53666 Jones jones@cs 18 3.4

    53688 Smith smith@ee 18 3.2

    13

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    14/36

    What does the following query compute?SELECT S.name, E.cidFROM Students S, Enrolled EWHERE S.sid=E.sid AND E.grade='A'

    S.name E.cid

    Smith Topology112

    sid cid grade

    53831 Carnatic101 C

    53831 Reggae203 B

    53650 Topology112 A53666 History105 B

    Given the following instance ofEnrolled

    we get:

    14

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    15/36

    Hyper Text Markup Language A markup language designed for the creation

    of web pages and other information viewablein a browser The basic language used to write web pages File extension: .htm, .html

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    16/36

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    17/36

    1. Open Notepad2. Click on File -> Save as3. In the File name pull-down box, type in

    webpage.html4. Click on Save5. Type in content for your file

    6. Once you finished the content, click on File -> Save

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    18/36

    For example: , ,,

    etc. Tag usually goes with pair: an open tag () and

    an end tag ()

    Single tag: ,
    Tags are NOT case sensitive

    Effect Code Code Used What It Does

    Bold B Bold Bold

    Italic I Italic Italic

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    19/36

    Page Title Goes Here

    content goes here

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    20/36

    Bgcolor Specifies a background-

    color for a HTML page.

    Background Specifies a background-

    image for a HTML page

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    21/36

    Put text on a webpage

    Today is my first day at my new job, Im so

    excited!

    Output: Today is my first day at my new job, Im so excited!

    Put text in center of a page Hello

    Output: Hello

    Put text on the right of a page

    Hello

    Output: Hello
  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    22/36

    To change text size Hello

    Output: Hello

    To change text color Hello

    Output: Hello

    Using both Hello

    Output: Hello

    Tag attribute

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    23/36

    There are 6 heading commands.

    This is Heading 1

    This is Heading 2

    This is Heading 3

    This is Heading 4

    This is Heading 5

    This is Heading 6

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    24/36

    Unordered list

    Code:

    CoffeeMilk

    Output:

    Coffee Milk

    Ordered list

    Code:

    CoffeeMilk

    Output:

    1. Coffee2. Milk

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    25/36

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    26/36

    A Hypertext link

    < a href=http://www.iusb.edu>IUSB Home

    Output: IUSB Home

    A Email link

    Email me Output: Email me

    http://www.iusb.edu/mailto:[email protected]:[email protected]://www.iusb.edu/
  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    27/36

    .gif

    Graphics Interchange Format

    .jpeg or .jpg Joint Photographic Experts Group

    .bmp

    bitmap

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    28/36

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    29/36

    Computer images are made up of pixels

    Width

    Height

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    30/36

    A form is an area that can contain formelements.

    Commonly used form elements includes:

    Text fields

    Radio buttons

    Checkboxes

    Submit buttons

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    31/36

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    32/36

    When user clicks on theSubmit button, thecontent of the form is sentto another file.

    Username:

    Output

    Username:

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    33/36

    Used when you want theuser to select one or moreoptions of a limitednumber of choices.

    Ihave a car

    Output

    I have a bikeI have a car

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    34/36

    Used when you want theuser to select one of alimited number of choices.

    Male
    Female

    Output

    MaleFemale

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    35/36

    Used when you want to getinput from user.

    Please provide your

    suggestion in the text boxbelow:

    Output

    Please provide yoursuggestion in the text box

    below:

  • 7/28/2019 Aplikime Te Bazave Te Te Dhenave 2

    36/36

    Used when you want userto respond with onespecific answer withchoices you given.

    Select a fruit:

    Apples Bananas

    < option > Oranges

    Output

    Select a fruit: