how to creating table in mysql with primary key

To create a table in mysql use following commands.

Syntax:-

CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
.
.
.
column_nameN data_type(size)
);

Example:-

CREATE TABLE homedetails
(
Homeno int,
Homename varchar(255),
state varchar(255),
country varchar(255)
);

Create table with primary key

Syntax:-

CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
.
.
.
column_nameN data_type(size),
PRIMARY KEY(column name)
);

Example:-

CREATE TABLE homedetails
(
Homeno int(25),
Homename varchar(255),
state varchar(255),
country varchar(255),
PRIMARY KEY(homeno)
);

Here homeno as primary key

Make column as a not null
null means not having a value, not null means there much be a value.

Syntax:-

column_name data_type(size) NOT NULL

Example:-

CREATE TABLE homedetails
(
Homeno int NOT NULL,
Homename varchar(255) NOT NULL,
state varchar(255),
country varchar(255),
PRIMARY KEY(homeno)
);

Here Homeno and Homename are not null column. it should contain value/data

How to get list of tables name present in database in mysql

Get list of Table name

Syntax:-

SHOW TABLES;

Note:-

# Any number of column can be create.
# Any data type can be used for column.
# Data in Primary key column must be unique it can`t be repeated.
# We can use any word as table name.
# Table name can be combination of Character and number but not number only.
# Number can be used as 1st digit in table name.

Previous Code:-
Delete Database

List Code:-
Mysql Codes

Next Code:-
Auto increment column

Leave reply

Add your comments here

Back to Top