10. Page 10
– Table 34.1 Required PHP and Perl RPMs for MySQL Support
RPM RPM
php-mysql MySQL database specific support for PHP
perl-DBI Provides a generic Perl interface for interacting with
relational databases
perl-DBD-MySQL MySQL database specific support for Perl
18. Page 18
UPDATEUPDATESyntax:Syntax:
UPDATE [table] SET [column]=[value] WHERE [criteria]
UPDATE Used_Vehicles SET mileage=66000 WHERE vehicle_id=1;
UPDATE [table] SET [column]=[value] WHERE [criteria]
Example:
UPDATE Used_Vehicles SET mileage=66000 WHERE
vehicle_id=1;
Explanation:
UPDATE updates columns in existing table rows with new
values. The SET clause indicates which columns to modify and the
values they should be given. The WHERE clause, if given,
specifies which rows should be updated. Otherwise all rows are
updated.
27. Page 27
SQL Constraints:
Constraints are used to limit the type of data that can go into a table.
Constraints can be specified when a table is created (with the CREATE TABLE
statement) or after the table is created (with the ALTER TABLE statement).
We will focus on the following constraints:
NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY
CHECK
DEFAULT
28. Page 28
The TOP Clause
The TOP clause is used to specify the number of records to return.
The TOP clause can be very useful on large tables with thousands of records. Returning a large number of records
can impact on performance.
Note: Not all database systems support the TOP clause.
SQL Server Syntax
SELECT TOP number|percent column_name(s)
FROM table_name
examble:
SELECT TOP 2 * FROM Persons
P_Id LastName FirstName Address City
1 HansenOla Timoteivn 10 Sandnes
2 Svendson ToveBorgvn 23 Sandnes
29. Page 29
The LIKE Operator
The LIKE operator is used to search for a specified pattern in a column.
SQL LIKE Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern
EXAMPLE:
SELECT * FROM Persons
WHERE City LIKE 's%'
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10
32. Page 32
With the data in a text file, its time to import the data back into
MySQL. This can be done by passing the commands contained in
the text file into the MySQL client.
For example:
mysql p user=username < guestdb.txt
This passes all the commands in the file into the mysql client just like
you were typing them in.
Importing the DatabaseImporting the Database