cristhian_alca@yahoo.com
cristhian_alca@yahoo.com
Common MySQL Statements
Short reference to some useful MySQL statements to create and update table structures (metadata) and do some common queries, updates and deletions from tables.

DOMAIN

CREATE DOMAIN AS <domain_name> AS CHAR(5);

TABLE STRUCTURE

A) CREATE TABLE <table_name> ( <attribute_name> <attribute_type> <”” | PRIMARY KEY | NOT NULL > );

B) DROP TABLE <table_name>;

C) (to delete columns) ALTER TABLE <table_name> DROP <column_name> ;

D) (to add Columns) ALTER TABLE <table_name> ADD <attribute_name> <attribute_type> <conditions> ;


TABLE DATA

A) (to erase all table data) DELETE FROM <table_name> ;

B) (to erase one row) DELETE FROM <table_name> WHERE <attribute_name> <condition> <value> ;

C) (to insert one row) INSERT INTO <table_name> VALUES ( '<attribute1_value>', .... , '<attributeN_value>' );

D) (to insert one row with some specified attributes)
INSERT INTO <table_name> ( <attributeAname>, ... , <attributeZname> )
VALUES ( '<attributeA_value>', .... , '<attributeZ_value>' );

E) (to change one row attribute )
UPDATE <table_name> SET <attribute_name> = <value> WHERE <attribute_name> <condition> <value> ;

F) (to search one row)
SELECT < * | <attribute_list > FROM <table_name> WHERE <search_condition> [ ORDER BY <attribute> ];