Jump to: navigation, search

PHP MySQL Query Create Tables

From w3cyberlearnings

Contents

PHP MySQL Create Table and Insert Sample Records

Create these two tables and insert some sample records for this tutorial.

Create employee table

 CREATE TABLE IF NOT EXISTS employee(
    id INT NOT NULL AUTO_INCREMENT,
    name VARCHAR(200) NOT NULL,
    grade char(1) NOT NULL,
    PRIMARY KEY(id)
);


INSERT INTO employee(name,grade) VALUES('John','a');
INSERT INTO employee(name,grade) VALUES('Mark','a');
INSERT INTO employee(name,grade) VALUES('Smit','a');
INSERT INTO employee(name,grade) VALUES('Lili','a');
INSERT INTO employee(name,grade) VALUES('Alex','c');
INSERT INTO employee(name,grade) VALUES('Walton','c');
INSERT INTO employee(name,grade) VALUES('Kim','d');
INSERT INTO employee(name,grade) VALUES('Marry','d');
INSERT INTO employee(name,grade) VALUES('Paul','c');
INSERT INTO employee(name,grade) VALUES('Christ','c');

Create employee_salary table


CREATE TABLE employee_salary( 
     id INT NOT NULL AUTO_INCREMENT,
     employee_id INT NOT NULL,
     salary DOUBLE NOT NULL,
     PRIMARY KEY(id)
);

INSERT INTO employee_salary(employee_id,salary) VALUES(1,25);
INSERT INTO employee_salary(employee_id,salary) VALUES(2,20);
INSERT INTO employee_salary(employee_id,salary) VALUES(3,23);
INSERT INTO employee_salary(employee_id,salary) VALUES(4,25);
INSERT INTO employee_salary(employee_id,salary) VALUES(5,30);
INSERT INTO employee_salary(employee_id,salary) VALUES(6,35);
INSERT INTO employee_salary(employee_id,salary) VALUES(7,40);
INSERT INTO employee_salary(employee_id,salary) VALUES(8,80);
INSERT INTO employee_salary(employee_id,salary) VALUES(9,50);
INSERT INTO employee_salary(employee_id,salary) VALUES(10,60);

Related Links


  1. MySQL Connect
  2. Create Database
  3. Connect to Database
  4. Delete Database
  5. Create Table
  6. Insert Record
  7. Insert From Array
  8. Insert From File
  9. Update Record
  10. Query Single Record
  11. Query Multiple Records
  12. Query Uses LIMIT
  13. Query Uses ORDER BY
  14. Delete Table
  1. Create Two Tables for this section tutorial
  2. Query Uses AND Operator
  3. Query Uses OR Operator
  4. Query Uses INNER JOIN
  5. Query Uses LEFT OUTER JOIN
  6. Query Uses RIGHT OUTER JOIN
  7. Query with Subquery
  1. MySQL Aggregate Count
  2. MySQL Aggregate SUM
  3. MySQL Aggregate MAX
  4. MySQL Aggregate MIN
  5. MySQL Aggregate AVG
  6. MySQL Query Uses GROUP BY
  7. MySQL Query Uses Having
  1. PHP MySQL Create Date
  2. PHP MySQL Insert Date
  3. PHP MySQL Query Date
Navigation
Web
SQL
MISC
References