Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
35 views3 pages

SQLServer - Lab 9

The document outlines a series of SQL Server lab exercises, including creating stored procedures for various database operations such as counting students, checking employee numbers, and updating project assignments. It also includes tasks for adding columns, creating audit tables, and implementing triggers to enforce data integrity. Additionally, there are XML-related tasks for displaying data and inserting records from XML documents into a new table.
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)
35 views3 pages

SQLServer - Lab 9

The document outlines a series of SQL Server lab exercises, including creating stored procedures for various database operations such as counting students, checking employee numbers, and updating project assignments. It also includes tasks for adding columns, creating audit tables, and implementing triggers to enforce data integrity. Additionally, there are XML-related tasks for displaying data and inserting records from XML documents into a new table.
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/ 3

SQLServer Lab

1. Create a stored procedure without parameters to show the number of


students per department name.[use ITI DB]

2. Create a stored procedure that will check for the # of employees in the
project p1 if they are more than 3 print message to the user “'The number
of employees in the project p1 is 3 or more'” if they are less display a
message to the user “'The following employees work for the project p1'” in
addition to the first name and last name of each one. [Company DB]

3. Create a stored procedure that will be used in case there is an old


employee has left the project and a new one become instead of him. The
procedure should take 3 parameters (old Emp. number, new Emp. number
and the project number) and it will be used to update works_on table.
[Company DB]

4. add column budget in project table and insert any draft values in it then
then Create an Audit table with the following structure
ProjectNo UserName ModifiedDate Budget_Old Budget_New
p2 Dbo 2008-01-31 95000 200000

This table will be used to audit the update trials on the Budget column
(Project table, Company DB)
Example:
If a user updated the budget column then the project number, user name
that made that update, the date of the modification and the value of the
old and the new budget will be inserted into the Audit table
Note: This process will take place only if the user updated the budget
column

5. Create a trigger to prevent anyone from inserting a new record in the


Department table [ITI DB]
“Print a message for user to tell him that he can’t insert a new record in
that table”
6. Create a trigger that prevents the insertion Process for Employee table in
March [Company DB].

7. Create a trigger on student table after insert to add Row in Student Audit
table (Server User Name , Date, Note) where note will be “[username]
Insert New Row with Key=[Key Value] in table [table name]”
Server User Name Date Note

8. Create a trigger on student table instead of delete to add Row in Student


Audit table (Server User Name, Date, Note) where note will be“ try to
delete Row with Key=[Key Value]”

9. Display all the data from the Employee table (HumanResources Schema)
As an XML document “Use XML Raw”. “Use Adventure works DB”
A) Elements
B) Attributes

10. Display Each Department Name with its instructors. “Use ITI DB”
A) Use XML Auto
B) Use XML Path

11. Use the following variable to create a new table “customers” inside the company DB.
Use OpenXML

declare @docs xml ='<customers>

<customer FirstName="Bob" Zipcode="91126">

<order ID="12221">Laptop</order>

</customer>

<customer FirstName="Judy" Zipcode="23235">

<order ID="12221">Workstation</order>

</customer>

<customer FirstName="Howard" Zipcode="20009">

<order ID="3331122">Laptop</order>
</customer>

<customer FirstName="Mary" Zipcode="12345">

<order ID="555555">Server</order>

</customer>

</customers>'

Bonus :
1. Transform all functions in lab2 to be stored procedures
2. Create a trigger that prevents users from altering any table in Company
DB.
3. Get All Student as an XML Document and display Student Id as attribute
and the other columns as Elements
Use XML Explicit

You might also like