Sei sulla pagina 1di 36

Prof Dr Ermir Rogova ermir.rogova@uni-prizren.

com

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

CREATE TABLE <name> ( <field> <domain>, )


INSERT INTO <name> (<field names>) VALUES (<field values>) DELETE FROM <name> WHERE <condition> UPDATE <name> SET <field name> = <value> WHERE <condition>

SELECT <fields> FROM <name> WHERE <condition>

Creates the Students table. Note: the type (domain) of each field is specified, and enforced by the DBMS
whenever tuples are added or

CREATE TABLE Students (sid CHAR(20), name CHAR(20), login CHAR(10), age INTEGER, gpa FLOAT)

CREATE TABLE Enrolled (sid CHAR(20), Another example: the Enrolled cid CHAR(20), table holds information about grade CHAR(2))

modified.

courses students take.


4

Can insert a single tuple using:


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

INSERT INTO VALUES

Can delete all tuples satisfying some condition (e.g., name = Smith):
DELETE FROM Students S WHERE S.name = Smith

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

Enrolled
sid 53666 53666 53650 53666

Keys are a way to associate tuples in different relations Keys are one form of integrity constraint (IC)
cid grade Carnatic101 C Reggae203 B Topology112 A History105 B

Students
sid 53666 53688 53650 name login Jones jones@cs Smith smith@eecs Smith smith@math age 18 18 19 gpa 3.4 3.2 3.8

E.g. sid is a key for Students. What about name? The set {sid, gpa} is a superkey.

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


Students
sid 53666 53688 53650 name login Jones jones@cs Smith smith@eecs Smith smith@math age 18 18 19 gpa 3.4 3.2 3.8

Enrolled
sid 53666 53666 53650 53666 cid grade Carnatic101 C Reggae203 B Topology112 A History105 B

Foreign key : Set of fields in one relation that is used to `refer to a tuple in another relation.
Must correspond to primary key of the second

relation. Like a `logical pointer.

E.g. sid is a foreign key referring to Students:


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

integrity is achieved (i.e., no dangling references.)


9

Only students listed in the Students relation should be 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 )

Enrolled
sid 53666 53666 53650 53666 cid grade Carnatic101 C Reggae203 B Topology112 A History105 B

Students
sid 53666 53688 53650 name login Jones jones@cs Smith smith@eecs Smith smith@math age 18 18 19 gpa 3.4 3.2 3.8
10

IC: condition that must be true for any instance of the database; e.g., domain constraints.

A legal instance of a relation is one that satisfies all specified ICs.


DBMS should not allow illegal instances.

ICs are specified when schema is defined. ICs are checked when relations are modified.

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

11

Enrolled
sid 53666 53666 53650 53666 cid Carnatic101 Reggae203 Topology112 History105 grade C B A B

sid name login 53666 Jones jones@cs 53688 Smith smith@eecs 53650 Smith smith@math

Students

age 18 18 19

gpa 3.4 3.2 3.8

Remember Students and Enrolled; sid in Enrolled is a foreign key that references Students. What should be done if an Enrolled tuple with a non-existent student id is inserted?

What should be done if a Students tuple is deleted?


(Reject it!)

Similar if primary key of Students tuple is updated.

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 `unknown or `inapplicable.)

12

The most widely used relational query language.


Current std is SQL99; SQL92 is a basic subset

To find all 18 year old students, we can write:


SELECT * FROM Students S WHERE S.age=18
sid name login jones@cs age gpa 18 3.4 3.2 53666 Jones 53688 Smith smith@ee 18

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


SELECT S.name, S.login

13

What does the following query compute?


SELECT S.name, E.cid FROM Students S, Enrolled E WHERE S.sid=E.sid AND E.grade='A'

Given the following instance of Enrolled

sid 53831 53831 53650 53666

cid grade Carnatic101 C Reggae203 B Topology112 A History105 B

we get:

S.name E.cid Smith Topology112


14

Hyper Text Markup Language A markup language designed for the creation of web pages and other information viewable in a browser The basic language used to write web pages File extension: .htm, .html

1.

2.
3.

4.
5. 6.

