Tuesday, June 15, 2010

Database testing - SQL - Creation of Database and Tables for practice

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

Create table employee
(
employee_id int,
Last_name varchar(100),
First_name varchar(100),
Middle_name varchar(100),
Job_id int,
manager_id int,
hiredate datetime,
salary int,
comm varchar(100) ,
department_id int
)

No comments:

Post a Comment