MySQL is an open source program for processing database / data management. to use mysql course we must first learn a command - command / basic syntax of the mysql itself. As for some commands - command / mysql basic syntax is as follows:
Creating database for creating a new database, so it does not apply if the database already exists or you do not have privilege.Sintaksnya: CREATE DATABASE nama_db;
Delete the database for deleting the database and all tables in it. This command does not apply if the database does not exist or you do not have privilege.Sintaksnya: DROP DATABASE nama_db;
Using the default database for making database and reference of the table that you will use. This command does not apply if the database does not exist or you do not have privilege.Sintaksnya: USE nama_db;
Displays the list of existing database for display in the current system itu.Sintaksnya: SHOW DATABASES;
LEVEL TABELMembuat tableUntuk make minimal table you must specify the name and type of columns you want. The simplest syntax (without any other definition) are:
CREATE TABLE nama_tbl (column1 tipekolom1 (), kolom2 tipekolom2 (), ...); Example: You want to create a table with the name of the profile that has column names (of type char, width 20), column age (integer), column jenis_kelamin (type enum , containing M and F). The syntax: TABLE reate profile (name CHAR (20), age INT NOT NULL, jenis_kelamin ENUM ('F', 'M'));
While a rather complete command in creating a table is to include a specific definition. For example a command like this: CREATE TABLE participants (No. SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, name CHAR (30) NOT NULL, BidangStudi ENUM ('TS', 'WD') NOT NULL, PRIMARY KEY (No), INDEX (name, BidangStudi) );
The above command means making table participants with No. column as PRIMARY KEY is a unique index table that can not be duplicated in the attribute AUTO_INCREMENT column that can automatically sort the numbers that filled him. While the Name column and BidangStudi be used as a regular index.
Create an index on the table, add an index on a table that already exists either unique or that biasa.Sintaksnya: CREATE INDEX index_name ON nama_tbl (column_name); CREATE UNIQUE INDEX index_name ON nama_tbl (column_name);
TableUntuk delete delete tables in a specific database. If done then all the contents, indexes and other attributes will terhapus.Sintaksnya: DROP TABLE nama_tbl;
Remove indeksUntuk erase the index on a table.Sintaksnya: DROP INDEX index name ON nama_tbl;
See table information tableUntuk see what's in the database tertentu.Sintaksnya: SHOW TABLES FROM nama_db;
As for seeing the table description or information about the column using the syntax: column_name DESC nama_tbl; or SHOW COLUMNS FROM FROM nama_tbl nama_db;
Obtain or display information from tableUntuk display the contents of the table with the options specified. For example, to display the entire contents of the table is used: SELECT * FROM nama_tbl;
To display only certain columns: SELECT column1, column2, ... FROM nama_tbl;
To display the contents of the column with tertentuSELECT condition WHERE column1 FROM nama_tbl kolom2 = isikolom;
TableDapat structural modifications used to rename a table or alter its structure as manambah columns or indexes, delete columns or indexes, change the type of column and so on. The general syntax: ALTER TABLE nama_tbl action;
To add a new column in a particular place can use: ALTER TABLE nama_tblADD kolom_baru type () definition;
To add kolom_baru integers after column1 used: ALTER TABLE nama_tblADD kolom_baru INT NOT NULL AFTER column1;
To add a new index on a particular table either unique or common: ALTER TABLE ADD INDEX index_name nama_tbl (column_name); ALTER TABLE ADD UNIQUE nama_tbl nama_indeks (column_name); ALTER TABLE nama_tbl nama_indeks ADD PRIMARY KEY (column_name);
To change the column names and definitions, such as changing the name of type integer kolom_baru be new_kolom char with a width of 30 is used: ALTER TABLE nama_tblCHANGE kolom_baru new_kolom CHAR (30) NOT NULL;
To remove a column and all its attributes, eg, remove column1: ALTER TABLE DROP nama_tbl column1;
To remove either a unique index or used: ALTER TABLE DROP nama_tbl index_name; nama_tbl ALTER TABLE DROP PRIMARY KEY;
TableUntuk modification of information in the record or add a new row in the table, the syntax: INSERT INTO nama_tbl (column_name) VALUES (isi_kolom); or INSERT INTO nama_tbl SET column_name = isi_kolom;
For example, to add two rows in the table profile with the content name = deden & sonny and content age = 17 & 18 are: INSERT INTO profile (name, age) VALUES (deden, 17), (sonny, 18) or INSERT INTO profile SET name = deden, age = 17; INSERT INTO SET profile name = sonny, age = 18;
To modify a record or an existing row corresponding to a column. For example to change the deden age to 18 in the above example can be used syntax: UPDATE profiles SET age = 18 WHERE name = qalit;
To delete a record or a specific row in a table. For example, to remove the existing line digunakansintaks ujang name: DELETE FROM WHERE name = ujang profile;
If WHERE is not included in the table then all content will be deleted profile.
sumber : http://dikrivan.blogspot.com