creating a table using sql command with datatype

creating a table using sql command with datatype

creating-tables-using-sql-command.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>creating a table using sql command with datatype</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="creating a table using sql command with datatype">
  <meta name="keywords" content="php, example, code, table, sql command, sql, creating table">
  <meta name="description" content="creating a table using sql command with datatype">
  <style>
   h2, h4{background:#ddd; color:#000083;}
   h2{ padding:3px; margin:3px; font-size:21px;}
   h4{ padding:2px; margin:2px; font-size:18px;}
   p{padding:2px; margin:2px; color:#0099Ff;}
   body{ background:#FFFFFb;}
  </style>
 </head>
 <body>
  <h2>creating a table using sql command with datatype</h2>
  <pre>
   <?php
    /*
     -------------------------------------------------------
     WE WANT TO MAKE A TABLE departments IN THE HR DATABASE
     WE CAN DO IT BY USING SQL COMMAND
     -------------------------------------------------------
    */
    /*
     -------------------------------------------------------------
     WE ALSO WANT : 
     DepartmentID, DepartmentName, ManagerID and LocationID
     AS COLUMNS OF THE TABLE 
     RESPECTIVELY INTEGER, VARCHAR, INTEGER AND INTEGER DATATYPE
     -------------------------------------------------------------
    */
    $sql = "CREATE TABLE departments(DepartmentID INT, DepartmentName VARCHAR(50), ManagerID INT, LocationID INT)";
    /*
     -----------------------------------------------------------------------
     YOU CAN ALSO USE [IF NOT EXISTS] EXPRESSION WHILE CREATIONG THE TABLE
     -----------------------------------------------------------------------
    */
    $sql = "CREATE TABLE IF NOT EXISTS departments(DepartmentID INT, DepartmentName VARCHAR(50), ManagerID INT, LocationID INT)";
    /*
     ----------------------------------------------------
     USING PHP YOU CAN ALSO DO THIS. 
     GET CONNECTION TO DATABASE BY USING : mysql_connect()
     SELECT DATABASE BY USING : mysql_select_db()
     THEN RUN THE QUERY
     ----------------------------------------------------
    */
    
    mysql_connect('localhost', 'root', 'root');
    mysql_select_db('hr');
    mysql_query($sql);
    
    /*
     -----------------------------------------------------------------------------
     TO RUN THE PHP CODE PROVIDE REAL DATA TO mysql_connect AND mysql_select_db()
     -----------------------------------------------------------------------------
    */
   ?>
  </pre>
 </body>
</html>

creating a table using sql command with datatype - output in the client

No comments:

Post a Comment

leave your comments here..