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 28 • MYSQL STORAGE ENGINES AND DATA TYPESViewing a Table StructureYou can view a table structure using the DESCRIBE statement:mysql>DESCRIBE employees;+-----------+---------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-----------+---------------------+------+-----+---------+----------------+| id | tinyint(3) unsigned | | PRI | NULL | auto_increment || firstname | varchar(25) | | | | || lastname | varchar(25) | | | | || email | varchar(45) | | | | || phone | varchar(10) | | | | |+-----------+---------------------+------+-----+---------+----------------+Alternatively, you can use the SHOW command like so to produce the same result:mysql>SHOW columns IN employees;If you’d like to wield more control over how to parse the schema, consider using the commandsprovided to you by way of the INFORMATION_SCHEMA, described in the upcoming section “TheINFORMATION_SCHEMA.”Deleting a TableDeleting a table, or dropping it, is accomplished via the DROP TABLE statement. Its syntax follows:DROP [TEMPORARY] TABLE [IF EXISTS] tbl_name [, tbl_name,...]For example, you could delete your employees table as follows:DROP TABLE employees;You could also simultaneously drop employees2 and employees3 tables like so:DROP TABLE employees2, employees3;Altering a Table StructureYou’ll find yourself often revising and improving your table structures, particularly in the early stages ofdevelopment. However, you don’t have to go through the hassle of deleting and re-creating the tableevery time you’d like to make a change. Rather, you can alter the table’s structure with the ALTERstatement. With this statement, you can delete, modify, and add columns as you deem necessary. LikeCREATE TABLE, the ALTER TABLE statement offers a vast number of clauses, keywords, and options. It’s leftto you to look up the gory details in the <strong>MySQL</strong> manual. This section offers several examples intended to551

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

Saved successfully!

Ooh no, something went wrong!