Virtual Open Schooling Online courses available at Virtual Open Schooling (VOS), for more details kindly click here!
NIOS Silver Jubilee Year
NIOS

Difference between revisions of "Create Database and Tables"

From NIOS
Jump to: navigation, search
Line 2: Line 2:
 
{| class="wikitable" style="float:right;margin:1em;width:300px;"
 
{| class="wikitable" style="float:right;margin:1em;width:300px;"
 
|-
 
|-
! [[Closing a Connection|Previous Page]] !! [[ICT-Application| Home Page]] !! [[Insert Into a Statement|Next Page]]
+
! [[Closing a Connection|Previous Page]] !! [[ICT-Application| Home Page]] !! [[Insert Into Statement|Next Page]]
 
|-
 
|-
 
|}<div  style="text-align:center;font-weight:bold;padding:0.4em 1em 0.3em 1em;-moz-border-radius: 6px;background-color:#47b8b8; ">ICT Applications</div>
 
|}<div  style="text-align:center;font-weight:bold;padding:0.4em 1em 0.3em 1em;-moz-border-radius: 6px;background-color:#47b8b8; ">ICT Applications</div>
Line 149: Line 149:
 
{| class="wikitable" style="float:right;margin:1em;width:300px;"
 
{| class="wikitable" style="float:right;margin:1em;width:300px;"
 
|-
 
|-
! [[Closing a Connection|Previous Page]] !! [[ICT-Application| Home Page]] !! [[Insert Into a Statement|Next Page]]
+
! [[Closing a Connection|Previous Page]] !! [[ICT-Application| Home Page]] !! [[Insert Into Statement|Next Page]]
 
|-
 
|-
 
|}<div  style="text-align:center;font-weight:bold;padding:0.4em 1em 0.3em 1em;-moz-border-radius: 6px;background-color:#47b8b8; ">ICT Applications</div>
 
|}<div  style="text-align:center;font-weight:bold;padding:0.4em 1em 0.3em 1em;-moz-border-radius: 6px;background-color:#47b8b8; ">ICT Applications</div>
 
[[Category:TOPICS]]
 
[[Category:TOPICS]]

Revision as of 11:52, 24 August 2012

Previous Page Home Page Next Page
ICT Applications


Create a Database

The CREATE DATABASE statement is usedto create a database in MySQL.

Syntax

CREATE DATABASE database_name

Example

The following example creates adatabase called "my_db":


<?php

$con =mysql_connect("localhost","userid","abc123");

if (!$con)

{ die('Could not connect: ' .mysql_error()); }

if (mysql_query("CREATE DATABASEmy_db",$con))

{ echo "Database created"; }

else { echo "Error creatingdatabase: " . mysql_error(); }

mysql_close($con);

?>

Create a Table

The CREATE TABLE statement is used tocreate a table in MySQL.


Syntax


CREATE TABLE table_name

(

column_name1 data_type,

column_name2 data_type,

column_name3 data_type,

....

)

We have to add the CREATE TABLEstatement to the mysql_query() function to execute the command.


Example


The following example creates a tablenamed "Contacts", with four columns. The column names willbe "FirstName", "LastName" and "Phone":


<?php

$con =mysql_connect("localhost","userid","abc123");

if (!$con)

{

die('Could not connect: ' .mysql_error());

}

// Create table

mysql_select_db("my_db",$con);

$sql = "CREATE TABLE Contacts

(

FirstNamevarchar(15),

LastNamevarchar(15),

Phoneint

)";


// Execute query

mysql_query($sql,$con);


mysql_close($con);

?>


Previous Page Home Page Next Page
ICT Applications