Select Chapter ❯
MySQL Tutorial
MySQL Create, Drop Tables
You can create or delete MySQL tables as many as you want
Create MySQL Tables
Syntax
Code Expanation
- tableName: is the name of the table you want to create.
- columnName: is the name of the columns you want to create in that table
- columnType: is the type of there respective column.You will understand more in Column Types in next Chapter.
Example of Creating a MySQL Table
<?php $host = 'localhost:3036'; $user = 'root'; $pass = ''; $conn = mysql_connect($host, $user, $pass); mysql_select_db( 'Demodata' ); $sql = "CREATE TABLE student_info ( ". "student_name text(100) NOT NULL, ". "course text(40) NOT NULL, ". ); "; $create = mysql_query( $sql ); ?>
Code Expanation
- This will create a MySQL table name student_info in Demodata database.
- The table has two columns named student_name and course both are having type of text
- The Columns have length of 100 and 40 respectively and these values cannot be Null
You will learn more on Column datatype and other column values in next chapter.
Drop MySQL Tables
You can easily delete any MySQL table you want.But Be aware that you cannot recover data after dropping a table
Syntax
$sql = "DROP TABLE student_info"; $delete = mysql_query( $sql );