Open Notepad Click on File -> Save as In the File name pull-down box, type in webpage.html Click on Save Type in content for your file Once you finished the content, click on File > Save

For example: <b>, <font>,<title>, <p> etc. Tag usually goes with pair: an open tag (<b>) and an end tag (<\b>)
Effect Bold Italic Code B I Code Used <B>Bold</B> <I>Italic</I> What It Does Bold Italic

Single tag: <hr>,<br> Tags are NOT case sensitive

<html> <head> <title> Page Title Goes Here </title> </head>


<body> content goes here </body> </html>

Bgcolor Specifies a backgroundcolor for a HTML page. <body bgcolor="#000000"> <body bgcolor="rgb(0,0,0)"> <body bgcolor="black">

Background Specifies a backgroundimage for a HTML page <body background="clouds.gif"> <body background="http://www. w3schools.com/clouds.gif" >

Put text on a webpage


<p>Today is my first day at my new job, Im so

excited!</p> Output: Today is my first day at my new job, Im so excited!

Put text in center of a page


<center>Hello</center> Output: Hello

Put text on the right of a page


<p align=right>Hello</p> Output:

Hello

To change text size


<font size=+3>Hello</font> Output:

Hello

Tag attribute

To change text color


<font color=red>Hello</font> Output: Hello

Using both
<font size=+3 color=red>Hello</font> Output:

Hello

There are 6 heading commands.


<H1>This is Heading 1</H1>
<H2>This is Heading 2</H2>
<H3>This is Heading 3</H3>
<H4>This is Heading 4</H4>
<H5>This is Heading 5</H5>
<H6>This is Heading 6</H6>

Unordered list
Code:

Ordered list

<ul> <li>Coffee</li> <li>Milk</li> </ul> Output:


Coffee Milk

Code: <ol> <li>Coffee</li> <li>Milk</li> </ol> Output:


1. Coffee 2. Milk

<table border=1"> <tr> <th>Heading</th> <th>Another Heading</th> </tr> <tr> Heading <td>row 1, cell 1</td> <td>row 1, cell 2</td> Row 1, cell 1 </tr> Row 2, cell 1 <tr> <td>row 2, cell 1</td> <td></td> </tr> </table>

Another Heading
Row 1, cell 2

A Hypertext link
< a href=http://www.iusb.edu>IUSB Home</a> Output: IUSB Home

A Email link
<a href=mailto:vkwong@iusb.edu>

Email me</a> Output: Email me

.gif
Graphics Interchange Format

.jpeg or .jpg
Joint Photographic Experts Group

.bmp
bitmap

Place all images in the same directory/folder where you web pages are <img src> is a single tag <img src=image.gif>
Output:

Turn an image into a hyerlink


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

src=image.gif></a> Output:

Computer images are made up of pixels <IMG HEIGHT=100" WIDTH=150" SRC="image.gif">


Height

Width

A form is an area that can contain form elements. <form></form> Commonly used form elements includes:
Text fields Radio buttons

Checkboxes
Submit buttons

Used when you want the user to type letters, number, etc. <form> First name: <input type="text" name="firstname"> <br> Last name: <input type="text" name="lastname"> </form>

Output
First name: Last name:

When user clicks on the Submit button, the content of the form is sent to another file. <form name="input" action="html_form_action .asp" method="get"> Username: <input type="text" name="user"> <br> <input type="submit" value="Submit"> </form>

Output
Username:

Used when you want the user to select one or more options of a limited number of choices. <form> <input type="checkbox" name="bike value=bike > I have a bike <br> <input type="checkbox" name="car value=car> I have a car </form>

Output
I have a bike I have a car

Used when you want the user to select one of a limited number of choices. <form> <input type="radio" name="sex" value="male"> Male <br> <input type="radio" name="sex" value="female"> Female </form>

Output
Male Female

Used when you want to get input from user. <form> <p>Please provide your suggestion in the text box below:</p> <textarea row=10 cols=30> </textarea> </form>

Output Please provide your suggestion in the text box below:

Used when you want user to respond with one specific answer with choices you given. <p>Select a fruit:</p> <select name"Fruit"> <option selected> Apples <option> Bananas < option > Oranges </select>

Output Select a fruit:

Potrebbero piacerti anche