Calendar
May 2012
M T W T F S S
« Apr    
 123456
78910111213
14151617181920
21222324252627
28293031  
Statistic
Earn Cash by using your Blog

Posts Tagged ‘sql language’

5 Command DDL (Data Definition Language)

Post an this is my project work on the SQL DML command … may be useful for readers wrote … :)

Overview of the SQL …

SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases. The entire database applications on the market, both free and is licensed, adopt the SQL language for database processing. There are two types of command in SQL, the DDL and DML.

DDL (Data Definition Language) is a SQL command associated with the definition of a database and tables.Some basic commands are included in the DDL, among others.

A. CREATE

Function: CREATE Command is working to create a database or create a table inside the database.

Syntax: CREATE database_name database;

Parameters: -

Example: CREATE pharmacy database;

Explanation: CREATE command above will create a database with the name of the pharmacy.

2. SHOW

Function: This function SHOW Command to display the database or table that we created earlier.

Syntax: SHOW databases;

Parameters: -

Example: SHOW databases;

Explanation: The SHOW command above will show all the existing database.

3. USE

Function: USE Command is working to open / activate / enter the database we have created. Once we enter into the database we have created, then we can manipulate existing data, including to create a table in the database.

Syntax: USE database_name;

Parameters: -

Example: USE pharmacies;

Explanation: The command above will enable the database with the name of the pharmacy so that we can manipulate the data.

4. ALTER

Function: ALTER Command is working to change the structure of a table. Change here is not simply renew the existing table structure, but also changed the name of the field, adding a primary key, change the field type, or delete fields that have been made previously.

Syntax: ALTER TABLE table_name parameter_option;

Parameters: add, modify, drop

Example: ALTER TABLE ADD medication price int (6);

Explanation: The command above will add a field into the price of the drug table.

5. DROP

Function: DROP Command is working to remove, either database, table, or field that has been entered into the table.

Syntax: DROP TABLE table_name;

Parameters: -

Example: DROP TABLE supplier;

Explanation: The command above will remove the table supplier in the pharmacy database.

Mastering The DDL Script Command

DDL is a sub language whose function is to define the SQL database and tables. The commands used are: CREATE, ALTER, and DROP.
Jump ajah well, so the table creation commands you are not experiencing the error, create a database electronicdb and then activate with the following example:

Image and video hosting by TinyPic

and switch on or connect it with the following command:
Image and video hosting by TinyPic

After you run the second command has been entered into the database electronikdb, and you can create a table in the database is active.

Image and video hosting by TinyPicTo understand the command to create a simple table, the condition you should already know what tables you will create, then image data to be stored in it. By using the command:
Image and video hosting by TinyPic
if it has been completed on the do command as above and there is no error, you can see and check with SHOW TABLES command as shown below:
Image and video hosting by TinyPic

Then we go back to the command to create a table tipe_barang:
Image and video hosting by TinyPic

Well, now my friends already have electronikdb database with two tables already contained in it, namely tables and tables jenis_barang tipe_barang.

There again, the SQL language, the command ALTER able to assist us in changing the data and its provisions when we forget to make during the first defines the table. You can change the column names, table names, add column, add primary key, delete the columns that exist there. For example, if we want to add a new column named description of type TEXT on jenis_barang table, the command as follows:

Image and video hosting by TinyPic
and you can see it with the command:
mysql> desc jenis_barang;

By using the same way, you can add a new column on the first part. For that, use the FIRST parameter, such as the following:
SYNTAX: alter table table_name add kolom_baru type (length) [FIRST | AFTER kolom_lama]

Image and video hosting by TinyPic

There is another command to change the name column:
SYNTAX: alter table table_name CHANGE kolom_lama kolom_baru type (length)
Image and video hosting by TinyPic
and as usual, can be checked using desc command.

The latter is in the SQL DROP command is used to remove components of an existing table. You can remove the primary key, or delete the table. Let not curious, straight at aja peep like the ways below.
To remove the primary key, you can use the DROP command. With a command like the following:
SYNTAX: alter table table_name DROP primary key

Image and video hosting by TinyPic

To delete a table column, with the following syntax and command as follows:
SYNTAX: alter table table_name DROP column_name
Image and video hosting by TinyPic

sources http://haidinda.wordpress.com/2009/01/09/menguasai-perintah-ddl/