MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL Create Table

The CREATE Table statement is creates a database table with the given name. A table creation statement requires three parameters. The name of table specify table name in database. The column parameters specify the names of the columns of the table. The datatype parameter specifies the type of data to be store (e.g. varchar, integer, date, etc.).

Tip: In order to get compelet details of the available data types, go to our MySQL Data Types section.

Syntax

CREATE TABLE table_name (
    column_name1 datatype,
    column_name2 datatype,
    column_name3 l3 datatype,
   ....
);

CREATE TABLE Example

The following MySQL statement creates a database called "myDB":

Example

CREATE TABLE tblCustomerLoan(
	pk INT NOT NULL AUTO_INCREMENT Key,
	firstName varchar(50) NULL,
	lastName varchar(50) NULL,
	address varchar(150) NULL
);

Note:

In the above example, The pk column is of type int NOT NULL and will hold an integer. The NOT NULL is a field attribute and it is used to make sure field should not be NULL.

The firstName, lastName and address fields are of type varchar and will hold characters with specified length. The NULL is a field attribute and it is used to allow NULL value to be stored.

The field attribute AUTO_INCREMENT specifies MySQL to go ahead and add the next available number to the pk field. PRIMARY KEY is used to define a column as primary key.

You can use MySQL Command Line Client to create table. It will look like this:

Show CRETATED TABLES

You can check the created table by the following query:

Example

SHOW tables;

You can use MySQL Command Line Client to show table. It will look like this:

Show CRETATED TABLES STRUCTURE

You can check the created table structure by the following query:

Example

DESCRIBE tblCustomerLoan;

You can use MySQL Command Line Client to show table structure. It will look like this: