MySQL Create Table | How to create table in MySQL
×

MySQL Create Table

0 1561

MySql Create Table: The statement used to create a table in MYSQL is: CREATE TABLE.

General Syntax to MySQL Create Table:

CREATE TABLE table_name (column_name column_exp);

Here table_name is the name of the table, comumn_name  is name of column and column_exp is the explanation of that particular column.


Full Syntax:

CREATE TABLE table_name(
column1 VARCHAR(25) NOT NULL,
column2 VARCHAR(25) NOT NULL,
column3 VARCHAR(25) NOT NULL
);

Here:

  1. INT and VARCHAR is the type of the columns which define what type value, we can enter into that particular column.
  2. AUTO_INCREMENT attribute makes the column value auto incremented means we do not need to give the value of this column.
  3. NOT NULL restrict the column value not to be NULL.

Example:

<?php
// First connect to the database and then create a table.
$connect=mysqli_connect("host","username","password","databasename"); OR die ("connection failed");
$query="CREATE TABLE table_name(
id INT(11) AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(25) NOT NULL,
city VARCHAR(25) NOT NULL
)";
$result=mysqli_query($connect,$query);
if($result){
echo "Table created successfully";
}
?>

For any issue and query you can feel free discuss to us, we always happy to serve you.. Please send your queries on below comment box.



Share:


Discount Coupons



Leave a Reply


Comments
    Waiting for your comments