11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 34 • MYSQL VIEWSSHOW CREATE VIEW employee_contact_info_view\GThis produces the following output (slightly modified for readability):*************************** 1. row ***************************View: employee_contact_info_viewCreate View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost`SQL SECURITY DEFINER VIEW `employee_contact_info_view`AS select `employees`.`first_name`AS `first_name`,`employees`.`last_name`AS `last_name`,`employees`.`email`AS `email`,`employees`.`phone`AS `phone` from `employees`order by `employees`.`last_name`character_set_client: latin1collation_connection: latin1_swedish_ciWhile useful, you can view the code syntax and much more by using the INFORMATION_SCHEMAdatabase.Using the INFORMATION_SCHEMA DatabaseThe INFORMATION_SCHEMA database includes a views table that contains the following:SELECT * FROM INFORMATION_SCHEMA.views\GAssuming employee_contact_info_view is the only existing view, executing this statement producesthe following output:*************************** 1. row ***************************TABLE_CATALOG: NULLTABLE_SCHEMA: chapter34TABLE_NAME: employee_contact_info_viewVIEW_DEFINITION: select first_name, last_name, email, phone from employeesCHECK_OPTION: NONEIS_UPDATABLE: YESDEFINER: root@localhostSECURITY_TYPE: DEFINERCHARACTER_SET_CLIENT: latin1COLLATION_CONNECTION: latin1_swedish_ciOf course, the beauty of using the information schema is the ability to query any aspect of a view,rather than being forced to sort through a mountain of information. For example, you could use thefollowing query if you just wanted to retrieve the names of the views defined for the chapter34 database:SELECT table_name FROM INFORMATION_SCHEMA.views WHERE table_schema="chapter34"\G667

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!