Archive:PHP and MySQL Programming/Basic Queries: Difference between revisions

wikademia>Wikademia
 
(17 intermediate revisions by 6 users not shown)
Line 1: Line 1:
[[Programming:PHP and MySQL|TOC]]
== Introduction ==
== Introduction ==


Here are a few basic queries to get you going. For more detailed information, have a look at the online documentation on the MySQL website http://dev.mysql.com/doc/refman/5.1/en/index.html .
Here are a few basic queries to get you going. For more detailed information, have a look at the online documentation on the MySQL website http://dev.mysql.com/doc/refman/5.1/en/index.html .
 
{{?}}
== SELECT ==
== SELECT ==


Line 33: Line 31:


  mysql> INSERT INTO table_name
  mysql> INSERT INTO table_name
         (`field1`, `field2`, etc...)
         (field1, field2, etc...)
         VALUES ('val1', 'val2', etc...);
         VALUES ('val1', 'val2', etc...);


Line 39: Line 37:


  mysql> INSERT INTO books
  mysql> INSERT INTO books
         (`ISBN`, `Title`, `Author`, `Year`)
         (ISBN, Title, Author, Year)
         VALUES ('1234567890', 'Programming PHP and MySQL', 'Poisson, R.W', 2006);
         VALUES ('1234567890', 'Programming PHP and MySQL', 'Poisson, R.W', 2006);


Line 46: Line 44:
The DELETE statement is used to remove row(s) from a table. The syntax is as follows :
The DELETE statement is used to remove row(s) from a table. The syntax is as follows :


  mysql> DELETE FROM `table_name`
  mysql> DELETE FROM table_name
         [WHERE condition1, condition2 etc...];
         [WHERE condition1, condition2 etc...];


Example :
Example :


  mysql> DELETE FROM `books`
  mysql> DELETE FROM books
         WHERE `ISBN` = '1234567890';
         WHERE ISBN = '123456789ĞÁ0';


== ALTER ==
== ALTER ==
Line 102: Line 100:
   | REBUILD PARTITION partition_names
   | REBUILD PARTITION partition_names
   | REPAIR PARTITION partition_names
   | REPAIR PARTITION partition_names
   | REMOVE PARTITIONING  
   | REMOVE PARTITIONING


== DROP ==
== DROP ==
Line 108: Line 106:
DROP is used to completely remove a table or database. The syntax is as follows :
DROP is used to completely remove a table or database. The syntax is as follows :


  mysql> DROP `table_name`;
  mysql> DROP table_name;


== TRUNCATE ==
== TRUNCATE ==
Line 114: Line 112:
TRUNCATE is used when you want to remove the data, but not the structure of a table. The syntax is as follows :
TRUNCATE is used when you want to remove the data, but not the structure of a table. The syntax is as follows :


  mysql> TRUNCATE `table_name`;
  mysql> TRUNCATE table_name;
 
[[../Creating a Table/|Previous: Creating a Table]] | [[../|TOC]] | [[../Common Functions and Operators/|Next: Common Functions and Operators]]


[[Category:PHP]]
[[Category:PHP and MySQL Programming|{{SUBPAGENAME}}]]
[[Category:MySQL]]