Create Table
Tables: table is collection of related data. We will store data in database using table format(columns and rows).
Query to create table in database
CREATE TABLE tablename(
column_name DATA_TYPE,
cloumn_name DATA_TYPE
);
Create Table Example
We already created code_calculate database. we are going to create tables in the code_calculate database.Before create table just check which database you are using
CREATE TABLE employees(
empId INT,
empName VARCHAR(20),
department VARCHAR(3)
);
-
Table with name 'employees' is created in the code_calculate database
-
empId, empName, department are the column names
-
INT, VARACHAR are data types, we will learn what are data types in sql in next page
I have written query in 5 lines for readability purpose only, you can create whole query in one line.
CREATE TABLE employees( empId INT, empName VARCHAR(20), department VARCHAR(3) );