0% found this document useful (0 votes)
9 views6 pages

Lab No. 03

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Lab No. 03

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB NO.

03 DATE: 05/09/2023
HOW TO CREATE TABLE IN MS SQL SERVER

Lab outcomes:
After completing this lab, students will be able to:
 Know about Microsoft SQL server
 Know about SQL server management studio
 Create table in SQL server

Corresponding CLO and PLO:


 CLO-1, PLO-3(Design and Development solutions)

SOFTWARE REQUIRED:
 Microsoft SQL server
 SQL server management studio

Theory:
In Microsoft SQL Server, a database table is a structured object that stores data in a tabular
format. Tables are the fundamental building blocks of a relational database system, and they
play a crucial role in organizing and storing data efficiently. In this lab, you will learn how to
create tables in MS SQL Server, define their structure, and set constraints to ensure data
integrity.
Table Structure:
Before you create a table, it's essential to understand the structure of a table and its
components:
1. Table Name: Each table in SQL Server must have a unique name within the
database. The table name should be descriptive and indicative of the data it will store.
2. Columns (Fields): Tables consist of one or more columns, also known as fields. Each
column defines the type of data it can hold (e.g., text, numbers, dates) and can have
various constraints such as NOT NULL, unique, or primary key constraints.
3. Data Types: SQL Server provides a wide range of data types to define the kind of
data that can be stored in each column, such as INT, VARCHAR, DATETIME, etc.
4. Constraints: Constraints are rules that you can apply to columns to maintain data
integrity. Common constraints include PRIMARY KEY, FOREIGN KEY, UNIQUE,
and CHECK constraints.
Figure 1 Simple table queries
Where
 table_name: The name of the table you want to create.
 column1, column2, etc.: The names of the columns in the table.
 datatype: The data type for each column.
 constraint: Optional constraints for each column.

Figure 2 Example table


In this example, we create a table named "Students" with columns for student ID, first name,
last name, birth date, and email. We've applied various constraints to ensure data integrity.
Creating tables is a fundamental skill when working with SQL Server databases. It forms the
basis for organizing and storing data effectively. In this lab, you will practice creating tables
with different column types and constraints to gain a better understanding of this essential
database operation.
Creating Tables:
To create a table in MS SQL Server, you will typically use the CREATE TABLE statement.
Here is the basic syntax:
Syntax
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype );
CREATE TABLE is the keyword telling the database system what you want to do. In this
case, you want to create a new table. The unique name or identifier for the table follows the
CREATE TABLE statement.
Then in brackets comes the list defining each column in the table and what sort of data type it
is. The syntax becomes clearer with the following example.
A copy of an existing table can be created using a combination of the CREATE TABLE
statement and the SELECT statement. You can check the complete details at Create Table
Using another Table.
 1st we will create table using create command then insert in the bractkets the data
type of all the columns in the table.

Figure 3: columns of table

 Then put the value into the tables using insert and set command.

Figure 4: inserting values to table


 As the table is created check it using SELECT command either the inserted values
are lies in the column or not

Figure 5: use of select command


Lab Tasks:

Task 1:

1) Create any table in MS SQL Server and insert some values


Solution:
Table creation and entering values:

Table query:

Task 2:

1) Create two tables one for Employee(EmpID, EmpName, EmpSalary,


EmpEmail, EmpDateOfBirth, EmpDepartment) and Second for
department(DepID, DepName,DepHod, DepEmail) insert data into
each table and take screenshots. Set the data types and also apply
constraints
Solution:
Employee Table Query:
Solution:
Employee Table Output:

Department Table Query:

Department Table Output:

Conclusion:
In this lab, I learned about table creation, and all the constraints that can be applied in it.
Rubrics:
Report not Plagiarized Requirements Observations Appropriate Correctly
submitted content are listed and are recorded computation drawn
presented or experimental along with s or conclusion
Laboratory incomplete procedure is detailed numerical with
Reports submission or presented procedure analysis is exact results
late performed and complete
report in all
respects
Category Ungraded Very Poor Poor Fair Good Excellent
Marks 0 1 2 3 4 5

Date Total Marks Instructor’s Signature

Absent Student failed Student Student Student Student


to develop a developed a developed a developed a excelled in
functional partially mostly fully developing
code or functional functional functional fully
complete the code and code and met code and functional
lab objective struggled to the lab met the lab code,
within the accomplish objective objective exceeding
simulation the lab within the within the expected
environment. objective simulation simulation results within
They exhibit within the environment, environment simulation
inadequate simulation achieving , achieving environment.
understanding environment. satisfactory expected They
Demonstrat
in They results. They results. demonstrate
ion
configuring, demonstrate exhibit They mastery in
operating, and minimal moderate demonstrate independently
executing the understanding proficiency in proficiency configuring,
simulation in configuring, in operating and
independently configuring, operating, and configuring, executing the
. operating, and executing the operating, simulation.
executing the simulation and
simulation independently executing
independently . the
. simulation
independent
ly.
Category Ungraded Very Poor Poor Fair Good Excellent

Marks 0 1 2 3 4 5

Date Total Marks Instructor’s Signature

You might also like