Create new table with mySQL query

0 votes
267 views
added Aug 4, 2017 in mySQL by anonymous
edited Jul 12, 2019 by LC Marshal

In order to create table in database, you need at least one column;

CREATE TABLE new_table LIKE old_table;

 

CREATE TABLE ... LIKE to create a new empty new_table based on the definition of old_table, including any column attributes and indexes defined in the old_table.

1 Response

0 votes
responded Sep 13, 2019 by LC Marshal Captain (25,790 points)
// sql to create table
$sql = "CREATE TABLE lcNewTable (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
 
if ($conn->query($sql) === TRUE) {
    echo "Table lcNewTable created successfully";
} else {
    echo "Error creating table: " . $conn->error;
}
$conn->close();

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...