Step-by-Step SQL Labs in SQL Server Management Studio (SSMS)

 

Lab 1: Creating a Database

 

1. Open SSMS and connect to your SQL Server instance.

2. Create a new database:

   - Right-click on *Databases* in the Object Explorer.

   - Select *New Database…*.

   - Enter a name for your database (e.g., TestDB).

   - Click *OK*.

 

Lab 2: Creating a Table

 

1. Use the newly created database:

   - In the query window, type:

     sql

     USE TestDB;

     GO

     

   - Click *Execute* or press *F5*.

 

2. Create a table:

   - In the query window, type:

     sql

     CREATE TABLE Employees (

         EmployeeID INT PRIMARY KEY,

         FirstName NVARCHAR(50),

         LastName NVARCHAR(50),

         BirthDate DATE,

         JobTitle NVARCHAR(50)

     );

     GO

     

   - Click *Execute*.

 

Lab 3: Inserting Data into a Table

 

1. Insert data into the Employees table:

   - In the query window, type:

     sql

     INSERT INTO Employees (EmployeeID, FirstName, LastName, BirthDate, JobTitle)

     VALUES (1, 'John', 'Doe', '1985-05-15', 'Software Developer'),

            (2, 'Jane', 'Smith', '1990-07-22', 'Data Analyst'),

            (3, 'Sam', 'Brown', '1978-11-02', 'Project Manager');

     GO

     

   - Click *Execute*.

 

Lab 4: Querying Data from a Table

 

1. Select all data from the Employees table:

   - In the query window, type:

     sql

     SELECT * FROM Employees;

     GO

     

   - Click *Execute*.

 

2. Select specific columns:

   - In the query window, type:

     sql

     SELECT FirstName, LastName, JobTitle FROM Employees;

     GO

     

   - Click *Execute*.

 

Lab 5: Filtering Data

 

1. Filter data using a WHERE clause:

   - In the query window, type:

     sql

     SELECT * FROM Employees WHERE JobTitle = 'Software Developer';

     GO

     

   - Click *Execute*.

 

2. Filter data using a different condition:

   - In the query window, type:

     sql

     SELECT * FROM Employees WHERE BirthDate < '1990-01-01';

     GO

     

   - Click *Execute*.

 

Lab 6: Updating Data

 

1. Update data in the Employees table:

   - In the query window, type:

     sql

     UPDATE Employees

     SET JobTitle = 'Senior Software Developer'

     WHERE EmployeeID = 1;

     GO

     

   - Click *Execute*.

 

2. Verify the update:

   - In the query window, type:

     sql

     SELECT * FROM Employees WHERE EmployeeID = 1;

     GO

     

   - Click *Execute*.

 

Lab 7: Deleting Data

 

1. Delete data from the Employees table:

   - In the query window, type:

     sql

     DELETE FROM Employees WHERE EmployeeID = 3;

     GO

     

   - Click *Execute*.

 

2. Verify the deletion:

   - In the query window, type:

     sql

     SELECT * FROM Employees;

     GO

     

   - Click *Execute*.

 

Lab 8: Dropping a Table

 

1. Drop the Employees table:

   - In the query window, type:

     sql

     DROP TABLE Employees;

     GO

     

   - Click *Execute*.

 

2. Verify the table is dropped:

   - In the query window, type:

     sql

     SELECT * FROM Employees;

     GO

     

   - Click *Execute*.

 

   - You should see an error message indicating that the table doesn't exist.


 

2 Comments

  • Image placeholder

    ojeabuo emmanuel destiny

    2025-01-18 20:06:59

    hi mary is nice to meet you.

  • Image placeholder

    Blessing 234

    2025-01-18 20:10:29

    Awesome...

Leave a comment