Basic MySQL Query Commands :
Syntax for Query Commands
1. CREATE Command
The Create command is used to create a table by specifying the tablename, fieldnames and constraints as shown below:
Syntax:
$createSQL=("CREATE TABLE tblName");
Example:
$createSQL=("CREATE TABLE tblstudent(fldstudid int(10) NOTNULL AUTO_INCREMENT PRIMARY KEY,fldstudName VARCHAR(250) NOTNULL,fldstudentmark int(4) DEFAULT '0' ");
2. SELECT Command
The Select command is used to select the records from a table using its field names. To select all the fields in a table, '*' is used in the command. The result is assigned to a variable name as shown below:
Syntax:
$selectSQL=("SELECT field_names FROM tablename");
Example:
$selectSQL=("SELECT * FROM tblstudent");
3. DELETE Command
The Delete command is used to delete the records from a table using conditions as shown below:
Syntax:
$deleteSQL=("DELETE * FROM tablename WHERE condition");
Example:
$deleteSQL=("DELETE * FROM tblstudent WHERE fldstudid=2");
4. INSERT Command
The Insert command is used to insert records into a table. The values are assigned to the field names as shown below:
Syntax:
$insertSQL=("INSERT INTO tblname(fieldname1,fieldname2..) VALUES(value1,value2,...) ");
Example:
$insertSQL=("INSERT INTO Tblstudent(fldstudName,fldstudmark)VALUES(Baskar,75) ");
5. UPDATE Command
The Update command is used to update the field values using conditions. This is done using 'SET' and the fieldnames to assign new values to them.
Syntax:
$updateSQL=("UPDATE Tblname SET (fieldname1=value1,fieldname2=value2,...) WHERE fldstudid=IdNumber");
Example:
$updateSQL=("UPDATE Tblstudent SET (fldstudName=siva,fldstudmark=100) WHERE fldstudid=2");
6. DROP Command
The Drop command is used to delete all the records in a table using the table name as shown below:
Syntax:
$dropSQL=("DROP tblName");
Example:
$dropSQL=("DROP tblstudent");
May 23, 2013
Basic MySQL Query Commands
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment