SQL CREATE TABLE

SQL CREATE TABLE

 SQL CREATE TABLE

Use the CREATE TABLE statement to create a new table in the MySQL database. You must create and select a database to create tables in it.

Syntax:

CREATE TABLE [IF NOT EXISTS] table_name (
     coloumn1,
     coloumn2
  ) engine=table_type;

Here [IF NOT EXISTS] is used to create a table only if there is no existing table with the name. The database engine can be used as per your requirements. A column can be defined as follows.

 column_name data_type[size] [NOT NULL|NULL] [DEFAULT value] [AUTO_INCREMENT],

Example:

For example, create table users to store information of our web application users with their account login information.

MySQL
1
2
3
4
5
6
7
8
9
10
CREATE TABLE users (
  id INT(11) NOT NULL AUTO_INCREMENT,
  username VARCHAR(20) NOT NULL,
  password VARCHAR(20) NOT NULL,
  email VARCHAR(60) DEFAULT NULL,
  signup_date DATE DEFAULT NULL,
  last_update_date DATE DEFAULT NULL,
  description VARCHAR(200) DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB
Reactions

Post a Comment

0 Comments

close