CST2355 Lab2b Summer2024
CST2355 Lab2b Summer2024
Hand-in:
1. The lab assignment will be graded out of a maximum 3 points. (a maximum of 1.5 points for
the portion handed in during the lab session, and an additional 1.5 points for the portion
handed in before the due date.)
2. This template should be used to submit your lab assignment. That means you should
save a copy of these instructions and then add your screenshots and other notes to that
copy. Then submit the updated version to Brightspace. This will thoroughly document
your work and make it much easier to review before the midterm test.
3. Make sure you have enough screenshots to completely document that you have completed all
the steps.
Activities (Steps):
1. Make sure you have signed the attendance sheet for your lab session! (Otherwise, you will
receive a grade of 0 for this lab.)
1.1. You also need to submit a version of the lab assignment submission before the end of
the lab session that includes all activities up to and including step 3 in order to receive a
grade on the first part of this individual lab. You will be able to hand in a complete,
carefully documented, version of the entire lab (including step 6) up to the Brightspace
due date – that is the upcoming Sunday at 11:59pm.
2. Receive your updated lab instructions from your lab instructor at the beginning of the lab session
and enter them here:
2.1. Special table name(s):__enter your notes here _________________________________
2.2. Special field name(s):__ enter your notes here _________________________________
2.3. Detailed instructions:
(enter your notes here)
3. Now we will try to link to our new tables from the Access application!
3.1. Open your Northwind database version from lab1. Use the File > Save As menu to save it as
lab2.
3.2. In the Develop menu, select the Linked Table Manager, and then select Add.
Set the Data source name to be “DepartmentsLinked” (Note: the lab professor may require you
to use a different table and/or field or report– see step 2.) and Select SQL (Server/Azure)
3.3. Set the connection parameters using YOUR information – server name, loginID, Password.
3.4. If all is OK, you will be prompted with a list of possible tables to link. Select the
dbo.Departments and dbo.Employees tables. (Note: the lab professor may require you to
use a different table and/or field or report– see step 2.)
3.5. If all is OK, you will have two new tables in your list of tables in Access – named
dbo.Departments and dbo.Employees. Here is my screenshot just after using the linked table
manager.
3.6. Double-click the dbo.Departments linked table to open it for editing in the Datasheet View.
Add a new department… Here’s my change (Note: the lab professor may require you to use
a different table and/or field or report– see step 2.)
3.7. Now, go back to SSMS and run a “select * from lab2.dbo.Departments;” query. Here’s mine
showing that the edit from Access has worked!
THIS IS THE POINT AT WHICH YOU NEED TO PROVIDE YOUR WORK BEFORE THE
END OF THE LAB SESSION TO RECEIVE PART MARKS.
Note: The remainder of the lab activities can be either submitted during the lab session, or
submitted later in Brightspace before the final deadline.
4. Now you will use SQL Server Management Studio to create a new database that is owned by
your own personal account by performing the following tasks:
4.1. Create a new database named “lab3”, (YES really lab3 – we will use it in the next labs)
owned by yourlastnameUser, by following these steps:
4.1.1. Connect using your Windows login account (so that you have all the required
privileges).
4.1.3. Restore the backup to a new database called “lab3” by following these steps:
4.1.3.2. Provide the source database as “lab2”. Then a list of backups will appear.
Select the destination as “lab3”. You should have something similar to the
following:
4.1.3.3. If you have a warning message about ‘Tail-log backups…” go to the Options
page and unselect that option.
4.1.3.4. Then click OK to create the new database (including all constraints, etc.)
4.1.3.5. Once restored, you will also need to change owner (by executing the following
query script – you need to change the login name…not likely kingLogin!)
USE lab3;
EXEC sp_changedbowner 'kingLogin', 'true';
4.1.3.6. Navigate to the Security > Logins area and update the yourlastnameUser login
to have lab3 as the default database.
5. Now, create a new project for your scripts. Use File > New > Project. Make sure the “Create
Directory” option is selected. Here is mine:
Provide a screenshot:
6.2. Use the function definition example provided below (it may require minor changes to allow
it to work with your tables …) and run it in SSMS.
use lab3;
DROP FUNCTION IF EXISTS ufnGetFullName;
GO
CREATE FUNCTION dbo.ufnGetFullName(@EmployeeID int)
RETURNS varchar(50)
AS
-- Returns the full name for an employee.
BEGIN
DECLARE @ret varchar(50);
SELECT @ret = LastName + ', ' + FirstName
FROM dbo.Employees e
WHERE e.EmployeeID = @EmployeeID;
IF (@ret IS NULL)
SET @ret = '';
RETURN @ret;
END;
GO
-- Now try it
select dbo.ufnGetFullName(EmployeeID) "Full Name" from
Employees;
-- End of file
6.3. Paste a screenshot of the example query (or one very similar) to show the ufnGetFullName()
function working to provide the employees full name for your own employeeid. Make sure
the screenshot clearly shows your login in the connection and the query and query result.
7. Once you have embedded all of your screenshots, I would encourage you to show the result to
your lab professor – if you are done in the lab session. Make sure you have included all of your
screen shots to document your work and submit the file in Brightspace and you’re done!