Go Back   Web Server Hosting Forum by BODHost > Support > MySQL Issues.
 

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-05-07, 12:06
BOD Member
 
Join Date: Nov 2005
Posts: 131
Default Creation of table in MySQL Databases

Prior to entering data in rows in a table, definition of tables is essential with appropriate names -

The following is the MySQL query to create a table -

<?php
// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Create a MySQL table in the selected database
mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
age INT)")
or die(mysql_error());

echo "Table Created!";

?>

Explanation for above -

> mysql_query - Create new table

> Example refers to table name

> Descriptive Names is preferred

> Clear names mentions the content of table.

> "id" - Automatic addition of entry in the table.

> INT refers to integer

> NOT NULL refers that columns cannot be Null

> AUTO_INCREMENT - Auto Increment by 1, everytime a new entry is added.

> PRIMARY KEY - Unique Identification of rows.

> 'name VARCHAR(30),' - name(Column name) , VARCHAR{variable character(letters/numbers)}

> 'age INT,' - Stores an Integer

> 'or die(mysql_error());' - Error printing in the process of creation.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump


All times are GMT -6. The time now is 01:48.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Copyright © 1999-2012, BODHost Ltd. All rights reserved.