MSSQL PRACTICAL GUIDELINES
1. Drop the foreign and Primary key constraints on the userLog (the table you created in the last class)
from the TechDesk schema. After that, drop the SerialNo Field on this table and then make the
username
a Primary key. The same Primary key should be the Foreign key to reference the TechDesk.Employees
table on the EmployeeID
2. Note that there are two Faults.FaultLog tables, drop one. Just ensure you only have one faultLog
table linking the Employees table and the Faults table. Hint: To drop a table, you need to drop the
constraints first!
3. Populate the Employees Table with data, at least enough data, if you haven't done so. Next, create
triggers as follows:
- Create a trigger to populate the userLog table once a customer has inserted, updated and deleted
faults in the FaultLog table. In the userLog table, use appropriate messages for the ActionDone
field to indicate what the user has done. For example, if the user deletes a fault, the message
can be 'Deleted a fault'.
THREE TRIGGERS ARE EXPECTED HERE
4. Using the SYNONYM clause, Create a replica of the Employees and Customer tables.
5. On any two tables of your choice, implement a custom store procedure and non-clustered index.
6. Using the BEFORE INSERT Trigger, check if the Customer's and Employee's email addresses are in the
correct format e.g. [email protected] If the email has no @ symbol and dot(.) com or .org
etc., a message should be displayed 'Email entered is invalid, please try again'.
HINT: Your trigger must make use of the FOR EACH ROW clause, NOT LIKE and the IF ... THEN ... END IF
7. Create a VIEW with a select statement joining at least 3 (three) tables. You are free to choose those
tables.
8. Rename the field EmployeeAddress to ResidentialAddress in the Employees table.
9. In this company, Employees can have similar or different categories of work. Using the SELECT
DISTINCT clause and state your observations after you run the query.
10. Using table or tables of your choice, apply some logical operators in your select statement to return
customized selection of data.
11. Write queries that implement at least five wildcards with the LIKE and NOT LIKE operators.
12. Demonstrate appreciation of TRANSACTIONS using triggers. Your transactions should not be
successful or should be rolled-back if a certain criteria is not met.
13. Demonstrate application of the following functions:
> Convenient aggregate functions
> Statistical aggregate functions
> User-defined aggregate functions UDFs
> Analytical functions
> Date functions
14. Using JOINS, generate a report with the following information:
> Customer ID, Customer Name, Customer Phone Number, Device SerialNo, Device Model and Color,
all Faults Details and Ammout of money the customer must pay.
15. Using your own example, demonstrate the querying of a database using XML (Extensible Markup
Language).
16. Implement PIVOT tables in TSQL.
Please note that all queries must be written in order. Enjoy....