Menu

How to create table in database-SQL


For create a table in a database the CREATE TABLE statement is used.

Syntax for create a table in database

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

For create a table three parameter is used

The column_name parameters specify the names of the columns of the table.

The data_type parameter specifies what type of data the column can hold (e.g. varchar, integer, decimal, date, etc.).

The data_type parameter specifies the length of the column.

Example

CREATE TABLE Student
(
ID int,
LastName varchar(50),
FirstName varchar(50),
RollNo varchar(50),
Address varchar(50),
City varchar(50)
);

Here Student is the table name and LastName, FirstName, RollNo, Address, City is name of the column.

Varchar is a data type and the maximum length of this field are 50 character.








Connection failed: SQLSTATE[28000] [1045] Access denied for user 'studentdb'@'localhost' (using password: YES)

Subscribe