Download presentation
Presentation is loading. Please wait.
Published byEmil Todd Modified over 9 years ago
1
2440: 141 Web Site Administration Database Management Using SQL Professor: Enoch E. Damson
2
Database Concepts A database is a collection of data about an entities For example, a database might contain checking account information in a bank, product items information in an on-line store, students’ records in a college, and so on Relational databases store information in simple structures called tables Most commercial databases today are relational databases Introduction to SQL2
3
Database Concepts An entity is a distinct object, for example, a person's name, a product, or an event, to be presented in the table The columns in the table contain fields A field contains a single, specific piece of information within a record. So, a record is a group of related fields The data in a table is organized into rows and columns The rows in the table are called records A record contains information about a given entity Introduction to SQL3
4
Sample Item Database Table Introduction to SQL4 Item NumberItem NameUnit PriceInventory 100Camera$267.9913 101Washer$489.568 102TV$189.9929
5
Creating Tables Details required to create database tables include: 1. Table name The table name identifies the table A database can consist of many tables You use the name of a table to reference the table and to manipulate data in that table 2. Fields names 3. Field data types Introduction to SQL5
6
Data Types Introduction to SQL6 Data typeSample dataDescription CHAR(length)Newcastle Dr. For nonnumeric data. Fixed length VARCHAR(length)Newcastle Dr. For nonnumeric data. Variable length (listed length indicates maximum) INTEGER123456For whole number data between –2 31 and +2 31 -1 SMALLINT31For whole number data between –2 15 and +2 15 -1 NUMERIC2.6E+10Very large or vary small numbers DATE11/16/2001For date. Implementations vary in different databases
7
Primary Key An integrity constraint that uses a unique identifier to uniquely identify a record in a table Introduction to SQL7
8
Using Common Fields (Foreign Keys) to Link Two Tables Introduction to SQL8 productI D productNa me mode l Pricemanufacture rID 100WasherD1356.9 9 1 200TVS2255.6 8 2 manufacturerIDnameaddres s phone 1Weiwei Co.Edward Rd 123456 2XYZ Co.Central654321
9
An Introduction to SQL The Structured Query Language (SQL) is a language embedded in relational DBMSs to process relational databases SQL can be used as a: 1. Data definition language (DDL): Used to define a table’s column, add or delete columns, and delete unneeded tables Example: Create table, alter table, drop table, etc 2. Data manipulation language(DML): Used to insert, update, delete, and retrieve data in a table Example: Insert into, update, delete, and select Introduction to SQL9
10
Creating and Dropping Tables CREATE TABLE tableName (field1 dataType, field2 dataType, …) CREATE TABLE tableName (field1 dataType PRIMARY KEY, field2 dataType, …) DROP TABLE tableName Introduction to SQL10
11
Example: Student Table CREATE TABLE student ( id integer PRIMARY KEY, firstName varchar(15), lastName varchar(15)); Introduction to SQL11
12
Inserting Data Into a Table INSERT INTO TABLE tableName VALUES (value1, value2, …) or INSERT INTO TABLE tableName (field1, field2, …) VALUES ( value1, value2, …) Introduction to SQL12
13
Updating Table Data UPDATE tableName SET field1=value1, fiedl2=value2, … WHERE conditions The WHERE clause gives the condition for selecting which rows (records) are to be updated in the table identified as tableName The SET keyword is followed by the field list to be updated If the WHERE clause is omitted, all rows in the table are updated Introduction to SQL13
14
Updating Table Data Conditions in a WHERE clause are similar to conditional statements in JSP Conditions can be constructed with comparison operators and logical operators You can use the six comparison operators ( =, <> for not equal,, =) as well as the three logical operators (AND, OR, and NOT) to create compound conditions or to negate a condition Introduction to SQL14
15
Deleting Records from a Table DELETE FROM tableName WHERE conditions This deletes all rows that satisfy the WHERE clause in the statement If there is no WHERE clause, then all rows in the table are deleted Introduction to SQL15
16
Retrieving Data SELECT field1, field2, … FROM tableName WHERE conditions The SELECT clause lists the fields retrieved in the query result, separated by commas The FROM clause lists one or more table names to be used by the query All fields listed in the SELECT or WHERE clauses must be found in one and only one of the tables listed in the FROM clause Introduction to SQL16
17
Retrieving Data… The WHERE clause contains conditions for selecting rows from the tables listed in the FROM clause The data retrieved are from the rows that satisfy the condition (and are therefore selected) If the WHERE clause is omitted, all rows are selected Introduction to SQL17
18
Wildcard Characters Special symbols that represent any character or combination of characters Make it easier to use inexact spelling in a query The percent symbol % represents any collection of characters, including zero characters The underscore _ represents any individual character Introduction to SQL18
19
Sorting Retrieved Data SELECT field1, field2, … FROM tableName WHERE conditions ORDER BY sort_field1 DESC, sort_field2, … Sort data retrieved in a particular order Introduction to SQL19
20
Steps to Accessing Databases 1. Load the database driver 2. Define the connection URL 3. Establish the connection 4. Create the statement object 5. Execute a query or update 6. Process the results 7. Close the connection Introduction to SQL20
21
Loading a DBMS Driver The DBMS driver acts as the bridge between the server-side programming environment and the database itself The driver is a piece of software that knows how to talk to the DBMS To load a driver, all you need to do is to load the appropriate class Introduction to SQL21
22
Client-side Scripts and Browser Dependency Client-side scripts are executed in the client browser The browser must provide an appropriate interpreter All browsers come with built-in engines to support certain client-side scripting languages Introduction to SQL22
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.