Presentation is loading. Please wait.

Presentation is loading. Please wait.

_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.

Similar presentations


Presentation on theme: "_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1."— Presentation transcript:

1 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1  Wiley and the book authors 2001 E-Commerce: Fundamentals and Applications Chapter 5 : Server-Side Programming II Database Connectivity

2 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications2  Wiley and the book authors 2001 Outline Overview of relational database systems Common SQL commands and their usage

3 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications3  Wiley and the book authors 2001 Relational database Database: a shared collection of interrelated data in a structured form. Relational database: uses relations to represent entities and relationships (the E-R relationship). Schema: describes the structure of the database. The relations are essentially "tables". These tables can be manipulated using SQL (Structured Query Language). Fig. 5.1 shows a snapshot of BOOK database which contains three related tables.

4 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications4  Wiley and the book authors 2001 Snapshot of BOOK Database (Fig. 5.1)

5 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications5  Wiley and the book authors 2001 Basic SQL statements In this chapter, we will provide a brief overview of SQL (The Structured Query Language) using the BOOK database as an example of how to manipulate a relational database based on SQL commands. There are four different basic SQL statements. They are:  SELECT statement;  INSERT statement;  UPDATE statement; and  DELETE statement.

6 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications6  Wiley and the book authors 2001 SELECT Statement The SELECT command displays the results according to the user’s specified condition(s). A typical form of the SELECT statement is given by: SELECT fields FROM table WHERE criteria Example SELECT ISBN, Name FROM sbook WHERE Publisher='Wiley'  It displays all the records with Publisher name "Wiley" and the records will contain only the fields (ISBN, Name) as shown in Fig. 5.2.

7 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications7  Wiley and the book authors 2001 Conditional Query on sbook Table (Fig. 5.2) ISBNName 0471176117Java Electronic Commerce Sourcebook 0471192236E-commerce Security

8 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications8  Wiley and the book authors 2001 Composite SELECT Statement Actually, we can link-up different tables during a query. Let’s see the following example: SELECT Customer.Customer_ID, Customer.Firstname, Transaction.Transaction_No, Transaction.ISBN FROM Customer, Transaction WHERE Customer.Customer_ID = Transaction.Customer_No AND Customer.Customer_ID='JO321' A snapshot of the search result is shown in Fig. 5.3.

9 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications9  Wiley and the book authors 2001 A Composite Query on Customer and Transaction Tables (Fig. 5.3) Customer_IDFirstnameTransaction_NOISBN JO321Jones00010137491360 JO321Jones00021562054961 JO321Jones00030471176117 JO321Jones00090471176117

10 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications10  Wiley and the book authors 2001 INSERT Statement The INSERT statement is for adding new rows to a table. INSERT statement comes in two different forms  allows the user to add only a single new row  allows the user to add a set of rows to a table using information from another table. INSERT statement to add a new row  The typical form of this SQL INSERT is: INSERT INTO table (field_name1, field_name2,.., field_nameN) VALUES (field_value1, field_value2, …, field_valueN )

11 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications11  Wiley and the book authors 2001 INSERT to Add New Record (Fig. 5.4) Customer_IDLastnameFirstnameTel no CH222SimonChan1243-4524 CL444TimClarke5468-1453 JO321LarryJones4562-4555 LE123LeePeter1234-9142 TO133TommyRaymond2478-4699 Example INSERT INTO Customer (Customer_ID, Lastname, Firstname, “Tel no”) VALUES (’TO133', 'Tommy', ’Raymond', '2478-4699')

12 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications12  Wiley and the book authors 2001 UPDATE Statement The UPDATE statement is used to modify the value(s) of the data within a table, and the typical form of it is: UPDATE table SET field_name1 = field_value1, field_name2 = field_value2,.., field_nameN = field_valueN [WHERE ] Using the UPDATE statement, we can also modify the specified record(s) utilising some calculations. Example:  Update transaction no ‘0010’ (in transaction table) for buying 2 books instead of 1 book and recalculate the total amount as well: UPDATE Transaction SET Qty = 2, Total = Total * 2 WHERE Transaction_No = ‘0010’

13 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications13  Wiley and the book authors 2001 Using UPDATE Statement to Modify Transaction Table (Fig. 5.5) Transaction_NoCustomer_N o DateISBNQtyTotal 0001JO3211/1/0001374913601$380.00 0002JO3211/1/0015620549612$456.00 0003JO3211/1/0004711761171$280.00 0004LE1231/5/0000791327072$810.00 0005LE1231/5/0004711922362$440.00 0006CL4441/5/0004711761171$280.00 0007CL4441/5/0004711922361$220.00 0008CL4441/5/0018868010881$324.00 0009JO3211/10/0004711761172$560.00 0010CH2221/18/0015620549612$456.00

14 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications14  Wiley and the book authors 2001 DELETE Statement The DELETE statement is used to remove a record or a series of records from a table under specific condition(s). The typical form of it is given by: DELETE FROM table [WHERE ] Using the Customer Table as an example, we can delete all the records with Lastname(s) containing the character “i” by using the following statement: DELETE FROM Customer WHERE Lastname LIKE ‘%i%’

15 _______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications15  Wiley and the book authors 2001 Customer Table After DELETE Operation (Fig. 5.6) Customer_IDLastnameFirstnameTel no CH222ChanSimon1243-4524 CR443JaneCraw4875-2222 JO321LarryJones4562-4555 TO133TommyRaymond2478-4699 LE123LeePeter1234-9142


Download ppt "_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1."

Similar presentations


Ads by Google