Skip to main content

Managing Database Tables


1. Login in to the mysql client using the login name and password provided by your instructor.

2. View the existing databases that the MySQL Server is maintaining.

SHOW DATABASES;

3. Utilize the photo_album database.

USE photo_album;

4. Create the first table called customers that will store the information related to the customers
who have purchased access to the online photo album

CREATE TABLE customers (
email_customer VARCHAR(50) NOT NULL DEFAULT '',
f_name VARCHAR(20) NOT NULL DEFAULT '',
l_name VARCHAR(30) NOT NULL DEFAULT '',
addr1 VARCHAR(30) NOT NULL DEFAULT '',
addr2 VARCHAR(30) NULL,
addr_city VARCHAR(25) NOT NULL DEFAULT '',
addr_state CHAR(3) NOT NULL DEFAULT '',
addr_zip CHAR(10) NOT NULL DEFAULT '',
primary_phone CHAR(12) NOT NULL DEFAULT '',
secondary_phone CHAR(12) NULL,
term_date DATE NOT NULL DEFAULT 0,
active_customer ENUM('True', 'False') NOT NULL DEFAULT
'True',
PRIMARY KEY (email_customer)
) ENGINE=INNODB;


5. Create the second table called logins that will contain the login authentication data. Each
customer will be able to have up to 5 logins for their site (this could be given to family and
friends to access their photos).

CREATE TABLE logins (
login_name VARCHAR(30) NOT NULL DEFAULT '',
email_customer VARCHAR(50) NOT NULL DEFAULT '',
f_name VARCHAR(20) NOT NULL DEFAULT '',
l_name VARCHAR(30) NOT NULL DEFAULT '',
passwd VARCHAR(30) NOT NULL DEFAULT '',
last_login DATETIME NOT NULL DEFAULT 0,
active_login ENUM('True', 'False') NOT NULL DEFAULT 'True',
PRIMARY KEY (login_name),
INDEX (email_customer),
FOREIGN KEY (email_customer)
REFERENCES customers (email_customer)
ON UPDATE CASCADE
) ENGINE=INNODB;


---- Note: The reason we do not want a DELETE CASCADE on this FK relationship is due to the
fact that we do not want to lose the customer information. By setting the active_customer to
False, we can simply code a response to the customer when they attempt to log in that there
account has been closed. If they wish to pay us, we will be happy to open their account again and
they have lost nothing. However, a policy would have to be in place on when data is archived.

6. Create the third table called images that will contain the information about the photos. The
image information will include information to connect the images to other tables, the size of the
image and the name of the image that was stored. Later in the course, the code will be created
to upload these images with the image information being stored in the database.

CREATE TABLE images (
id_image INT UNSIGNED AUTO_INCREMENT NOT NULL,
login_name VARCHAR(30) NOT NULL DEFAULT '',
image_size VARCHAR(30) NOT NULL DEFAULT '',
file_name VARCHAR(60) NOT NULL DEFAULT '',
image_date DATE NOT NULL DEFAULT 0,
active_image ENUM('True', 'False') NOT NULL DEFAULT 'True',
PRIMARY KEY (id_image),
INDEX (login_name)
) ENGINE=MYISAM;


7. Create the last table called comments that will be used to keep track of the comments attached
to each picture. Each login associated with the images will be able to provide comments against
the picture.

CREATE TABLE comments (
id_comment INT UNSIGNED AUTO_INCREMENT NOT NULL,
login_name VARCHAR(30) NOT NULL DEFAULT '',
id_image INT UNSIGNED NOT NULL DEFAULT 0,
comments TEXT NOT NULL DEFAULT '',
log_date TIMESTAMP NOT NULL,
active_comment ENUM('True', 'False') NOT NULL DEFAULT 'True',
PRIMARY KEY (id_comment),
INDEX (id_image)
) ENGINE=MYISAM;
8. View the list of tables located in the photo_album database.
SHOW TABLES;

9. Review the details of each table created and verify that the tables were designed properly. If
they are not correct, use the ALTER TABLE command to make the changes to correct the
problems.

SHOW CREATE TABLE customers\G
SHOW CREATE TABLE logins\G
SHOW CREATE TABLE images\G
SHOW CREATE TABLE comments\G


Comments

Popular posts from this blog

PHP INTRODUCTION

                     PHP  (recursive acronym for  PHP: Hypertext Preprocessor ) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. PHP stands for  P HP:  H ypertext  P reprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) PHP is an open source software PHP is free to download and use Why PHP? PHP runs on different platforms (Windows, Linux, Unix, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP is FREE to download from the official PHP resource:  www.php.net PHP is easy to learn and runs efficiently on the server side What can PHP do? Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynam

MySQL General Architecture

        MySQL operates in a networked environment using a client/server architecture. In other words, a central  program acts as a server, and various client programs connect to the server to make requests. A MySQL  installation has the following major components: MySQL Server, Client programs and MySQL non client  utilities.  MySQL Server MySQL Server, or mysqld, is the database server program. The server manages access to the actual  database (schema) on disk and in memory. MySQL Server is multi-threaded and supports many  simultaneous client connections. Clients can connect via several connection protocols. For managing  database contents, the MySQL server features a modular architecture that supports multiple storage engines  that handle different types of tables (for example, it supports both transactional and non-transactional  tables). Keep in mind the difference between a server and a host. The server is software (the MySQL server  program mysqld). Server characteristi