HOW TO CREATE DATABASE & TABLES IN SQL
1. First connect to SQL Server instance: a complete SQL server and you can install many
instances on a machine, but you can have only 1 default instance. An SQL Server instance has
its own copy of the server files, databases, and security credentials.
2. What to see: Object explorer (the left pane, that’s where you see all your created
database objects}
3. If Object explorer not there go to View then click Object explorer.
There are 2 ways to crate DB:
•
•
Graphical Interface: Via right clicking
Using SQL query statement: Click “New Query” or CTRL + N
❖ I’D RECOMMEND USE THE NEW QUERY WAY
1.Creating a User Defined Database
1. CREATE DATABASE Database_Name;
e.g., CREATE DATABASE employee
NB: The best way after defining Database name is to then execute the USE DATABASE
syntax as it makes your database DEFAULT so that all operations done should be on the same
database.
e.g Use employee
2. Renaming a User- Defined Database
alter database old_database_name modify name = new_database_name;
e.g alter database customer modify name = clients;
3. Dropping a User- Defined Database
1. DROP DATABASE Database_Name;
Dropping means deleting
Steps for creating a database (Remember database is made of tables where information is
stored)
1. Define database name using a Create Database syntax then click EXECUTE
2. Make the database default
3. Creating tables (make sure you define data types for attributes e.g., int, varchar, etc) then
click EXECUTE
4. Now time to insert values into tables e.g., insert into Employee values (1, ‘Lone’, ‘Modi’,
14000, ‘71223232’)
5. You make sure your values match defined columns on the table. Then execute.
6. Use syntax: select * table_name syntax to display all information about the table.
e.g. SELECT * FROM EMPLOYEE
it will display all employee information
Evert time you execute the results always shown on the bottom pane.
Database Creation Exercise
1.
2.
3.
4.
Create a database called ZoomEnterprise
Alter the database and name it StarlinkZones
Make the database a default one
Create table employee with columns (EmpId, FirstName, LastName, Salary,
MobileNo )
5. Use select * from employee_tbl to display all columns
6. Insert the provided values below into the database
Create database ZoomEnterprise
Highlight & Execute
alter database ZoomEnterprise modify name = StarlinkZones
Use StarlinkZones
Highlight & Execute
Highlight & Execute
Create table employee_tbl
(
EmpId int primary key,
FirstName varchar (50),
LastName varchar (50),
Salary float,
MobileNo varchar (15)
)
Highlight the whole table and Execute
Display the created columns by using below syntax
select * from employee_tbl
Now time to insert records:
Insert into employee_tbl values (1, 'Lone', 'Modi', 14000, '71223232')
Insert into employee_tbl values (2, 'Kevin', 'Lee', 14500, '73323232')
Insert into employee_tbl values (3, 'Lawrance', 'Bale', 15000, '71223002')
Insert into employee_tbl values (4, 'Kelly', 'Reel', 18000, '71343232')
Highlight all the rows and Execute
Select * from employee_tbl Highlight & Execute
delete from employee_tbl where EmpId=3 Highlight & Execute
update employee_tbl set FirstName='Julia' where EmpId=1 Highlight & Execute
Again, after all this execute select * from employee_tbl and Execute