First of all let us create a database with tables so that we can use all the examples given in the next posts for practice and this will help us to have a hold on SQL.
To create a database we use the Data Definition Language Command called CREATE
Syntax:
Create database [Name of the database]
Example:
create database Practice
To create different tables we use the DDL command Create and for tables we need to use the keyword table. We also need to specify the column names and the data type the column holds
Syntax:
Create table [Name of the table]
(
Column 1 Datatype,
Column 2 Datatype,
Column n Datatype
)
Example:
To create a location table for our Practice Database
Create table location
(
location_id int,
regional_group varchar(100)
)
To create a department table for our Practice Database
Create table department
(
department_id int,
Name varchar(100),
location_id int
)
To create a job table for our Practice Database
Create table job
(job_id int,
function1 varchar(50)
)
To create a employee table for our Practice Database
No comments:
Post a Comment