my sql syntax

Download My sql Syntax

If you can't read please download the document

Upload: reka

Post on 13-Jun-2015

780 views

Category:

Design


1 download

TRANSCRIPT

  • 1. Basic Query Commands in MySQL CREATE Command SELECT Command DELETE Command INSERT Command UPDATE Command DROP Command

2. CREATE CommandThe Create command is used to create a table by specifying the tablename, fieldnames and constraints as shown below : Syntax : $createSQL=("CREATE TABLE tblName"); 3. 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"); 4. 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"); 5. 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,...) "); 6. 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"); . 7. 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"); 8. PROCEDURE AND FUNCTIONS ProceduresThe procedure is a program that performs an action and does not return a value (outside of IN OUT and OUT parameters).Functions The function is a program that might perform an action and does return a value. 9. A procedure is declared as: CREATE OR REPLACE PROCEDURE()AS BEGINEND; Procedure Syntax 10. Functions Syntax A function is declared as :CREATE OR REPLACE FUNCTION() RETURNAS BEGIN RETURNEND; 11. This example shows how to export a database. It is a good idea to export the data often as a backup. # mysqldump -u username -ppassword database_name > FILE.sqlReplace username, password and database_name with your MySQL username, password and database name. 1.Export A MySQL Database: 12. MySQL Is arelational database management system(RDBMS)that runs as a server providing multi-user access to a number of databases. 1.Basic Queries 2.Porcedures and Functions 3.Imports and Exports 13. It can be used to back up a database or to move database information from one server to another. It can be used to back up a database or to move database information from one server to another. It can be used to back up a database or to move database information from one server to another. IMPORT AND EXPORT 14. Here, we import a database. Using this to restore data from a backup or to import from another MySQL server. Start by uploading the FILE.sql file to the server where we will be running this command. # mysql -u username -ppassword database_name < FILE.sql2. Import A MySQL Database: