From 6a60ed87053c799c4cd12b56f5db40718be18d3e Mon Sep 17 00:00:00 2001 From: Aleksandra Aya Georgievska Date: Fri, 10 Nov 2023 09:09:45 -0500 Subject: [PATCH 1/9] adding readme --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..1c57f6c --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +This is the start of the repo for Group1's CS311 Project 1 From 0f3c2b87ce36bb495373d3e42616e5e495c21422 Mon Sep 17 00:00:00 2001 From: Aleksandra Aya Georgievska Date: Fri, 10 Nov 2023 09:14:54 -0500 Subject: [PATCH 2/9] deleating readme to main --- README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 1c57f6c..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -This is the start of the repo for Group1's CS311 Project 1 From a1b6925de56af6fb6c7042ea9605bbc3e30a6a92 Mon Sep 17 00:00:00 2001 From: nicholaskong100 Date: Fri, 10 Nov 2023 17:52:46 -0500 Subject: [PATCH 3/9] adding swing app --- swing_app/src/Group_1_Project_2_Main.java | 28 ++++ swing_app/src/QueryProcessor.java | 155 ++++++++++++++++++++++ swing_app/src/QueryStorage.java | 123 +++++++++++++++++ swing_app/src/SimpleSwingApp.java | 153 +++++++++++++++++++++ 4 files changed, 459 insertions(+) create mode 100644 swing_app/src/Group_1_Project_2_Main.java create mode 100644 swing_app/src/QueryProcessor.java create mode 100644 swing_app/src/QueryStorage.java create mode 100644 swing_app/src/SimpleSwingApp.java diff --git a/swing_app/src/Group_1_Project_2_Main.java b/swing_app/src/Group_1_Project_2_Main.java new file mode 100644 index 0000000..33278d7 --- /dev/null +++ b/swing_app/src/Group_1_Project_2_Main.java @@ -0,0 +1,28 @@ +public class Group_1_Project_2_Main { + + + public static void main(String[] args) { + + + + // Register the driver + try { + Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); + } catch (ClassNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + + + // Launches the window + SimpleSwingApp app = new SimpleSwingApp(); + + while(true) + { + // detect which drop down option depending on database selection + app.update(); + } + } +} \ No newline at end of file diff --git a/swing_app/src/QueryProcessor.java b/swing_app/src/QueryProcessor.java new file mode 100644 index 0000000..ea367f2 --- /dev/null +++ b/swing_app/src/QueryProcessor.java @@ -0,0 +1,155 @@ +import java.awt.BorderLayout; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +public class QueryProcessor { + + + private static long executionTime; + + // DPC stands for Dim Product Category - the name of the SQL table #1 + + private static DefaultTableModel DPCmodel = new DefaultTableModel(); + private static JPanel DPCjPanel = new JPanel(); + private static JTable DPCjtable = new JTable(DPCmodel); + private static JScrollPane DPCscrollPane = new JScrollPane(DPCjtable); + + // DPS stands for Dim Product SubCategory - the name of the SQL table #2 + + private static DefaultTableModel DPSmodel = new DefaultTableModel(); + private static JPanel DPSjPanel = new JPanel(); + private static JTable DPSjtable = new JTable(DPSmodel); + private static JScrollPane DPSscrollPane = new JScrollPane(DPSjtable); + + public QueryProcessor(QueryStorage queryStorage, String selectSql, JFrame frame) + { + + /* + * Run the SQL Query + */ + try (Connection connection = DriverManager.getConnection(queryStorage.getConnection()); + + Statement statement = connection.createStatement();) + { + + ResultSet resultSet = statement.executeQuery(selectSql); + // Start measuring time of execution here + long startTime = System.currentTimeMillis(); + + // adding columns for first query +// if(selectSql.equals(queryStorage.getFirstQuery())) +// { +// Object[] columns = {"custid", "empid", "orderid"}; +// +// for(int i = 0; i < columns.length;i++) +// { +// DPCmodel.addColumn(columns[i]); +// +// } +// +// +// DPCjPanel.add(DPCscrollPane); +// frame.add(DPCjPanel, BorderLayout.WEST); +// } + // adding rows for the second query +// if(selectSql.equals(queryStorage.getSecondQuery())) +// { +// +// String custid = ""; +// int empid = 0; +// int orderid = 0; +// +// while(resultSet.next()) +// { +// custid = resultSet.getString("custid"); +// empid = resultSet.getInt("empid"); +// orderid = resultSet.getInt("orderid"); +// +// +// Object[] rowData = {custid, empid, orderid}; +// DPCmodel.addRow(rowData); +// } +// +// } + if(selectSql.equals(queryStorage.getThirdQuery())) + { + String[] columns = {"ProductCategoryId", "ProductCategoryName"}; + + for(int i = 0; i < columns.length;i++) + { + DPCmodel.addColumn(columns[i]); + + } + + // how to add the table #1 to the left + DPCjPanel.add(DPCscrollPane); + frame.add(DPCjPanel, BorderLayout.WEST); + + } + else if(selectSql.equals(queryStorage.getFourthQuery())) + { + String[] columns = {"ProductSubcategoryId", "ProductSubcategoryName"}; + + for(int i = 0; i < columns.length;i++) + { + DPSmodel.addColumn(columns[i]); + + } + + // how to add the table #2 to the right + + DPSjPanel.add(DPSscrollPane); + frame.add(DPSjPanel, BorderLayout.EAST); + + } + else if(selectSql.equals(queryStorage.getFifthQuery())) + { + int productCategoryId = 0; + String productCategoryName = ""; + + + while(resultSet.next()) + { + productCategoryId = resultSet.getInt("ProductCategoryId"); + productCategoryName = resultSet.getString("ProductCategoryName"); + + // DPCmodel is the table on the left of the Swing app + // every iteration of the while loop, we are adding a new data per row to the table + + Object[] rowData = {productCategoryId, productCategoryName}; + DPCmodel.addRow(rowData); + } + } + + // End measuring time of execution here + long endTime = System.currentTimeMillis(); + + //Calculate execution time which is from when the query started and ended. + executionTime = endTime - startTime; + + } + catch (SQLException e) + { + e.printStackTrace(); + } + + + + } + + public static long getExecutionTime() + { + return executionTime; + } + + + +} diff --git a/swing_app/src/QueryStorage.java b/swing_app/src/QueryStorage.java new file mode 100644 index 0000000..7762690 --- /dev/null +++ b/swing_app/src/QueryStorage.java @@ -0,0 +1,123 @@ + +import javax.swing.JFrame; + +public class QueryStorage{ + + private String connectionURL; + + + /* + * Here are all the TSQLV 4 code + */ +// private String selectSql1 = "DROP TABLE IF EXISTS dbo.Orders\r\n" +// + "\r\n" +// + "CREATE TABLE dbo.Orders\r\n" +// + "(\r\n" +// + "orderid INT NOT NULL\r\n" +// + "CONSTRAINT PK_Orders PRIMARY KEY,\r\n" +// + "orderdate DATE NOT NULL\r\n" +// + "CONSTRAINT DFT_orderdate DEFAULT(SYSDATETIME()),\r\n" +// + "empid INT NOT NULL,\r\n" +// + "custid VARCHAR(10) NOT NULL\r\n" +// + "\r\n" +// + ");\r\n" +// + "\r\n" +// + "Select O.orderid, O.empid, O.custid\r\n" +// + "From dbo.Orders as O;"; +// +// private String selectSql2 = "Insert INTO dbo.Orders(orderid, empid, custid)\r\n" +// + "VALUES (10003, 3, 'A'),\r\n" +// + "(1004,4,'C'),\r\n" +// + "(1005,5,'D'),\r\n" +// + "(1006,6,'E')\r\n" +// + "\r\n" +// + "\r\n" +// + "Select O.orderid, O.empid, O.custid\r\n" +// + "From dbo.Orders as O;\r\n" +// + ""; + + /* + * BIClass database + */ + + // creates table called [CH01-01-Dimension].[DimProductCategory] + private String selectSql3 = "DROP TABLE IF EXISTS [CH01-01-Dimension].[DimProductCategory] \r\n" + + "\r\n" + + "CREATE TABLE [CH01-01-Dimension].[DimProductCategory] (\r\n" + + " ProductCategoryId INT PRIMARY KEY,\r\n" + + " ProductCategoryName NVARCHAR(255) NOT NULL\r\n" + + ");\r\n" + + "\r\n" + + "SELECT DPC.ProductCategoryId, DPC.ProductCategoryName\r\n" + + "FROM [CH01-01-Dimension].[DimProductCategory] as DPC"; + + // creates table called [CH01-01-Dimension].[DimProductSubcategory] + private String selectSql4 = "DROP TABLE IF EXISTS [CH01-01-Dimension].[DimProductSubcategory] \r\n" + + "\r\n" + + "CREATE TABLE [CH01-01-Dimension].[DimProductSubcategory] (\r\n" + + " ProductSubcategoryId INT PRIMARY KEY,\r\n" + + " ProductSubcategoryName NVARCHAR(255) NOT NULL,\r\n" + + ");\r\n" + + "\r\n" + + "\r\n" + + "Select DPS.ProductSubcategoryId, DPS.ProductSubcategoryName\r\n" + + "From [CH01-01-Dimension].[DimProductSubcategory] as DPS"; + + // insert rows to the table called [CH01-01-Dimension].[DimProductCategory] + private String selectSql5 = "INSERT INTO [CH01-01-Dimension].[DimProductCategory] (ProductCategoryId, ProductCategoryName)\r\n" + + "VALUES\r\n" + + " (1, 'Electronics'),\r\n" + + " (2, 'Clothing'),\r\n" + + " (3, 'Home and Garden')\r\n" + + " \r\n" + + "SELECT DPC.ProductCategoryId, DPC.ProductCategoryName\r\n" + + "From [CH01-01-Dimension].[DimProductCategory] as DPC"; + + + + public QueryStorage(String connectionURL) + { + this.connectionURL = connectionURL; + } + + public void processQuery(String selectSql, JFrame frame) + { + QueryProcessor test = new QueryProcessor(this, selectSql, frame); + + } + + + public String getFourthQuery() { + // TODO Auto-generated method stub + return selectSql4; + } + + public String getThirdQuery() { + // TODO Auto-generated method stub + return selectSql3; + } + + +// public String getFirstQuery() +// { +// return selectSql1; +// } +// +// public String getSecondQuery() { +// // TODO Auto-generated method stub +// return selectSql2; +// } + + public String getConnection() + { + return connectionURL; + } + + public String getFifthQuery() { + // TODO Auto-generated method stub + return selectSql5; + } + + + +} diff --git a/swing_app/src/SimpleSwingApp.java b/swing_app/src/SimpleSwingApp.java new file mode 100644 index 0000000..48a7d7f --- /dev/null +++ b/swing_app/src/SimpleSwingApp.java @@ -0,0 +1,153 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class SimpleSwingApp { + + // Create a database dropdown menu + String[] databaseOption = {"","BIClass"}; + JComboBox databaseDropdown = new JComboBox<>(databaseOption); + + String[] dataRetrievalBIClass = {"Create a Table called [CH01-01-Dimension].[DimProductCategory] (Step 1)", + "Create a Table called [CH01-01-Dimension].[DimProductSubcategory] (Step 2)", + "Insert Values to [CH01-01-Dimension].[DimProductCategory] (Step 3)"}; + JComboBox retrievalDropDownBIClass = new JComboBox<>(dataRetrievalBIClass); + + //String[] dataRetrievalTSQLV4 = {"Create a Table (Step 1)","Insert data into table (Step 2)"}; + //JComboBox retrievalDropDownTSQLV4 = new JComboBox<>(dataRetrievalTSQLV4); + + // for containing the drop downs and the run query button + JPanel panel = new JPanel(); + + JPanel panel2 = new JPanel(); + + // for displaying query solution + //JTextPane textPane = new JTextPane(); + + public SimpleSwingApp() + { + + // Create a new window + JFrame frame = new JFrame("9:15_JDBC_Group 1"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(1200, 900); // Set the JFrame size + + // Create a button to update the text + JButton runQueryButton = new JButton("Run Query"); + // Create an ActionListener and implement the actionPerformed method + + panel.add(runQueryButton); + + // Add an action listener to the JButton + + panel.add(databaseDropdown); + panel.add(retrievalDropDownBIClass); + //panel.add(retrievalDropDownTSQLV4); + + // Run Query code logic + ActionListener buttonActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // Define the action to be performed when the button is clicked + + // when a user selects the database "TSQLV4" +// if(databaseDropdown.getSelectedItem().equals("TSQLV4")) +// { +// String connectionUrl = +// "jdbc:sqlserver://localhost:13001;databaseName=TSQLV4;" +// + "user=sa;password=PH@123456789;encrypt=true;" +// + "trustServerCertificate=true"; +// +// QueryStorage queryStorage = new QueryStorage(connectionUrl); +// +// // I kept this in so you can learn from it . +// // this is example of how the selections from the TSQLV4 database dropdown +// +// if(retrievalDropDownTSQLV4.getSelectedItem().equals("Create a Table (Step 1)")) +// { +// queryStorage.processQuery(queryStorage.getFirstQuery(), frame); +// } +// else if(retrievalDropDownTSQLV4.getSelectedItem().equals("Insert data into table (Step 2)")) +// { +// queryStorage.processQuery(queryStorage.getSecondQuery(), frame); +// } +// } + // Project uses the BIClass database drop down menu. + // where you will implement the logic for that. + + if(databaseDropdown.getSelectedItem().equals("BIClass")) + { + String connectionUrl = + "jdbc:sqlserver://localhost:13001;databaseName=BIClass;" + + "user=sa;password=PH@123456789;encrypt=true;" + + "trustServerCertificate=true"; + + QueryStorage queryStorage = new QueryStorage(connectionUrl); + + // where you will implementing the logic for each selection of the BIClass dropdown + if(retrievalDropDownBIClass.getSelectedItem().equals("Create a Table called [CH01-01-Dimension].[DimProductCategory] (Step 1)")) + { + queryStorage.processQuery(queryStorage.getThirdQuery(), frame); + } + else if(retrievalDropDownBIClass.getSelectedItem().equals("Create a Table called [CH01-01-Dimension].[DimProductSubcategory] (Step 2)")) + { + queryStorage.processQuery(queryStorage.getFourthQuery(), frame); + + } + else if(retrievalDropDownBIClass.getSelectedItem().equals("Insert Values to [CH01-01-Dimension].[DimProductCategory] (Step 3)")) + { + queryStorage.processQuery(queryStorage.getFifthQuery(), frame); + + } + } + else if(databaseDropdown.getSelectedItem().equals("")) + { + JOptionPane.showMessageDialog(null, "You must select a database.", "Message Dialog", JOptionPane.INFORMATION_MESSAGE); + } + + panel.revalidate(); + + JOptionPane.showMessageDialog(null, "Execution time of query is " + QueryProcessor.getExecutionTime() + " milliseconds.", "Message Dialog", JOptionPane.INFORMATION_MESSAGE); + } + }; + + // Add the ActionListener to the JButton + runQueryButton.addActionListener(buttonActionListener); + + // Add the panel with the button and dropdown menu to the "NORTH" position + frame.add(panel, BorderLayout.NORTH); + + // Center the frame on the screen + frame.setLocationRelativeTo(null); + + // Make the frame visible + frame.setVisible(true); + } + + + public void update() + { + System.out.println("\n"); + + if(databaseDropdown.getSelectedItem().equals("")) + { + retrievalDropDownBIClass.setVisible(false); + //retrievalDropDownTSQLV4.setVisible(false); + } + else if(databaseDropdown.getSelectedItem().equals("TSQLV4")) + { + //retrievalDropDownTSQLV4.setVisible(true); + retrievalDropDownBIClass.setVisible(false); + } + else if(databaseDropdown.getSelectedItem().equals("BIClass")) + { + retrievalDropDownBIClass.setVisible(true); + //retrievalDropDownTSQLV4.setVisible(false); + } + + } + + + +} From 5ab0e484a4ff4545143050fa5597d93b23ac79e9 Mon Sep 17 00:00:00 2001 From: Aleksandra Aya Georgievska Date: Mon, 13 Nov 2023 21:18:22 -0500 Subject: [PATCH 4/9] adding template databade code --- SQL_files/MainScript.sql | 2513 +++++++++++++++++++++++++++++++++++ SQL_files/WorkFlowSteps.sql | 15 + 2 files changed, 2528 insertions(+) create mode 100644 SQL_files/MainScript.sql create mode 100644 SQL_files/WorkFlowSteps.sql diff --git a/SQL_files/MainScript.sql b/SQL_files/MainScript.sql new file mode 100644 index 0000000..88f61a6 --- /dev/null +++ b/SQL_files/MainScript.sql @@ -0,0 +1,2513 @@ +-- -- CREATE THE DATABASE + +CREATE DATABASE [9:15_Group1]; +GO + +--------------------- CREATE SCHEMAS ------------------------- +DROP SCHEMA IF EXISTS DbSecurity; +GO +CREATE SCHEMA DbSecurity +GO + +DROP SCHEMA IF EXISTS [CH01-01-Dimension]; +GO +CREATE SCHEMA [CH01-01-Dimension]; +GO + +DROP SCHEMA IF EXISTS Fact; +GO +CREATE SCHEMA Fact; +GO + +DROP SCHEMA IF EXISTS Project2; +GO +CREATE SCHEMA Project2 +GO + +DROP SCHEMA IF EXISTS Utils; +GO +CREATE SCHEMA Utils +GO + +DROP SCHEMA IF EXISTS FileUpload; +GO +CREATE SCHEMA FileUpload +GO + +/* Instructions for use of Group1 Schema name: +Part of the design is to create either a view or Inline Table Value function for +the source input query to load the specific table using your group name as a +schema name */ +DROP SCHEMA IF EXISTS Group1; +GO +CREATE SCHEMA Group1 +GO + +DROP SCHEMA IF EXISTS PkSequence; +GO +CREATE SCHEMA PkSequence +GO + +DROP SCHEMA IF EXISTS Process; +GO +CREATE SCHEMA Process +GO + +------------------------- CREATE SEQUENCES ---------------------------- + +-- for replacing identity key in Fact.[Data] +CREATE SEQUENCE PkSequence.[DataSequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO + +-- for replacing identity key in [CH01-01-Dimension].[DimCustomer] +CREATE SEQUENCE PkSequence.[DimCustomerSequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO +-- for replacing identity key in [CH01-01-Dimension].[DimProductCategory] +CREATE SEQUENCE PkSequence.[DimProductCategorySequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO + +-- for replacing identity key in [CH01-01-Dimension].[DimProduct] +CREATE SEQUENCE PkSequence.[DimProductSequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO + +CREATE SEQUENCE PkSequence.[DimProductSubCategorySequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO + +-- for replacing identity key in [CH01-01-Dimension].[DimProductSubCategory] +CREATE SEQUENCE PkSequence.[DimTerritorySequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO + +-- for replacing identity key in [CH01-01-Dimension].[DimOccupation] +CREATE SEQUENCE PkSequence.[OccupationSequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO + +-- for replacing identity key in [CH01-01-Dimension].[SalesManagers] +CREATE SEQUENCE PkSequence.[SalesManagersSequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO + +-- for replacing identity key in DbSecurity.[UserAuthorization] +CREATE SEQUENCE PkSequence.[UserAuthorizationSequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO + +-- for replacing identity key in Process.[WorkflowSteps] +CREATE SEQUENCE PkSequence.[WorkFlowStepsSequenceObject] + AS [int] + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 +GO + + +------------------------ Utils functions using Script as Create --------------------- + + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Professor Heller +-- Create date: default +-- Description: Code taken from the 'Script as Create' result of the scalar-Valued Function within the BIClass db +-- ============================================= +create FUNCTION [Utils].[CalculateDataTypeByteStorage] +( + -- Add the parameters for the function here + @DataType varchar(50) +) +RETURNS int +AS +BEGIN + -- Declare the return variable here + DECLARE @Result int + + -- Return the result of the function + RETURN CASE + WHEN CHARINDEX('(', @DataType, 0) > 0 + AND SUBSTRING(@DataType, 1, 3) = 'var' THEN + CAST(SUBSTRING( + @DataType + , CHARINDEX('(', @DataType, 0) + 1 + , LEN(@DataType) - CHARINDEX('(', @DataType, 0) - 1 + ) AS INT) + 2 + WHEN CHARINDEX('(', @DataType, 0) > 0 + AND SUBSTRING(@DataType, 1, 3) = 'cha' THEN + CAST(SUBSTRING( + @DataType + , CHARINDEX('(', @DataType, 0) + 1 + , LEN(@DataType) - CHARINDEX('(', @DataType, 0) - 1 + ) AS INT) + WHEN SUBSTRING(@DataType, 1, 3) = 'int' THEN + 4 + WHEN SUBSTRING(@DataType, 1, 3) = 'mon' THEN + 4 + WHEN SUBSTRING(@DataType, 1, 3) = 'dat' THEN + 3 + ELSE + -999 + END + +END +GO + + +---------------- recreating Util views using Script as Create --------- + +-- ShowServerUserNameAndCurrentDatabase View + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +create view Utils.[ShowServerUserNameAndCurrentDatabase] +as + select ServerName= @@SERVERNAME + , YourUserName = system_user + , CurrentDatabase = db_name(); + +GO + +-- uvw_FindColumnDefinitionPlusDefaultAndCheckConstraint View + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW [Utils].[uvw_FindColumnDefinitionPlusDefaultAndCheckConstraint] +AS + SELECT CONCAT(tbl.TABLE_SCHEMA, '.', tbl.TABLE_NAME) AS FullyQualifiedTableName , + tbl.TABLE_SCHEMA AS SchemaName , + tbl.TABLE_NAME AS TableName , + col.COLUMN_NAME AS ColumnName , + col.ORDINAL_POSITION AS OrdinalPosition, + CONCAT(col.DOMAIN_SCHEMA, '.', col.DOMAIN_NAME) AS FullyQualifiedDomainName , + col.DOMAIN_NAME AS DomainName , + CASE + WHEN col.DATA_TYPE = 'char' + THEN CONCAT('char(', CHARACTER_MAXIMUM_LENGTH, ')') + WHEN col.DATA_TYPE = 'nchar' + THEN CONCAT('nchar(', CHARACTER_MAXIMUM_LENGTH, ')') + WHEN col.DATA_TYPE = 'Nvarchar' + THEN CONCAT('nvarchar(', CHARACTER_MAXIMUM_LENGTH, ')') + WHEN col.DATA_TYPE = 'varchar' + THEN CONCAT('varchar(', CHARACTER_MAXIMUM_LENGTH, ')') + WHEN col.DATA_TYPE = 'numeric' + THEN CONCAT('numeric(', NUMERIC_PRECISION, ', ', + NUMERIC_SCALE, ')') + WHEN col.DATA_TYPE = 'decimal' + THEN CONCAT('decimal(', NUMERIC_PRECISION, ', ', + NUMERIC_SCALE, ')') + ELSE col.DATA_TYPE + END AS DataType , + col.IS_NULLABLE AS IsNullable, + dcn.DefaultName , + col.COLUMN_DEFAULT AS DefaultNameDefinition , + cc.CONSTRAINT_NAME AS CheckConstraintRuleName, + cc.CHECK_CLAUSE AS CheckConstraintRuleNameDefinition + FROM ( SELECT TABLE_CATALOG , + TABLE_SCHEMA , + TABLE_NAME , + TABLE_TYPE + FROM INFORMATION_SCHEMA.TABLES + ) AS tbl + INNER JOIN ( SELECT TABLE_CATALOG , + TABLE_SCHEMA , + TABLE_NAME , + COLUMN_NAME , + ORDINAL_POSITION , + COLUMN_DEFAULT , + IS_NULLABLE , + DATA_TYPE , + CHARACTER_MAXIMUM_LENGTH , + CHARACTER_OCTET_LENGTH , + NUMERIC_PRECISION , + NUMERIC_PRECISION_RADIX , + NUMERIC_SCALE , + DATETIME_PRECISION , + CHARACTER_SET_CATALOG , + CHARACTER_SET_SCHEMA , + CHARACTER_SET_NAME , + COLLATION_CATALOG , + COLLATION_SCHEMA , + COLLATION_NAME , + DOMAIN_CATALOG , + DOMAIN_SCHEMA , + DOMAIN_NAME + FROM INFORMATION_SCHEMA.COLUMNS + ) AS col ON col.TABLE_CATALOG = tbl.TABLE_CATALOG + AND col.TABLE_SCHEMA = tbl.TABLE_SCHEMA + AND col.TABLE_NAME = tbl.TABLE_NAME + LEFT OUTER JOIN ( SELECT t.name AS TableName , + SCHEMA_NAME(s.schema_id) AS SchemaName , + ac.name AS ColumnName , + d.name AS DefaultName + FROM sys.all_columns AS ac + INNER JOIN sys.tables AS t ON ac.object_id = t.object_id + INNER JOIN sys.schemas AS s ON t.schema_id = s.schema_id + INNER JOIN sys.default_constraints AS d ON ac.default_object_id = d.object_id + ) AS dcn ON dcn.SchemaName = tbl.TABLE_SCHEMA + AND dcn.TableName = tbl.TABLE_NAME + AND dcn.ColumnName = col.COLUMN_NAME + LEFT OUTER JOIN ( SELECT cu.TABLE_CATALOG , + cu.TABLE_SCHEMA , + cu.TABLE_NAME , + cu.COLUMN_NAME , + c.CONSTRAINT_CATALOG , + c.CONSTRAINT_SCHEMA , + c.CONSTRAINT_NAME , + c.CHECK_CLAUSE + FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE + AS cu + INNER JOIN INFORMATION_SCHEMA.CHECK_CONSTRAINTS + AS c ON c.CONSTRAINT_NAME = cu.CONSTRAINT_NAME + ) AS cc ON cc.TABLE_SCHEMA = tbl.TABLE_SCHEMA + AND cc.TABLE_NAME = tbl.TABLE_NAME + AND cc.COLUMN_NAME = col.COLUMN_NAME + + +GO + + +-- uvw_FindTablesStorageBytes View + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +create view [Utils].[uvw_FindTablesStorageBytes] +as + select FullyQualifiedTableName + , ColumnName + , DataType + , OrdinalPosition + , StorageBytes = case + when charindex('(', DataType, 0) > 0 + and substring(DataType, 1, 3) = 'var' then + cast(substring( + DataType + , charindex('(', DataType, 0) + 1 + , len(DataType) - charindex('(', DataType, 0) - 1 + ) as int) + 2 + when charindex('(', DataType, 0) > 0 + and substring(DataType, 1, 3) = 'cha' then + cast(substring( + DataType + , charindex('(', DataType, 0) + 1 + , len(DataType) - charindex('(', DataType, 0) - 1 + ) as int) + when substring(DataType, 1, 3) = 'int' then + 4 + when substring(DataType, 1, 3) = 'mon' then + 4 + when substring(DataType, 1, 3) = 'dat' then + 3 + else + -999 + end + from Utils.uvw_FindColumnDefinitionPlusDefaultAndCheckConstraint + where (SchemaName like 'CH%'); +GO + + + +------------------------- CREATE TABLES --------------------------- + + +-- UserAuthorization Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [DbSecurity].[UserAuthorization] +( + [UserAuthorizationKey] [int] NOT NULL, + [ClassTime] [nchar](5) NOT NULL, + [IndividualProject] [nvarchar](60) NULL, + [GroupMemberLastName] [nvarchar](35) NOT NULL, + [GroupMemberFirstName] [nvarchar](25) NOT NULL, + [GroupName] [nvarchar](20) NOT NULL, + [DateAdded] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [UserAuthorizationKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + + +-- Fact Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE Fact.[Data] +( + [SalesKey] [int] NOT NULL, + [SalesManagerKey] [int] NULL, + [OccupationKey] [int] NULL, + [TerritoryKey] [int] NULL, + [ProductKey] [int] NULL, + [CustomerKey] [int] NULL, + [ProductCategory] [varchar](20) NULL, + [SalesManager] [varchar](20) NULL, + [ProductSubcategory] [varchar](20) NULL, + [ProductCode] [varchar](10) NULL, + [ProductName] [varchar](40) NULL, + [Color] [varchar](10) NULL, + [ModelName] [varchar](30) NULL, + [OrderQuantity] [int] NULL, + [UnitPrice] [money] NULL, + [ProductStandardCost] [money] NULL, + [SalesAmount] [money] NULL, + [OrderDate] [date] NULL, + [MonthName] [varchar](10) NULL, + [MonthNumber] [int] NULL, + [Year] [int] NULL, + [CustomerName] [varchar](30) NULL, + [MaritalStatus] [char](1) NULL, + [Gender] [char](1) NULL, + [Education] [varchar](20) NULL, + [Occupation] [varchar](20) NULL, + [TerritoryRegion] [varchar](20) NULL, + [TerritoryCountry] [varchar](20) NULL, + [TerritoryGroup] [varchar](20) NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [SalesKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW Group1.[uvw_FactData] +AS + SELECT + Saleskey, + SalesManagerKey, + OccupationKey, + TerritoryKey, + ProductKey, + CustomerKey, + ProductCategory, + SalesManager, + ProductSubcategory, + ProductCode, + ProductName, + Color, + ModelName, + OrderQuantity, + UnitPrice, + ProductStandardCost, + SalesAmount, + OrderDate, + [MonthName], + MonthNumber, + [Year], + CustomerName, + MaritalStatus, + Gender, + Education, + Occupation, + TerritoryRegion, + TerritoryCountry, + TerritoryGroup, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate + FROM Fact.[Data] +GO + +-- DimCustomer Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[DimCustomer] +( + [CustomerKey] [int] NOT NULL, + [CustomerName] [varchar](30) NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [CustomerKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE VIEW Group1.[uvw_DimCustomer] +AS + SELECT CustomerKey, CustomerName, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimCustomer] +GO + + +-- DimGender Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[DimGender] +( + [Gender] [char](1) NOT NULL, + [GenderDescription] [varchar](6) NOT NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [Gender] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW Group1.[uvw_DimGender] +AS + SELECT Gender, GenderDescription, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimGender] +GO + + +-- DimMaritalStatus Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[DimMaritalStatus] +( + [MaritalStatus] [char](1) NOT NULL, + [MaritalStatusDescription] [varchar](7) NOT NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [MaritalStatus] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW Group1.[uvw_DimMaritalStatus] +AS + SELECT MaritalStatus, MaritalStatusDescription, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimMaritalStatus] +GO + +-- DimOccupation Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[DimOccupation] +( + [OccupationKey] [int] NOT NULL, + [Occupation] [varchar](20) NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [OccupationKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW Group1.[uvw_DimOccupation] +AS + SELECT OccupationKey, Occupation, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimOccupation] +GO + +-- DimOrderDate Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[DimOrderDate] +( + [OrderDate] [date] NOT NULL, + [MonthName] [varchar](10) NULL, + [MonthNumber] [int] NULL, + [Year] [int] NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [OrderDate] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW Group1.[uvw_DimOrderDate] +AS + SELECT OrderDate, MonthName, MonthNumber, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimOrderDate] +GO + +-- DimProduct Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[DimProduct] +( + [ProductKey] [int] NOT NULL, + [ProductSubcategoryKey] [int] NULL, + [ProductCategory] [varchar](20) NULL, + [ProductSubcategory] [varchar](20) NULL, + [ProductCode] [varchar](10) NULL, + [ProductName] [varchar](40) NULL, + [Color] [varchar](10) NULL, + [ModelName] [varchar](30) NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [ProductKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW Group1.[uvw_DimProduct] +AS + SELECT + ProductKey, + ProductSubcategoryKey, + ProductCategory, + ProductSubcategory, + ProductCode, + ProductName, + Color, + ModelName, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate + FROM [CH01-01-Dimension].[DimProduct] +GO + +-- DimTerritory Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[DimTerritory] +( + [TerritoryKey] [int] NOT NULL, + [TerritoryGroup] [varchar](20) NULL, + [TerritoryCountry] [varchar](20) NULL, + [TerritoryRegion] [varchar](20) NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [TerritoryKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW Group1.[uvw_DimTerritory] +AS + SELECT TerritoryKey, TerritoryGroup, TerritoryCountry, TerritoryRegion, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimTerritory] +GO + +-- SalesManagers Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[SalesManagers] +( + [SalesManagerKey] [int] NOT NULL, + [Category] [varchar](20) NULL, + [SalesManager] [varchar](50) NULL, + [Office] [varchar](50) NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [SalesManagerKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW Group1.[uvw_SalesManagers] +AS + SELECT SalesManagerKey, SalesManager, Category, Office, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[SalesManagers] +GO + +-- 2 additional tables DimProductCategory and DimProductSubCategory + +-- Table 1 +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[DimProductCategory] +( + [ProductCategoryKey] [int] NOT NULL, + [ProductCategory] [varchar](20) NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [ProductCategoryKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE VIEW Group1.[uvw_DimProductCategory] +AS + SELECT ProductCategoryKey, ProductCategory, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimProductCategory] +GO + +-- Table 2 +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [CH01-01-Dimension].[DimProductSubCategory] +( + [ProductSubcategoryKey] [int] NOT NULL, + [ProductCategoryKey] [int] NOT NULL, + [ProductSubcategory] [varchar](20) NULL, + [UserAuthorizationKey] [int] NOT NULL, + [DateAdded] [datetime2](7) NULL, + [DateOfLastUpdate] [datetime2](7) NULL, + PRIMARY KEY CLUSTERED +( + [ProductSubcategoryKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +-- accompanying view -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW Group1.[uvw_DimProductSubCategory] +AS + SELECT ProductSubCategoryKey, ProductCategoryKey, ProductSubcategory, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimProductSubCategory] +GO + + +-- OriginallyLoadedData Table -- + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE FileUpload.[OriginallyLoadedData] +( + [SalesKey] [int] NOT NULL, + [ProductCategory] [varchar](20) NULL, + [ProductSubcategory] [varchar](20) NULL, + [SalesManager] [varchar](20) NULL, + [ProductCode] [varchar](10) NULL, + [ProductName] [varchar](40) NULL, + [Color] [varchar](10) NULL, + [ModelName] [varchar](30) NULL, + [OrderQuantity] [int] NULL, + [UnitPrice] [money] NULL, + [ProductStandardCost] [money] NULL, + [SalesAmount] [money] NULL, + [OrderDate] [date] NULL, + [MonthName] [varchar](10) NULL, + [MonthNumber] [int] NULL, + [Year] [int] NULL, + [CustomerName] [varchar](30) NULL, + [MaritalStatus] [char](1) NULL, + [Gender] [char](1) NULL, + [Education] [varchar](20) NULL, + [Occupation] [varchar](20) NULL, + [TerritoryRegion] [varchar](20) NULL, + [TerritoryCountry] [varchar](20) NULL, + [TerritoryGroup] [varchar](20) NULL +) ON [PRIMARY] +GO + +-- ProductCategories Table + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE FileUpload.[ProductCategories] +( + [ProductCategory] [varchar](20) NOT NULL +) ON [PRIMARY] +GO + +-- ProductSubcategories Table + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE FileUpload.[ProductSubcategories] +( + [ProductSubcategory] [varchar](20) NOT NULL +) ON [PRIMARY] +GO + + +--------------------- Workflow Steps ------------------------- + + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE Process.[WorkflowSteps] +( + [WorkFlowStepKey] [int] NOT NULL, + [WorkFlowStepDescription] [nvarchar](100) NOT NULL, + [WorkFlowStepTableRowCount] [int] NULL, + [StartingDateTime] [datetime2](7) NULL, + [EndingDateTime] [datetime2](7) NULL, + [Class Time] [char](5) NULL, + [UserAuthorizationKey] [int] NOT NULL, + PRIMARY KEY CLUSTERED +( + [WorkFlowStepKey] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + + +--------------------- Alter Tables To Update Defaults/Constraints ------------------- + +ALTER TABLE [CH01-01-Dimension].[DimCustomer] ADD DEFAULT (NEXT VALUE FOR [PkSequence].[DimCustomerSequenceObject]) FOR [CustomerKey] +GO +ALTER TABLE [CH01-01-Dimension].[DimCustomer] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[DimCustomer] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE [CH01-01-Dimension].[DimGender] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[DimGender] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE [CH01-01-Dimension].[DimMaritalStatus] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[DimMaritalStatus] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE [CH01-01-Dimension].[DimOccupation] ADD DEFAULT (NEXT VALUE FOR [PkSequence].[OccupationSequenceObject]) FOR [OccupationKey] +GO +ALTER TABLE [CH01-01-Dimension].[DimOccupation] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[DimOccupation] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE [CH01-01-Dimension].[DimOrderDate] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[DimOrderDate] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE [CH01-01-Dimension].[DimProduct] ADD DEFAULT (NEXT VALUE FOR [PkSequence].[DimProductSequenceObject]) FOR [ProductKey] +GO +ALTER TABLE [CH01-01-Dimension].[DimProduct] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[DimProduct] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE [CH01-01-Dimension].[DimProductCategory] ADD DEFAULT (NEXT VALUE FOR [PkSequence].[DimProductCategorySequenceObject]) FOR [ProductCategoryKey] +GO +ALTER TABLE [CH01-01-Dimension].[DimProductCategory] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[DimProductCategory] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] ADD DEFAULT (NEXT VALUE FOR [PkSequence].[DimProductSubCategorySequenceObject]) FOR [ProductSubcategoryKey] +GO +ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE [CH01-01-Dimension].[DimTerritory] ADD DEFAULT (NEXT VALUE FOR [PkSequence].[DimTerritorySequenceObject]) FOR [TerritoryKey] +GO +ALTER TABLE [CH01-01-Dimension].[DimTerritory] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[DimTerritory] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE [CH01-01-Dimension].[SalesManagers] ADD DEFAULT (NEXT VALUE FOR [PkSequence].[SalesManagersSequenceObject]) FOR [SalesManagerKey] +GO +ALTER TABLE [CH01-01-Dimension].[SalesManagers] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE [CH01-01-Dimension].[SalesManagers] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE Fact.[Data] ADD DEFAULT (NEXT VALUE FOR PkSequence.[DataSequenceObject]) FOR [SalesKey] +GO +ALTER TABLE Fact.[Data] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE Fact.[Data] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +GO +ALTER TABLE DbSecurity.[UserAuthorization] ADD DEFAULT (NEXT VALUE FOR PkSequence.[UserAuthorizationSequenceObject]) FOR [UserAuthorizationKey] +GO +ALTER TABLE DbSecurity.[UserAuthorization] ADD DEFAULT ('9:15') FOR [ClassTime] +GO +ALTER TABLE DbSecurity.[UserAuthorization] ADD DEFAULT ('PROJECT 2 RECREATE THE BICLASS DATABASE STAR SCHEMA') FOR [IndividualProject] +GO +ALTER TABLE DbSecurity.[UserAuthorization] ADD DEFAULT ('GROUP 1') FOR [GroupName] +GO +ALTER TABLE DbSecurity.[UserAuthorization] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +GO +ALTER TABLE Process.[WorkflowSteps] ADD DEFAULT (NEXT VALUE FOR PkSequence.[WorkFlowStepsSequenceObject]) FOR [WorkFlowStepKey] +GO +ALTER TABLE Process.[WorkflowSteps] ADD DEFAULT ((0)) FOR [WorkFlowStepTableRowCount] +GO +ALTER TABLE Process.[WorkflowSteps] ADD DEFAULT (sysdatetime()) FOR [StartingDateTime] +GO +ALTER TABLE Process.[WorkflowSteps] ADD DEFAULT (sysdatetime()) FOR [EndingDateTime] +GO +ALTER TABLE Process.[WorkflowSteps] ADD DEFAULT ('9:15') FOR [Class Time] +GO +ALTER TABLE [CH01-01-Dimension].[DimCustomer] WITH CHECK ADD CONSTRAINT [FK_DimCustomer_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimCustomer] CHECK CONSTRAINT [FK_DimCustomer_UserAuthorization] +GO +ALTER TABLE [CH01-01-Dimension].[DimGender] WITH CHECK ADD CONSTRAINT [FK_DimGender_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimGender] CHECK CONSTRAINT [FK_DimGender_UserAuthorization] +GO +ALTER TABLE [CH01-01-Dimension].[DimMaritalStatus] WITH CHECK ADD CONSTRAINT [FK_DimMaritalStatus_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimMaritalStatus] CHECK CONSTRAINT [FK_DimMaritalStatus_UserAuthorization] +GO +ALTER TABLE [CH01-01-Dimension].[DimOccupation] WITH CHECK ADD CONSTRAINT [FK_DimOccupation_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimOccupation] CHECK CONSTRAINT [FK_DimOccupation_UserAuthorization] +GO +ALTER TABLE [CH01-01-Dimension].[DimOrderDate] WITH CHECK ADD CONSTRAINT [FK_DimOrderDate_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimOrderDate] CHECK CONSTRAINT [FK_DimOrderDate_UserAuthorization] +GO +ALTER TABLE [CH01-01-Dimension].[DimProduct] WITH CHECK ADD CONSTRAINT [FK_DimProduct_DimProductSubCategory] FOREIGN KEY([ProductSubcategoryKey]) +REFERENCES [CH01-01-Dimension].[DimProductSubCategory] ([ProductSubcategoryKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimProduct] CHECK CONSTRAINT [FK_DimProduct_DimProductSubCategory] +GO +ALTER TABLE [CH01-01-Dimension].[DimProduct] WITH CHECK ADD CONSTRAINT [FK_DimProduct_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimProduct] CHECK CONSTRAINT [FK_DimProduct_UserAuthorization] +GO +ALTER TABLE [CH01-01-Dimension].[DimProductCategory] WITH CHECK ADD CONSTRAINT [FK_DimProductCategory_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimProductCategory] CHECK CONSTRAINT [FK_DimProductCategory_UserAuthorization] +GO +ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] WITH CHECK ADD CONSTRAINT [FK_DimProductSubCategory_DimProductCategory] FOREIGN KEY([ProductCategoryKey]) +REFERENCES [CH01-01-Dimension].[DimProductCategory] ([ProductCategoryKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] CHECK CONSTRAINT [FK_DimProductSubCategory_DimProductCategory] +GO +ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] WITH CHECK ADD CONSTRAINT [FK_DimProductSubCategory_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] CHECK CONSTRAINT [FK_DimProductSubCategory_UserAuthorization] +GO +ALTER TABLE [CH01-01-Dimension].[DimTerritory] WITH CHECK ADD CONSTRAINT [FK_DimTerritory_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[DimTerritory] CHECK CONSTRAINT [FK_DimTerritory_UserAuthorization] +GO +ALTER TABLE [CH01-01-Dimension].[SalesManagers] WITH CHECK ADD CONSTRAINT [FK_SalesManagers_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE [CH01-01-Dimension].[SalesManagers] CHECK CONSTRAINT [FK_SalesManagers_UserAuthorization] +GO +ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimCustomer] FOREIGN KEY([CustomerKey]) +REFERENCES [CH01-01-Dimension].[DimCustomer] ([CustomerKey]) +GO +ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimCustomer] +GO +ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimGender] FOREIGN KEY([Gender]) +REFERENCES [CH01-01-Dimension].[DimGender] ([Gender]) +GO +ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimGender] +GO +ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimMaritalStatus] FOREIGN KEY([MaritalStatus]) +REFERENCES [CH01-01-Dimension].[DimMaritalStatus] ([MaritalStatus]) +GO +ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimMaritalStatus] +GO +ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimOccupation] FOREIGN KEY([OccupationKey]) +REFERENCES [CH01-01-Dimension].[DimOccupation] ([OccupationKey]) +GO +ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimOccupation] +GO +ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimOrderDate] FOREIGN KEY([OrderDate]) +REFERENCES [CH01-01-Dimension].[DimOrderDate] ([OrderDate]) +GO +ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimOrderDate] +GO +ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimProduct] FOREIGN KEY([ProductKey]) +REFERENCES [CH01-01-Dimension].[DimProduct] ([ProductKey]) +GO +ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimProduct] +GO +ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimTerritory] FOREIGN KEY([TerritoryKey]) +REFERENCES [CH01-01-Dimension].[DimTerritory] ([TerritoryKey]) +GO +ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimTerritory] +GO +ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_SalesManagers] FOREIGN KEY([SalesManagerKey]) +REFERENCES [CH01-01-Dimension].[SalesManagers] ([SalesManagerKey]) +GO +ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_SalesManagers] +GO +ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_UserAuthorization] +GO +ALTER TABLE Process.[WorkflowSteps] WITH CHECK ADD CONSTRAINT [FK_WorkFlowSteps_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +REFERENCES DbSecurity.[UserAuthorization] ([UserAuthorizationKey]) +GO +ALTER TABLE Process.[WorkflowSteps] CHECK CONSTRAINT [FK_WorkFlowSteps_UserAuthorization] +GO + + +-------------- Create Stored Procedures -------------- + +-- ShowWorkflowSteps + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Aleksandra Georgievska +-- Create date: 11/13/23 +-- Description: Show table of all workflow steps +-- ============================================= +CREATE PROCEDURE Process.[usp_ShowWorkflowSteps] +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + SELECT * + FROM Process.[WorkFlowSteps]; +END +GO + +-- TrackWorkFlow + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Aleksandra Georgievska +-- Create date: 11/13/23 +-- Description: Keep track of all workflow steps +-- ============================================= +CREATE PROCEDURE Process.[usp_TrackWorkFlow] + -- Add the parameters for the stored procedure here + @WorkflowDescription NVARCHAR(100), + @WorkFlowStepTableRowCount INT, + @StartingDateTime DATETIME2, + @EndingDateTime DATETIME2, + @UserAuthorizationKey INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here + INSERT INTO Process.[WorkflowSteps] + ( + WorkFlowStepDescription, + WorkFlowStepTableRowCount, + StartingDateTime, + EndingDateTime, + [Class Time], + UserAuthorizationKey + ) + VALUES + (@WorkflowDescription, @WorkFlowStepTableRowCount, @StartingDateTime, @EndingDateTime, '9:15', + @UserAuthorizationKey); + +END; +GO + + +-- AddForeignKeysToStarSchemaData + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Aleksandra Georgievska +-- Create date: 11/13/23 +-- Description: Add the foreign keys to the start Schema database +-- ============================================= +CREATE PROCEDURE [Project2].[AddForeignKeysToStarSchemaData] + @UserAuthorizationKey INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + DECLARE @StartingDateTime DATETIME2 = SYSDATETIME(); + + ALTER TABLE Fact.[Data] + ADD CONSTRAINT FK_Data_DimCustomer + FOREIGN KEY (CustomerKey) + REFERENCES [CH01-01-Dimension].DimCustomer (CustomerKey); + ALTER TABLE Fact.[Data] + ADD CONSTRAINT FK_Data_DimGender + FOREIGN KEY (Gender) + REFERENCES [CH01-01-Dimension].DimGender (Gender); + ALTER TABLE Fact.[Data] + ADD CONSTRAINT FK_Data_DimMaritalStatus + FOREIGN KEY (MaritalStatus) + REFERENCES [CH01-01-Dimension].DimMaritalStatus (MaritalStatus); + ALTER TABLE Fact.[Data] + ADD CONSTRAINT FK_Data_DimOccupation + FOREIGN KEY (OccupationKey) + REFERENCES [CH01-01-Dimension].DimOccupation (OccupationKey); + ALTER TABLE Fact.[Data] + ADD CONSTRAINT FK_Data_DimOrderDate + FOREIGN KEY (OrderDate) + REFERENCES [CH01-01-Dimension].DimOrderDate (OrderDate); + ALTER TABLE Fact.[Data] + ADD CONSTRAINT FK_Data_DimProduct + FOREIGN KEY (ProductKey) + REFERENCES [CH01-01-Dimension].DimProduct (ProductKey); + ALTER TABLE Fact.[Data] + ADD CONSTRAINT FK_Data_DimTerritory + FOREIGN KEY (TerritoryKey) + REFERENCES [CH01-01-Dimension].DimTerritory (TerritoryKey); + ALTER TABLE Fact.[Data] + ADD CONSTRAINT FK_Data_SalesManagers + FOREIGN KEY (SalesManagerKey) + REFERENCES [CH01-01-Dimension].SalesManagers (SalesManagerKey); + ALTER TABLE [CH01-01-Dimension].[DimProduct] + ADD CONSTRAINT FK_DimProduct_DimProductSubCategory + FOREIGN KEY (ProductSubcategoryKey) + REFERENCES [CH01-01-Dimension].DimProductSubCategory (ProductSubCategoryKey); + ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] + ADD CONSTRAINT FK_DimProductSubCategory_DimProductCategory + FOREIGN KEY (ProductCategoryKey) + REFERENCES [CH01-01-Dimension].DimProductCategory (ProductCategoryKey); + ALTER TABLE [CH01-01-Dimension].DimCustomer + ADD CONSTRAINT FK_DimCustomer_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE [CH01-01-Dimension].DimGender + ADD CONSTRAINT FK_DimGender_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE [CH01-01-Dimension].DimMaritalStatus + ADD CONSTRAINT FK_DimMaritalStatus_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE [CH01-01-Dimension].DimOccupation + ADD CONSTRAINT FK_DimOccupation_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE [CH01-01-Dimension].DimOrderDate + ADD CONSTRAINT FK_DimOrderDate_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE [CH01-01-Dimension].DimProduct + ADD CONSTRAINT FK_DimProduct_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE [CH01-01-Dimension].DimProductCategory + ADD CONSTRAINT FK_DimProductCategory_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE [CH01-01-Dimension].DimProductSubCategory + ADD CONSTRAINT FK_DimProductSubCategory_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE [CH01-01-Dimension].DimTerritory + ADD CONSTRAINT FK_DimTerritory_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE [CH01-01-Dimension].SalesManagers + ADD CONSTRAINT FK_SalesManagers_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE Fact.Data + ADD CONSTRAINT FK_Data_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + ALTER TABLE Process.[WorkflowSteps] + ADD CONSTRAINT FK_WorkFlowSteps_UserAuthorization + FOREIGN KEY (UserAuthorizationKey) + REFERENCES DbSecurity.UserAuthorization (UserAuthorizationKey); + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = 0; + DECLARE @EndingDateTime DATETIME2 = SYSDATETIME(); + EXEC Process.[usp_TrackWorkFlow] 'Add Foreign Keys', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; +END; +GO + +-- DropForeignKeysFromStarSchemaData + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Aleksandra Georgievska +-- Create date: 11/13/23 +-- Description: Drop the foreign keys from the start Schema database +-- ============================================= +CREATE PROCEDURE [Project2].[DropForeignKeysFromStarSchemaData] + @UserAuthorizationKey INT +AS +BEGIN + SET NOCOUNT ON; + DECLARE @StartingDateTime DATETIME2 = SYSDATETIME(); + + ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimCustomer; + ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimGender; + ALTER TABLE Fact.[Data] + DROP CONSTRAINT FK_Data_DimMaritalStatus; + ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimOccupation; + ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimOrderDate; + ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimProduct; + ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimTerritory; + ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_SalesManagers; + ALTER TABLE [CH01-01-Dimension].[DimProduct] + DROP CONSTRAINT FK_DimProduct_DimProductSubCategory; + ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] + DROP CONSTRAINT FK_DimProductSubCategory_DimProductCategory; + ALTER TABLE [CH01-01-Dimension].DimCustomer + DROP CONSTRAINT FK_DimCustomer_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimGender + DROP CONSTRAINT FK_DimGender_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimMaritalStatus + DROP CONSTRAINT FK_DimMaritalStatus_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimOccupation + DROP CONSTRAINT FK_DimOccupation_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimOrderDate + DROP CONSTRAINT FK_DimOrderDate_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimProduct + DROP CONSTRAINT FK_DimProduct_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimProductCategory + DROP CONSTRAINT FK_DimProductCategory_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimProductSubCategory + DROP CONSTRAINT FK_DimProductSubCategory_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimTerritory + DROP CONSTRAINT FK_DimTerritory_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].SalesManagers + DROP CONSTRAINT FK_SalesManagers_UserAuthorization; + ALTER TABLE Fact.Data DROP CONSTRAINT FK_Data_UserAuthorization; + ALTER TABLE Process.[WorkflowSteps] + DROP CONSTRAINT FK_WorkFlowSteps_UserAuthorization; + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = 0; + DECLARE @EndingDateTime DATETIME2 = SYSDATETIME(); + EXEC Process.[usp_TrackWorkFlow] 'Drop Foreign Keys', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; +END; +GO + + +--- Load_Data Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Sigalita Yakubova +-- Create date: 11/13/23 +-- Description: Fill in the data table +-- ============================================= +-- DROP PROC IF EXISTS Project2.[Load_Data] +-- GO + +CREATE PROCEDURE Project2.[Load_Data] + @UserAuthorizationKey INT +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [9:15_Group1].[Fact].[Data] + ( + SalesKey, + SalesManagerKey, + OccupationKey, + TerritoryKey, + ProductKey, + CustomerKey, + ProductCategory, + SalesManager, + ProductSubcategory, + ProductCode, + ProductName, + Color, + ModelName, + OrderQuantity, + UnitPrice, + ProductStandardCost, + SalesAmount, + OrderDate, + [MonthName], + MonthNumber, + [Year], + CustomerName, + MaritalStatus, + Gender, + Education, + Occupation, + TerritoryRegion, + TerritoryCountry, + TerritoryGroup, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate + ) + SELECT DISTINCT + OLD.Saleskey, + sm.SalesManagerKey, + do.OccupationKey, + dt.TerritoryKey, + dp.ProductKey, + dc.CustomerKey, + OLD.ProductCategory, + OLD.SalesManager, + OLD.ProductSubcategory, + OLD.ProductCode, + OLD.ProductName, + OLD.Color, + OLD.ModelName, + OLD.OrderQuantity, + OLD.UnitPrice, + OLD.ProductStandardCost, + OLD.SalesAmount, + OLD.OrderDate, + OLD.[MonthName], + OLD.MonthNumber, + OLD.[Year], + OLD.CustomerName, + OLD.MaritalStatus, + OLD.Gender, + OLD.Education, + OLD.Occupation, + OLD.TerritoryRegion, + OLD.TerritoryCountry, + OLD.TerritoryGroup, + @UserAuthorizationKey, + @DateAdded, + @DateOfLastUpdate + FROM + [FileUpload].[OriginallyLoadedData] AS OLD LEFT JOIN + [CH01-01-Dimension].DimProduct AS dp + on dp.ProductName = OLD.ProductName AND + dp.ProductCode = OLD.ProductCode LEFT JOIN + [CH01-01-Dimension].DimTerritory AS dt + on dt.TerritoryCountry = OLD.TerritoryCountry AND + dt.TerritoryGroup = OLD.TerritoryGroup AND + dt.TerritoryRegion = OLD.TerritoryRegion INNER JOIN + [CH01-01-Dimension].DimCustomer AS dc + on dc.CustomerName = OLD.CustomerName LEFT JOIN + [CH01-01-Dimension].SalesManagers AS sm + on sm.SalesManager = OLD.SalesManager and + sm.Category = OLD.ProductSubcategory LEFT JOIN + [CH01-01-Dimension].DimOccupation AS do + on do.Occupation = OLD.Occupation + + --- accompanying view --- + EXEC ('DROP VIEW IF EXISTS Group1.uvw_FactData'); + EXEC ('CREATE VIEW Group1.uvw_FactData AS + SELECT + Saleskey, + SalesManagerKey, + OccupationKey, + TerritoryKey, + ProductKey, + CustomerKey, + ProductCategory, + SalesManager, + ProductSubcategory, + ProductCode, + ProductName, + Color, + ModelName, + OrderQuantity, + UnitPrice, + ProductStandardCost, + SalesAmount, + OrderDate, + [MonthName], + MonthNumber, + [Year], + CustomerName, + MaritalStatus, + Gender, + Education, + Occupation, + TerritoryRegion, + TerritoryCountry, + TerritoryGroup, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate + FROM Fact.[Data]'); + + + DECLARE @EndingDateTime DATETIME2; + SET @EndingDateTime = SYSDATETIME(); + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) + FROM Fact.[Data]); + + EXEC Process.[usp_TrackWorkFlow] 'Procedure: Project2.[Load_Data] loads data into Fact.[Data]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; + + + SELECT * + FROM Group1.uvw_FactData; + +END; +GO + +-- Load_DimProductCategory Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Sigalita Yakubova +-- Create date: 11/13/23 +-- Description: Fill in the product category table +-- ============================================= +CREATE PROCEDURE Project2.[Load_DimProductCategory] + @UserAuthorizationKey INT +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].[DimProductCategory] + ( + ProductCategory, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate + ) + SELECT DISTINCT + FileUpload.OriginallyLoadedData.[ProductCategory], + @UserAuthorizationKey, + @DateAdded, + @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData; + + --- accompanying view --- + EXEC ('DROP VIEW IF EXISTS Group1.uvw_DimProductCategory'); + EXEC ('CREATE VIEW Group1.uvw_DimProductCategory AS + SELECT ProductCategoryKey, ProductCategory, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimProductCategory] '); + + DECLARE @EndingDateTime DATETIME2; + SET @EndingDateTime = SYSDATETIME(); + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = + ( + SELECT COUNT(*) + FROM [CH01-01-Dimension].DimProductCategory + ); + + EXEC Process.[usp_TrackWorkFlow] 'Procedure: Project2.[Load_DimProductCategory] loads data into [CH01-01-Dimension].[DimProductCategory]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; + + SELECT * + FROM Group1.uvw_DimProductCategory; +END; +GO + + +-- Load_DimProductSubcategory Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Sigalita Yakubova +-- Create date: 11/13/23 +-- Description: Fill in the product SUBcategory table +-- ============================================= +CREATE PROCEDURE Project2.[Load_DimProductSubcategory] + @UserAuthorizationKey INT +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].[DimProductSubCategory] + ( + ProductCategoryKey, + ProductSubcategory, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate + ) + SELECT DISTINCT + DPC.ProductCategoryKey, + OLD.ProductSubcategory, + @UserAuthorizationKey, + @DateAdded, + @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData AS OLD + FULL JOIN [CH01-01-Dimension].[DimProductCategory] AS DPC + ON OLD.[ProductCategory] = DPC.[ProductCategory]; + + --- accompanying view --- + EXEC ('DROP VIEW IF EXISTS Group1.uvw_DimProductSubCategory'); + EXEC ('CREATE VIEW Group1.uvw_DimProductSubCategory AS + SELECT ProductSubCategoryKey, ProductCategoryKey, ProductSubcategory, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimProductSubCategory] '); + + DECLARE @EndingDateTime DATETIME2; + SET @EndingDateTime = SYSDATETIME(); + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = + ( + SELECT COUNT(*) + FROM [CH01-01-Dimension].DimProductSubCategory + ); + + EXEC Process.[usp_TrackWorkFlow] 'Procedure: Project2.[Load_DimProductSubCategory] loads data into [CH01-01-Dimension].[DimProductSubCategory]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; + + SELECT * + FROM Group1.uvw_DimProductSubCategory; + +END; +GO + +-- Load_DimCustomer Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Nicholas Kong +-- Create date: 11/13/2023 +-- Description: Populate the customer table +-- ============================================= +CREATE PROCEDURE Project2.[Load_DimCustomer] + @UserAuthorizationKey INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].[DimCustomer] + ( + CustomerName, UserAuthorizationKey, DateAdded, DateOfLastUpdate) + SELECT DISTINCT CustomerName, @UserAuthorizationKey, @DateAdded, @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData + + + --- accompanying view --- + EXEC('DROP VIEW IF EXISTS Group1.uvw_DimCustomer') + EXEC('CREATE VIEW Group1.uvw_DimCustomer AS + SELECT CustomerKey, CustomerName, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimCustomer]') + + DECLARE @EndingDateTime DATETIME2; + set @EndingDateTime = SYSDATETIME() + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) + FROM [CH01-01-Dimension].DimCustomer); + + EXEC Process.[usp_TrackWorkFlow] + 'Procedure: Project2.[Load_DimCustomer] loads data into [CH01-01-Dimension].[DimCustomer]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey + + EXEC('SELECT * FROM Group1.uvw_DimCustomer') +END +GO + +-- Load_DimGender Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Nicholas Kong +-- Create date: 11/13/2023 +-- Description: Populate the gender table +-- ============================================= +CREATE PROCEDURE Project2.[Load_DimGender] + @UserAuthorizationKey INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].[DimGender] + (Gender, GenderDescription, UserAuthorizationKey, DateAdded, DateOfLastUpdate) + SELECT DISTINCT Gender, CASE Gender WHEN 'M' THEN 'Male' ELSE 'Female' END AS GenderDescription, @UserAuthorizationKey, @DateAdded, @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData + + + --- accompanying view --- + EXEC('DROP VIEW IF EXISTS Group1.uvw_DimGender') + EXEC('CREATE VIEW Group1.uvw_DimGender AS + SELECT Gender, GenderDescription, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimGender]') + + DECLARE @EndingDateTime DATETIME2; + set @EndingDateTime = SYSDATETIME() + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) + FROM [CH01-01-Dimension].DimGender); + + EXEC Process.[usp_TrackWorkFlow] + 'Procedure: Project2.[Load_DimGender]loads data into [CH01-01-Dimension].[DimGender]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey + + EXEC('SELECT * FROM Group1.uvw_DimGender') +END; +GO + +-- TruncateStarSchemaData Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Nicholas Kong +-- Create date: 11/13/2023 +-- Description: Truncate the star schema +-- ============================================= +CREATE PROCEDURE Project2.[TruncateStarSchemaData] + @UserAuthorizationKey int + +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + DECLARE @StartingDateTime DATETIME2 = SYSDATETIME(); + + TRUNCATE TABLE [CH01-01-Dimension].DimCustomer; + ALTER SEQUENCE PkSequence.DimCustomerSequenceObject RESTART WITH 1; + TRUNCATE TABLE [CH01-01-Dimension].DimGender; + TRUNCATE TABLE [CH01-01-Dimension].DimMaritalStatus; + TRUNCATE TABLE [CH01-01-Dimension].DimOccupation; + ALTER SEQUENCE PkSequence.OccupationSequenceObject RESTART WITH 1; + TRUNCATE TABLE [CH01-01-Dimension].DimOrderDate; + TRUNCATE TABLE [CH01-01-Dimension].DimProduct; + ALTER SEQUENCE PkSequence.DimProductSequenceObject RESTART WITH 1; + TRUNCATE TABLE [CH01-01-Dimension].DimProductCategory; + ALTER SEQUENCE PkSequence.DimProductCategorySequenceObject RESTART WITH 1; + TRUNCATE TABLE [CH01-01-Dimension].DimProductSubCategory; + ALTER SEQUENCE PkSequence.DimProductSubCategorySequenceObject RESTART WITH 1; + TRUNCATE TABLE [CH01-01-Dimension].DimTerritory; + ALTER SEQUENCE PkSequence.DimTerritorySequenceObject RESTART WITH 1; + TRUNCATE TABLE [CH01-01-Dimension].SalesManagers; + ALTER SEQUENCE PkSequence.SalesManagersSequenceObject RESTART WITH 1; + TRUNCATE TABLE Fact.Data; + ALTER SEQUENCE PkSequence.DataSequenceObject RESTART WITH 1; + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = 0; + DECLARE @EndingDateTime DATETIME2 = SYSDATETIME(); + EXEC Process.[usp_TrackWorkFlow] 'Truncate Data', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; +END +GO + + + +-- Load_DimMaritalStatus Procedure + + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +-- ============================================= +-- Author: Edwin Wray +-- Create date: 11/13/2023 +-- Description: Populate the marital status table +-- ============================================= + +CREATE PROCEDURE Project2.[Load_DimMaritalStatus] + @UserAuthorizationKey INT +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].[DimMaritalStatus] + ( + MaritalStatus, + MaritalStatusDescription, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate + ) + SELECT DISTINCT + MaritalStatus, + CASE + WHEN OLD.MaritalStatus = 'M' THEN + 'Married' + ELSE + 'Single' + END AS MaritalStatusDescription, + @UserAuthorizationKey, + @DateAdded, + @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData AS OLD; + + + EXEC ('DROP VIEW IF EXISTS Group1.uvw_DimMaritalStatus'); + EXEC ('CREATE VIEW Group1.uvw_DimMaritalStatus AS + SELECT MaritalStatus, MaritalStatusDescription, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimMaritalStatus]'); + + --- accompanying view --- + DECLARE @EndingDateTime DATETIME2; + SET @EndingDateTime = SYSDATETIME(); + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) + FROM [CH01-01-Dimension].DimMaritalStatus); + + EXEC Process.[usp_TrackWorkFlow] 'Procedure: Project2.[Load_MaritalStatus] loads data into [CH01-01-Dimension].[DimMaritalStatus]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; + SELECT * + FROM Group1.uvw_DimMaritalStatus; +END; +GO + +-- Load_DimOccupation Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +-- ============================================= +-- Author: Edwin Wray +-- Create date: 11/13/2023 +-- Description: Populate the occupation table +-- ============================================= + +CREATE PROCEDURE Project2.[Load_DimOccupation] + @UserAuthorizationKey INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].[DimOccupation] + (Occupation,UserAuthorizationKey,DateAdded,DateOfLastUpdate) + SELECT DISTINCT FileUpload.OriginallyLoadedData.[Occupation], @UserAuthorizationKey, @DateAdded, @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData + + + --- accompanying view --- + EXEC('DROP VIEW IF EXISTS Group1.uvw_DimOccupation') + EXEC('CREATE VIEW Group1.uvw_DimOccupation AS + SELECT OccupationKey,Occupation,UserAuthorizationKey,DateAdded,DateOfLastUpdate + FROM [CH01-01-Dimension].[DimOccupation]') + + + DECLARE @EndingDateTime DATETIME2; + set @EndingDateTime = SYSDATETIME() + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) + FROM [CH01-01-Dimension].DimOccupation); + + EXEC Process.[usp_TrackWorkFlow] + 'Procedure: Project2.[Load_DimOccupation] loads data into [CH01-01-Dimension].[DimOccupation]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey + + SELECT * + FROM Group1.uvw_DimOccupation +END +GO + +-- Load_DimTerritory Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +-- ============================================= +-- Author: Edwin Wray +-- Create date: 11/13/2023 +-- Description: Populate the Territory table +-- ============================================= + +CREATE PROCEDURE Project2.[Load_DimTerritory] + @UserAuthorizationKey int + +AS +BEGIN + SET NOCOUNT ON + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].DimTerritory + ([TerritoryRegion], + [TerritoryCountry], + [TerritoryGroup], + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate) + + SELECT DISTINCT OLD.[TerritoryRegion], + OLD.[TerritoryCountry], + OLD.[TerritoryGroup], + @UserAuthorizationKey, + @DateAdded, + @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData AS OLD + + DECLARE @EndingDateTime DATETIME2; + set @EndingDateTime = SYSDATETIME() + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) + FROM [CH01-01-Dimension].DimTerritory); + + EXEC('DROP VIEW IF EXISTS Group1.uvw_DimTerritory') + EXEC('CREATE VIEW Group1.uvw_DimTerritory AS + SELECT TerritoryKey, TerritoryGroup, TerritoryCountry, TerritoryRegion, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimTerritory] ') + + EXEC Process.[usp_TrackWorkFlow] + 'Procedure: Project2.[Load_DimTerritory] loads data into [CH01-01-Dimension].[DimTerritory]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey + + SELECT * + FROM Group1.uvw_DimTerritory +END +GO + + +-- Load_DimOrderDate Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +-- ============================================= +-- Author: Ahnaf +-- Create date: 11/13/2023 +-- Description: Load the order date information into the table +-- ============================================= +CREATE PROCEDURE Project2.[Load_DimOrderDate] + @UserAuthorizationKey INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].[DimOrderDate] + ([OrderDate], + [MonthName], + MonthNumber, + [Year], + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate) + + SELECT DISTINCT A.[OrderDate], + A.[MonthName], + A.MonthNumber, + A.[Year], + @UserAuthorizationKey, + @DateAdded, + @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData as A + + --- accompanying view --- + EXEC('DROP VIEW IF EXISTS Group1.uvw_DimOrderDate') + EXEC('CREATE VIEW Group1.uvw_DimOrderDate AS + SELECT OrderDate, MonthName, MonthNumber, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[DimOrderDate]') + + DECLARE @EndingDateTime DATETIME2; + set @EndingDateTime = SYSDATETIME() + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) + FROM [CH01-01-Dimension].DimOrderDate); + + EXEC Process.[usp_TrackWorkFlow] + 'Procedure: Project2.[Load_DimOrderDate] loads data into [CH01-01-Dimension].[DimOrderDate]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey + + SELECT * + FROM Group1.uvw_DimOrderDate +END +GO + + +-- Load_SalesManagers Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + +-- ============================================= +-- Author: Ahnaf +-- Create date: 11/13/2023 +-- Description: Load the Sales Manager information into the table +-- ============================================= + +CREATE PROCEDURE Project2.[Load_SalesManagers] + @UserAuthorizationKey int + +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].[SalesManagers] + (SalesManager, + Category, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate) + + SELECT DISTINCT OLD.[SalesManager], + OLD.[ProductSubcategory], + @UserAuthorizationKey, + @DateAdded, + @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData AS OLD + + --- accompanying view --- + EXEC('DROP VIEW IF EXISTS Group1.uvw_SalesManagers') + EXEC('CREATE VIEW Group1.uvw_SalesManagers AS + SELECT SalesManagerKey, SalesManager, Category, Office, UserAuthorizationKey, DateAdded, DateOfLastUpdate + FROM [CH01-01-Dimension].[SalesManagers] ') + + DECLARE @EndingDateTime DATETIME2; + set @EndingDateTime = SYSDATETIME() + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) + FROM [CH01-01-Dimension].SalesManagers); + + EXEC Process.[usp_TrackWorkFlow] + 'Procedure: Project2.[Load_SalesManagers] loads data into [CH01-01-Dimension].[SalesManagers]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey + + SELECT * + FROM Group1.uvw_SalesManagers +END; +GO + + +-- DropProcsInCSCI331FinalProject Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Ahnaf +-- Create date: 11/13/2023 +-- Description: Run the DropProcsInCSCI331FinalProject procedure +-- ============================================= +CREATE procedure Utils.[DropProcsInCSCI331FinalProject] @UserAuthorizationKey INT +AS +BEGIN + SET NOCOUNT ON; + DECLARE @StartingDateTime DATETIME2 = SYSDATETIME(); + + DROP PROC IF EXISTS Project2.Load_SalesManagers; + DROP PROC IF EXISTS Project2.Load_DimProductSubcategory; + DROP PROC IF EXISTS Project2.Load_DimProductCategory; + DROP PROC IF EXISTS Project2.Load_DimGender; + DROP PROC IF EXISTS Project2.Load_DimMaritalStatus; + DROP PROC IF EXISTS Project2.Load_DimOccupation; + DROP PROC IF EXISTS Project2.Load_DimOrderDate; + DROP PROC IF EXISTS Project2.Load_DimTerritory; + DROP PROC IF EXISTS Project2.Load_DimProduct; + DROP PROC IF EXISTS Project2.Load_DimCustomer; + DROP PROC IF EXISTS Project2.Load_Data; + DROP PROC IF EXISTS Project2.TruncateStarSchemaData; + DROP PROC IF EXISTS Project2.LoadStarSchemaData; + DROP PROC IF EXISTS Project2.AddForeignKeysToStarSchemaData; + DROP PROC IF EXISTS Project2.DropForeignKeysFromStarSchemaData; + DROP PROC IF EXISTS Project2.ShowTableStatusRowCount; + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = 0; + DECLARE @EndingDateTime DATETIME2 = SYSDATETIME(); + EXEC Process.[usp_TrackWorkFlow] 'Drop Procedures', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; + + DROP PROC IF EXISTS Process.usp_TrackWorkFlow; +END; +GO + + +--- Load_DimProduct Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Aryeh Richman +-- Create date: 11/13/23 +-- Description: Populate the product table +-- ============================================= +CREATE PROCEDURE Project2.[Load_DimProduct] + @UserAuthorizationKey INT +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + INSERT INTO [CH01-01-Dimension].[DimProduct] + ( + ProductSubcategoryKey, + ProductCategory, + ProductSubcategory, + ProductCode, + ProductName, + Color, + ModelName, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate + ) + SELECT DISTINCT + DPSC.ProductSubcategoryKey, + OLD.ProductCategory, + DPSC.ProductSubcategory, + OLD.ProductCode, + OLD.ProductName, + OLD.Color, + OLD.ModelName, + @UserAuthorizationKey, + @DateAdded, + @DateOfLastUpdate + FROM FileUpload.OriginallyLoadedData AS OLD + FULL JOIN [CH01-01-Dimension].[DimProductSubCategory] AS DPSC + ON OLD.[ProductSubcategory] = DPSC.[ProductSubcategory]; + + --- accompanying view --- + EXEC ('DROP VIEW IF EXISTS Group1.uvw_DimProduct'); + EXEC ('CREATE VIEW Group1.uvw_DimProduct AS + SELECT + ProductKey, + ProductSubcategoryKey, + ProductCategory, + ProductSubcategory, + ProductCode, + ProductName, + Color, + ModelName, + UserAuthorizationKey, + DateAdded, + DateOfLastUpdate + FROM [CH01-01-Dimension].[DimProduct]'); + + DECLARE @EndingDateTime DATETIME2; + SET @EndingDateTime = SYSDATETIME(); + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) + FROM [CH01-01-Dimension].[DimProduct]); + + EXEC Process.[usp_TrackWorkFlow] 'Procedure: Project2.[Load_DimProduct] loads data into [CH01-01-Dimension].[DimProduct]', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; + + SELECT * + FROM Group1.uvw_DimProduct; + +END; +GO + + +-- ShowTableStatusRowCount Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: Aryeh Richman +-- Create date: 11/13/23 +-- Description: Populate a table to show the status of the row counts +-- ============================================= +CREATE PROCEDURE Project2.[ShowTableStatusRowCount] + @TableStatus VARCHAR(64), + @UserAuthorizationKey INT +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + DECLARE @DateAdded DATETIME2; + SET @DateAdded = SYSDATETIME(); + + DECLARE @DateOfLastUpdate DATETIME2; + SET @DateOfLastUpdate = SYSDATETIME(); + + DECLARE @StartingDateTime DATETIME2; + SET @StartingDateTime = SYSDATETIME(); + + DECLARE @EndingDateTime DATETIME2; + + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = 0; + + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].DimCustomer', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[DimCustomer] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].DimGender', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[DimGender] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].DimMaritalStatus', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[DimMaritalStatus] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].DimOccupation', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[DimOccupation] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].DimOrderDate', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[DimOrderDate] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].DimProduct', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[DimProduct] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].DimProductCategory', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[DimProductCategory] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].DimProductSubcategory', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[DimProductSubcategory] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].DimTerritory', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[DimTerritory] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = '[CH01-01-Dimension].SalesManagers', + [Row Count] = COUNT(*) + FROM [CH01-01-Dimension].[SalesManagers] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = 'Fact.Data', + [Row Count] = COUNT(*) + FROM Fact.[Data] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = 'DbSecurity.UserAuthorization', + [Row Count] = COUNT(*) + FROM DbSecurity.[UserAuthorization] + UNION ALL + SELECT TableStatus = @TableStatus, + TableName = 'Process.WorkflowSteps', + [Row Count] = COUNT(*) + FROM Process.[WorkflowSteps]; + + SET @EndingDateTime = SYSDATETIME(); + + EXEC Process.[usp_TrackWorkFlow] 'Procedure: Project2.[ShowStatusRowCount] loads data into ShowTableStatusRowCount', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; +END; +GO + + + +-- LoadStarSchemaData Procedure + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: YourName +-- Create date: +-- Description: +-- ============================================= +CREATE PROCEDURE [Project2].[LoadStarSchemaData] @UserAuthorizationKey INT +AS +BEGIN + SET NOCOUNT ON; + DECLARE @StartingDateTime DATETIME2 = SYSDATETIME(); + + -- + -- Drop All of the foreign keys prior to truncating tables in the star schema + -- + EXEC [Project2].[DropForeignKeysFromStarSchemaData] @UserAuthorizationKey = 1; + -- + -- Check row count before truncation + EXEC [Project2].[ShowTableStatusRowCount] + @UserAuthorizationKey = 2, -- Change -1 to the appropriate UserAuthorizationKey + @TableStatus = N'''Pre-truncate of tables''' + -- + -- Always truncate the Star Schema Data + -- + EXEC [Project2].[TruncateStarSchemaData] @UserAuthorizationKey = 1; + -- + -- Load the star schema + -- + EXEC [Project2].[Load_DimProductCategory] @UserAuthorizationKey = 4; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_DimProductSubcategory] @UserAuthorizationKey = 4; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_DimProduct] @UserAuthorizationKey = 6; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_SalesManagers] @UserAuthorizationKey = 3; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_DimGender] @UserAuthorizationKey = 5; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_DimMaritalStatus] @UserAuthorizationKey = 2; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_DimOccupation] @UserAuthorizationKey = 7; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_DimOrderDate] @UserAuthorizationKey = 7; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_DimTerritory] @UserAuthorizationKey = 3; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_DimCustomer] @UserAuthorizationKey = 5; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_Data] @UserAuthorizationKey = 6; -- Change -1 to the appropriate UserAuthorizationKey + -- + -- Recreate all of the foreign keys prior after loading the star schema + -- + -- + -- Check row count before truncation + EXEC [Project2].[ShowTableStatusRowCount] + @UserAuthorizationKey = 2, -- Change -1 to the appropriate UserAuthorizationKey + @TableStatus = N'''Row Count after loading the star schema''' + -- + EXEC [Project2].[AddForeignKeysToStarSchemaData] @UserAuthorizationKey = 1; -- Change -1 to the appropriate UserAuthorizationKey + -- + + DECLARE @WorkFlowStepTableRowCount INT; + SET @WorkFlowStepTableRowCount = 0; + DECLARE @EndingDateTime DATETIME2 = SYSDATETIME(); + EXEC [Process].[usp_TrackWorkFlow] 'Load Star Schema Data', + @WorkFlowStepTableRowCount, + @StartingDateTime, + @EndingDateTime, + @UserAuthorizationKey; +END; +GO + + diff --git a/SQL_files/WorkFlowSteps.sql b/SQL_files/WorkFlowSteps.sql new file mode 100644 index 0000000..1f50bfd --- /dev/null +++ b/SQL_files/WorkFlowSteps.sql @@ -0,0 +1,15 @@ +USE [9:15_Group1] +GO + +SELECT + ua.GroupMemberLastName + , ua.GroupMemberFirstName + , wfs.WorkFlowStepKey + , wfs.WorkFlowStepDescription + , wfs.WorkFlowStepTableRowCount + , CAST(DATEDIFF(ms, MIN(wfs.StartingDateTime), MAX(wfs.EndingDateTime)) as varchar(100)) + ' ' + 'ms' AS ExecutionTime +FROM Process.WorkflowSteps AS wfs +FULL OUTER JOIN DbSecurity.UserAuthorization AS ua +ON wfs.UserAuthorizationKey = UA.UserAuthorizationKey +WHERE wfs.UserAuthorizationKey = 1 +GROUP BY wfs.WorkFlowStepKey, wfs.WorkFlowStepDescription, wfs.WorkFlowStepTableRowCount, ua.GroupMemberFirstName, ua.GroupMemberLastName; \ No newline at end of file From 8bf6f19e713f5673109b427e4d3e1325407db24d Mon Sep 17 00:00:00 2001 From: Aleksandra Aya Georgievska Date: Tue, 14 Nov 2023 23:17:22 -0500 Subject: [PATCH 5/9] uploading completed sql scripts --- .DS_Store | Bin 0 -> 6148 bytes SQL_files/MainScript.sql | 491 ++++++++++++++++++++++++------------ SQL_files/WorkFlowSteps.sql | 25 +- 3 files changed, 342 insertions(+), 174 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a5d13c793c16351764c3d1ce01874b03c89a6a72 GIT binary patch literal 6148 zcmeHK%}T>S5T0$TZ7D(z3VK`cTChJ>5ig~6%;3Z6vl49tGB^OI%2gqIIjPl~jf&iD>`kY|!p8Q_;hFasK1J%q@G0=q)3RnUg;z8dZ0*?{M4^iA zF`8DU6^zUPGr$Zi2?O@{E0mUGzr0OmfEoBX19Uz}R6@sMVo)C)IMDAS#dCxtXwzMS zP+D{>CI&HrB1|cwDHZmLAxt^?rOk6JCI(G82)!~s$F3~w4MphH(Jys62*)6g%m6bm z%Rtsl%hdmmzrX*_7V(T3U Date: Wed, 15 Nov 2023 20:04:07 -0500 Subject: [PATCH 6/9] adding updated SQL scripts --- SQL_files/MainScript.sql | 58 ++++++++++++++++++------------------- SQL_files/WorkFlowSteps.sql | 7 +++-- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/SQL_files/MainScript.sql b/SQL_files/MainScript.sql index 554f1ee..205bcdc 100644 --- a/SQL_files/MainScript.sql +++ b/SQL_files/MainScript.sql @@ -1104,6 +1104,20 @@ ALTER TABLE Process.[WorkflowSteps] ADD DEFAULT (sysdatetime()) FOR [EndingDate GO ALTER TABLE Process.[WorkflowSteps] ADD DEFAULT ('9:15') FOR [Class Time] GO + +INSERT INTO [DbSecurity].[UserAuthorization] +([GroupMemberLastName],[GroupMemberFirstName]) +VALUES + + ('Georgievska','Aleksandra'), + ('Yakubova','Sigalita'), + ('Kong','Nicholas'), + ('Wray','Edwin'), + ('Ahmed','Ahnaf'), + ('Richman','Aryeh'); +GO + + ALTER TABLE [CH01-01-Dimension].[DimCustomer] WITH CHECK ADD CONSTRAINT [FK_DimCustomer_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey]) GO @@ -1425,40 +1439,26 @@ BEGIN ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimCustomer; ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimGender; - ALTER TABLE Fact.[Data] - DROP CONSTRAINT FK_Data_DimMaritalStatus; + ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimMaritalStatus; ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimOccupation; ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimOrderDate; ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimProduct; ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimTerritory; ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_SalesManagers; - ALTER TABLE [CH01-01-Dimension].[DimProduct] - DROP CONSTRAINT FK_DimProduct_DimProductSubCategory; - ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] - DROP CONSTRAINT FK_DimProductSubCategory_DimProductCategory; - ALTER TABLE [CH01-01-Dimension].DimCustomer - DROP CONSTRAINT FK_DimCustomer_UserAuthorization; - ALTER TABLE [CH01-01-Dimension].DimGender - DROP CONSTRAINT FK_DimGender_UserAuthorization; - ALTER TABLE [CH01-01-Dimension].DimMaritalStatus - DROP CONSTRAINT FK_DimMaritalStatus_UserAuthorization; - ALTER TABLE [CH01-01-Dimension].DimOccupation - DROP CONSTRAINT FK_DimOccupation_UserAuthorization; - ALTER TABLE [CH01-01-Dimension].DimOrderDate - DROP CONSTRAINT FK_DimOrderDate_UserAuthorization; - ALTER TABLE [CH01-01-Dimension].DimProduct - DROP CONSTRAINT FK_DimProduct_UserAuthorization; - ALTER TABLE [CH01-01-Dimension].DimProductCategory - DROP CONSTRAINT FK_DimProductCategory_UserAuthorization; - ALTER TABLE [CH01-01-Dimension].DimProductSubCategory - DROP CONSTRAINT FK_DimProductSubCategory_UserAuthorization; - ALTER TABLE [CH01-01-Dimension].DimTerritory - DROP CONSTRAINT FK_DimTerritory_UserAuthorization; - ALTER TABLE [CH01-01-Dimension].SalesManagers - DROP CONSTRAINT FK_SalesManagers_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].[DimProduct] DROP CONSTRAINT FK_DimProduct_DimProductSubCategory; + ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] DROP CONSTRAINT FK_DimProductSubCategory_DimProductCategory; + ALTER TABLE [CH01-01-Dimension].DimCustomer DROP CONSTRAINT FK_DimCustomer_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimGender DROP CONSTRAINT FK_DimGender_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimMaritalStatus DROP CONSTRAINT FK_DimMaritalStatus_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimOccupation DROP CONSTRAINT FK_DimOccupation_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimOrderDate DROP CONSTRAINT FK_DimOrderDate_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimProduct DROP CONSTRAINT FK_DimProduct_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimProductCategory DROP CONSTRAINT FK_DimProductCategory_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimProductSubCategory DROP CONSTRAINT FK_DimProductSubCategory_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].DimTerritory DROP CONSTRAINT FK_DimTerritory_UserAuthorization; + ALTER TABLE [CH01-01-Dimension].SalesManagers DROP CONSTRAINT FK_SalesManagers_UserAuthorization; ALTER TABLE Fact.Data DROP CONSTRAINT FK_Data_UserAuthorization; - ALTER TABLE Process.[WorkflowSteps] - DROP CONSTRAINT FK_WorkFlowSteps_UserAuthorization; + ALTER TABLE Process.[WorkflowSteps] DROP CONSTRAINT FK_WorkFlowSteps_UserAuthorization; DECLARE @WorkFlowStepTableRowCount INT; SET @WorkFlowStepTableRowCount = 0; @@ -2659,7 +2659,7 @@ BEGIN */ EXEC [Project2].[Load_DimProductCategory] @UserAuthorizationKey = 2; -- Change -1 to the appropriate UserAuthorizationKey EXEC [Project2].[Load_DimProductSubcategory] @UserAuthorizationKey = 2; -- Change -1 to the appropriate UserAuthorizationKey - EXEC [Project2].[Load_DimProduct] @UserAuthorizationKey = 2; -- Change -1 to the appropriate UserAuthorizationKey + EXEC [Project2].[Load_DimProduct] @UserAuthorizationKey = 6; -- Change -1 to the appropriate UserAuthorizationKey EXEC [Project2].[Load_SalesManagers] @UserAuthorizationKey = 5; -- Change -1 to the appropriate UserAuthorizationKey EXEC [Project2].[Load_DimGender] @UserAuthorizationKey = 3; -- Change -1 to the appropriate UserAuthorizationKey EXEC [Project2].[Load_DimMaritalStatus] @UserAuthorizationKey = 4; -- Change -1 to the appropriate UserAuthorizationKey diff --git a/SQL_files/WorkFlowSteps.sql b/SQL_files/WorkFlowSteps.sql index 6bd8920..3da162f 100644 --- a/SQL_files/WorkFlowSteps.sql +++ b/SQL_files/WorkFlowSteps.sql @@ -4,7 +4,6 @@ GO -- Run the next command to populate the star schema database with all of the data EXEC [Project2].[LoadStarSchemaData] @UserAuthorizationKey = 1 - -- Run the next code to execute the Workflow steps to demo in the JDBC SELECT WFS.[Class Time], WFS.[EndingDateTime], @@ -13,4 +12,8 @@ SELECT WFS.[Class Time], WFS.WorkFlowStepDescription, WFS.WorkFlowStepKey, WFS.WorkFlowStepTableRowCount -FROM [Process].[WorkflowSteps] AS WFS \ No newline at end of file +FROM [Process].[WorkflowSteps] AS WFS + +-- Show the UserAuthorization table +SELECT * +FROM [DbSecurity].[UserAuthorization] \ No newline at end of file From e699b492d472b74d01cb7ebfc2842f9781eaee0c Mon Sep 17 00:00:00 2001 From: Aleksandra Aya Georgievska Date: Wed, 15 Nov 2023 20:30:04 -0500 Subject: [PATCH 7/9] updating group name views and table names --- SQL_files/MainScript.sql | 108 +++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/SQL_files/MainScript.sql b/SQL_files/MainScript.sql index 205bcdc..ae59ac4 100644 --- a/SQL_files/MainScript.sql +++ b/SQL_files/MainScript.sql @@ -34,13 +34,13 @@ GO CREATE SCHEMA FileUpload GO -/* Instructions for use of Group1 Schema name: +/* Instructions for use of G9_1 Schema name: Part of the design is to create either a view or Inline Table Value function for the source input query to load the specific table using your group name as a schema name */ -DROP SCHEMA IF EXISTS Group1; +DROP SCHEMA IF EXISTS G9_1; GO -CREATE SCHEMA Group1 +CREATE SCHEMA G9_1 GO DROP SCHEMA IF EXISTS PkSequence; @@ -437,7 +437,7 @@ FROM [BIClass].[FileUpload].[OriginallyLoadedData]; /* -Table: [Fact].[Data] +Table: [CH01-01-Fact].[Data] Description: This table serves as the central fact table for the sales data warehouse. It contains transactional @@ -527,7 +527,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_FactData] +CREATE VIEW G9_1.[uvw_FactData] AS SELECT Saleskey, @@ -591,7 +591,7 @@ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_DimCustomer] +CREATE VIEW G9_1.[uvw_DimCustomer] AS SELECT CustomerKey, CustomerName, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimCustomer] @@ -625,7 +625,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_DimGender] +CREATE VIEW G9_1.[uvw_DimGender] AS SELECT Gender, GenderDescription, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimGender] @@ -659,7 +659,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_DimMaritalStatus] +CREATE VIEW G9_1.[uvw_DimMaritalStatus] AS SELECT MaritalStatus, MaritalStatusDescription, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimMaritalStatus] @@ -693,7 +693,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_DimOccupation] +CREATE VIEW G9_1.[uvw_DimOccupation] AS SELECT OccupationKey, Occupation, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimOccupation] @@ -728,7 +728,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_DimOrderDate] +CREATE VIEW G9_1.[uvw_DimOrderDate] AS SELECT OrderDate, MonthName, MonthNumber, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimOrderDate] @@ -798,7 +798,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_DimProduct] +CREATE VIEW G9_1.[uvw_DimProduct] AS SELECT ProductKey, @@ -844,7 +844,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_DimTerritory] +CREATE VIEW G9_1.[uvw_DimTerritory] AS SELECT TerritoryKey, TerritoryGroup, TerritoryCountry, TerritoryRegion, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimTerritory] @@ -879,7 +879,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_SalesManagers] +CREATE VIEW G9_1.[uvw_SalesManagers] AS SELECT SalesManagerKey, SalesManager, Category, Office, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[SalesManagers] @@ -912,7 +912,7 @@ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_DimProductCategory] +CREATE VIEW G9_1.[uvw_DimProductCategory] AS SELECT ProductCategoryKey, ProductCategory, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimProductCategory] @@ -945,7 +945,7 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW Group1.[uvw_DimProductSubCategory] +CREATE VIEW G9_1.[uvw_DimProductSubCategory] AS SELECT ProductSubCategoryKey, ProductCategoryKey, ProductSubcategory, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimProductSubCategory] @@ -1399,7 +1399,7 @@ BEGIN ADD CONSTRAINT FK_SalesManagers_UserAuthorization FOREIGN KEY (UserAuthorizationKey) REFERENCES [DbSecurity].[UserAuthorization] (UserAuthorizationKey); - ALTER TABLE Fact.Data + ALTER TABLE [CH01-01-Fact].[Data] ADD CONSTRAINT FK_Data_UserAuthorization FOREIGN KEY (UserAuthorizationKey) REFERENCES [DbSecurity].[UserAuthorization] (UserAuthorizationKey); @@ -1457,7 +1457,7 @@ BEGIN ALTER TABLE [CH01-01-Dimension].DimProductSubCategory DROP CONSTRAINT FK_DimProductSubCategory_UserAuthorization; ALTER TABLE [CH01-01-Dimension].DimTerritory DROP CONSTRAINT FK_DimTerritory_UserAuthorization; ALTER TABLE [CH01-01-Dimension].SalesManagers DROP CONSTRAINT FK_SalesManagers_UserAuthorization; - ALTER TABLE Fact.Data DROP CONSTRAINT FK_Data_UserAuthorization; + ALTER TABLE [CH01-01-Fact].[Data] DROP CONSTRAINT FK_Data_UserAuthorization; ALTER TABLE Process.[WorkflowSteps] DROP CONSTRAINT FK_WorkFlowSteps_UserAuthorization; DECLARE @WorkFlowStepTableRowCount INT; @@ -1477,7 +1477,7 @@ Stored Procedure: Project2.[Load_Data] Description: This procedure is responsible for loading data from the staging table [FileUpload].[OriginallyLoadedData] -into the fact table [Fact].[Data]. It matches staging data with existing dimensions and populates the +into the fact table [CH01-01-Fact].[Data]. It matches staging data with existing dimensions and populates the fact table with transactional and dimensional data. It also maintains metadata about the data load, such as the responsible user and the timing of data load operations. @@ -1524,7 +1524,7 @@ BEGIN DECLARE @StartingDateTime DATETIME2; SET @StartingDateTime = SYSDATETIME(); - INSERT INTO [Fact].[Data] + INSERT INTO [CH01-01-Fact].[Data] ( SalesKey, SalesManagerKey, @@ -1610,8 +1610,8 @@ BEGIN on do.Occupation = OLD.Occupation --- accompanying view --- - EXEC ('DROP VIEW IF EXISTS Group1.uvw_FactData'); - EXEC ('CREATE VIEW Group1.uvw_FactData AS + EXEC ('DROP VIEW IF EXISTS G9_1.uvw_FactData'); + EXEC ('CREATE VIEW G9_1.uvw_FactData AS SELECT Saleskey, SalesManagerKey, @@ -1663,7 +1663,7 @@ BEGIN SELECT * - FROM Group1.uvw_FactData; + FROM G9_1.uvw_FactData; END; GO @@ -1709,8 +1709,8 @@ BEGIN FROM FileUpload.OriginallyLoadedData; --- accompanying view --- - EXEC ('DROP VIEW IF EXISTS Group1.uvw_DimProductCategory'); - EXEC ('CREATE VIEW Group1.uvw_DimProductCategory AS + EXEC ('DROP VIEW IF EXISTS G9_1.uvw_DimProductCategory'); + EXEC ('CREATE VIEW G9_1.uvw_DimProductCategory AS SELECT ProductCategoryKey, ProductCategory, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimProductCategory] '); @@ -1731,7 +1731,7 @@ BEGIN @UserAuthorizationKey; SELECT * - FROM Group1.uvw_DimProductCategory; + FROM G9_1.uvw_DimProductCategory; END; GO @@ -1781,8 +1781,8 @@ BEGIN ON OLD.[ProductCategory] = DPC.[ProductCategory]; --- accompanying view --- - EXEC ('DROP VIEW IF EXISTS Group1.uvw_DimProductSubCategory'); - EXEC ('CREATE VIEW Group1.uvw_DimProductSubCategory AS + EXEC ('DROP VIEW IF EXISTS G9_1.uvw_DimProductSubCategory'); + EXEC ('CREATE VIEW G9_1.uvw_DimProductSubCategory AS SELECT ProductSubCategoryKey, ProductCategoryKey, ProductSubcategory, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimProductSubCategory] '); @@ -1803,7 +1803,7 @@ BEGIN @UserAuthorizationKey; SELECT * - FROM Group1.uvw_DimProductSubCategory; + FROM G9_1.uvw_DimProductSubCategory; END; GO @@ -1844,8 +1844,8 @@ BEGIN --- accompanying view --- - EXEC('DROP VIEW IF EXISTS Group1.uvw_DimCustomer') - EXEC('CREATE VIEW Group1.uvw_DimCustomer AS + EXEC('DROP VIEW IF EXISTS G9_1.uvw_DimCustomer') + EXEC('CREATE VIEW G9_1.uvw_DimCustomer AS SELECT CustomerKey, CustomerName, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimCustomer]') @@ -1863,7 +1863,7 @@ BEGIN @EndingDateTime, @UserAuthorizationKey - EXEC('SELECT * FROM Group1.uvw_DimCustomer') + EXEC('SELECT * FROM G9_1.uvw_DimCustomer') END GO @@ -1902,8 +1902,8 @@ BEGIN --- accompanying view --- - EXEC('DROP VIEW IF EXISTS Group1.uvw_DimGender') - EXEC('CREATE VIEW Group1.uvw_DimGender AS + EXEC('DROP VIEW IF EXISTS G9_1.uvw_DimGender') + EXEC('CREATE VIEW G9_1.uvw_DimGender AS SELECT Gender, GenderDescription, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimGender]') @@ -1921,7 +1921,7 @@ BEGIN @EndingDateTime, @UserAuthorizationKey - EXEC('SELECT * FROM Group1.uvw_DimGender') + EXEC('SELECT * FROM G9_1.uvw_DimGender') END; GO @@ -1963,7 +1963,7 @@ BEGIN ALTER SEQUENCE PkSequence.DimTerritorySequenceObject RESTART WITH 1; TRUNCATE TABLE [CH01-01-Dimension].SalesManagers; ALTER SEQUENCE PkSequence.SalesManagersSequenceObject RESTART WITH 1; - TRUNCATE TABLE Fact.Data; + TRUNCATE TABLE [CH01-01-Fact].[Data]; ALTER SEQUENCE PkSequence.DataSequenceObject RESTART WITH 1; DECLARE @WorkFlowStepTableRowCount INT; @@ -2031,8 +2031,8 @@ BEGIN FROM FileUpload.OriginallyLoadedData AS OLD; - EXEC ('DROP VIEW IF EXISTS Group1.uvw_DimMaritalStatus'); - EXEC ('CREATE VIEW Group1.uvw_DimMaritalStatus AS + EXEC ('DROP VIEW IF EXISTS G9_1.uvw_DimMaritalStatus'); + EXEC ('CREATE VIEW G9_1.uvw_DimMaritalStatus AS SELECT MaritalStatus, MaritalStatusDescription, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimMaritalStatus]'); @@ -2050,7 +2050,7 @@ BEGIN @EndingDateTime, @UserAuthorizationKey; SELECT * - FROM Group1.uvw_DimMaritalStatus; + FROM G9_1.uvw_DimMaritalStatus; END; GO @@ -2091,8 +2091,8 @@ BEGIN --- accompanying view --- - EXEC('DROP VIEW IF EXISTS Group1.uvw_DimOccupation') - EXEC('CREATE VIEW Group1.uvw_DimOccupation AS + EXEC('DROP VIEW IF EXISTS G9_1.uvw_DimOccupation') + EXEC('CREATE VIEW G9_1.uvw_DimOccupation AS SELECT OccupationKey,Occupation,UserAuthorizationKey,DateAdded,DateOfLastUpdate FROM [CH01-01-Dimension].[DimOccupation]') @@ -2112,7 +2112,7 @@ BEGIN @UserAuthorizationKey SELECT * - FROM Group1.uvw_DimOccupation + FROM G9_1.uvw_DimOccupation END GO @@ -2168,8 +2168,8 @@ BEGIN SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) FROM [CH01-01-Dimension].DimTerritory); - EXEC('DROP VIEW IF EXISTS Group1.uvw_DimTerritory') - EXEC('CREATE VIEW Group1.uvw_DimTerritory AS + EXEC('DROP VIEW IF EXISTS G9_1.uvw_DimTerritory') + EXEC('CREATE VIEW G9_1.uvw_DimTerritory AS SELECT TerritoryKey, TerritoryGroup, TerritoryCountry, TerritoryRegion, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimTerritory] ') @@ -2181,7 +2181,7 @@ BEGIN @UserAuthorizationKey SELECT * - FROM Group1.uvw_DimTerritory + FROM G9_1.uvw_DimTerritory END GO @@ -2234,8 +2234,8 @@ BEGIN FROM FileUpload.OriginallyLoadedData as A --- accompanying view --- - EXEC('DROP VIEW IF EXISTS Group1.uvw_DimOrderDate') - EXEC('CREATE VIEW Group1.uvw_DimOrderDate AS + EXEC('DROP VIEW IF EXISTS G9_1.uvw_DimOrderDate') + EXEC('CREATE VIEW G9_1.uvw_DimOrderDate AS SELECT OrderDate, MonthName, MonthNumber, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimOrderDate]') @@ -2254,7 +2254,7 @@ BEGIN @UserAuthorizationKey SELECT * - FROM Group1.uvw_DimOrderDate + FROM G9_1.uvw_DimOrderDate END GO @@ -2303,8 +2303,8 @@ BEGIN FROM FileUpload.OriginallyLoadedData AS OLD --- accompanying view --- - EXEC('DROP VIEW IF EXISTS Group1.uvw_SalesManagers') - EXEC('CREATE VIEW Group1.uvw_SalesManagers AS + EXEC('DROP VIEW IF EXISTS G9_1.uvw_SalesManagers') + EXEC('CREATE VIEW G9_1.uvw_SalesManagers AS SELECT SalesManagerKey, SalesManager, Category, Office, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[SalesManagers] ') @@ -2323,7 +2323,7 @@ BEGIN @UserAuthorizationKey SELECT * - FROM Group1.uvw_SalesManagers + FROM G9_1.uvw_SalesManagers END; GO @@ -2432,8 +2432,8 @@ BEGIN ON OLD.[ProductSubcategory] = DPSC.[ProductSubcategory]; --- accompanying view --- - EXEC ('DROP VIEW IF EXISTS Group1.uvw_DimProduct'); - EXEC ('CREATE VIEW Group1.uvw_DimProduct AS + EXEC ('DROP VIEW IF EXISTS G9_1.uvw_DimProduct'); + EXEC ('CREATE VIEW G9_1.uvw_DimProduct AS SELECT ProductKey, ProductSubcategoryKey, @@ -2462,7 +2462,7 @@ BEGIN @UserAuthorizationKey; SELECT * - FROM Group1.uvw_DimProduct; + FROM G9_1.uvw_DimProduct; END; GO @@ -2553,7 +2553,7 @@ BEGIN FROM [CH01-01-Dimension].[SalesManagers] UNION ALL SELECT TableStatus = @TableStatus, - TableName = 'Fact.Data', + TableName = '[CH01-01-Fact].[Data]', [Row Count] = COUNT(*) FROM Fact.[Data] UNION ALL From f68cd648eeb4989376e2fe47b0ef5a41f27ef293 Mon Sep 17 00:00:00 2001 From: Aleksandra Aya Georgievska Date: Wed, 15 Nov 2023 21:06:06 -0500 Subject: [PATCH 8/9] fixed FACT bug in schema names --- SQL_files/MainScript.sql | 255 ++++++++++++++++++++++++++---------- SQL_files/WorkFlowSteps.sql | 2 +- 2 files changed, 188 insertions(+), 69 deletions(-) diff --git a/SQL_files/MainScript.sql b/SQL_files/MainScript.sql index ae59ac4..34c0e4b 100644 --- a/SQL_files/MainScript.sql +++ b/SQL_files/MainScript.sql @@ -1,7 +1,7 @@ -- CREATE THE DATABASE -CREATE DATABASE [9:15_Group1]; -GO +-- CREATE DATABASE [G9:15_Group1]; +-- GO --------------------- CREATE SCHEMAS ------------------------- DROP SCHEMA IF EXISTS DbSecurity; @@ -14,48 +14,48 @@ GO CREATE SCHEMA [CH01-01-Dimension]; GO -DROP SCHEMA IF EXISTS Fact; +DROP SCHEMA IF EXISTS [CH01-01-Fact]; GO -CREATE SCHEMA Fact; +CREATE SCHEMA [CH01-01-Fact]; GO -DROP SCHEMA IF EXISTS Project2; +DROP SCHEMA IF EXISTS [Project2]; GO -CREATE SCHEMA Project2 +CREATE SCHEMA [Project2] GO -DROP SCHEMA IF EXISTS Utils; +DROP SCHEMA IF EXISTS [Utils]; GO -CREATE SCHEMA Utils +CREATE SCHEMA [Utils] GO -DROP SCHEMA IF EXISTS FileUpload; +DROP SCHEMA IF EXISTS [FileUpload]; GO -CREATE SCHEMA FileUpload +CREATE SCHEMA [FileUpload] GO /* Instructions for use of G9_1 Schema name: Part of the design is to create either a view or Inline Table Value function for the source input query to load the specific table using your group name as a schema name */ -DROP SCHEMA IF EXISTS G9_1; +DROP SCHEMA IF EXISTS [G9_1]; GO -CREATE SCHEMA G9_1 +CREATE SCHEMA [G9_1] GO -DROP SCHEMA IF EXISTS PkSequence; +DROP SCHEMA IF EXISTS [PkSequence]; GO -CREATE SCHEMA PkSequence +CREATE SCHEMA [PkSequence] GO -DROP SCHEMA IF EXISTS Process; +DROP SCHEMA IF EXISTS [Process]; GO -CREATE SCHEMA Process +CREATE SCHEMA [Process] GO ------------------------- CREATE SEQUENCES ---------------------------- --- for replacing identity key in Fact.[Data] +-- for replacing identity key in [CH01-01-Fact].[Data] CREATE SEQUENCE PkSequence.[DataSequenceObject] AS [int] START WITH 1 @@ -146,16 +146,41 @@ GO ------------------------ Utils functions using Script as Create --------------------- +/* +Function: [Utils].[CalculateDataTypeByteStorage] + +Description: +This function calculates the storage size in bytes for a given SQL data type. +It handles various data types, including varchar, char, int, money, and date. +The storage size calculation is based on the data type and its specified length. + +Parameters: +@DataType - A varchar(50) parameter representing the SQL data type whose storage +size is to be calculated. The expected format is the data type followed by its +length in parentheses (for example, 'varchar(50)'). + +Returns: +Int - The function returns an integer value representing the number of bytes required to store a value of the specified data type. For variable-length types like varchar, an additional 2 bytes are added to the specified length to account for storage overhead. For fixed-length types, it returns their standard storage size. If the data type is not recognized, it returns -999. + +Usage: +This function is particularly useful for database sizing and planning. It can be used to estimate the storage requirements for tables based on their schema definitions. + +Example: +SELECT [Utils].[CalculateDataTypeByteStorage] ('varchar(50)'); +This example returns the storage size for a varchar data type with a length of 50 characters. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Professor Heller -- Create date: default -- Description: Code taken from the 'Script as Create' result of the scalar-Valued Function within the BIClass db -- ============================================= + +*/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO + CREATE FUNCTION [Utils].[CalculateDataTypeByteStorage] ( -- Add the parameters for the function here @@ -199,7 +224,35 @@ GO ---------------- recreating Util views using Script as Create --------- --- ShowServerUserNameAndCurrentDatabase View +/* +View: Utils.[ShowServerUserNameAndCurrentDatabase] + +Description: +This view is designed to quickly provide essential information about the current SQL Server environment. It returns the name of the server on which SQL Server is running, the username of the current user as recognized by the system, and the name of the database currently in use. + +Columns: +- ServerName: The name of the server where SQL Server is installed and running. +- YourUserName: The username of the current user as recognized by the system. This represents the user context in which the current SQL session is executing. +- CurrentDatabase: The name of the database that is currently in use by the session. + +Usage: +This view can be particularly useful for users who connect to multiple databases on different servers, especially in environments with complex configurations or multiple instances of SQL Server. It helps quickly identify the current context, which can be crucial for database administrators, developers, and analysts working in multi-database environments. + +Example: +SELECT * FROM Utils.[ShowServerUserNameAndCurrentDatabase]; + +This example retrieves the server name, the current user's username, and the name of the currently active database. + +Note: The information returned by this view reflects the current session's context and may vary depending on the user's connection and selected database. + +-- ============================================= +-- Author: Professor Heller +-- Create date: default +-- Description: Code taken from the 'Script as Create' result of the views within the BIClass db +-- ============================================= + + +*/ SET ANSI_NULLS ON GO @@ -213,7 +266,44 @@ as GO --- uvw_FindColumnDefinitionPlusDefaultAndCheckConstraint View + +/* +View: [Utils].[uvw_FindColumnDefinitionPlusDefaultAndCheckConstraint] + +Description: +This view provides comprehensive details about column definitions across various tables in the database. It concatenates information from different schema tables to give a detailed overview of each column, including its data type, nullability, default constraints, and check constraints if any. The view fetches data from INFORMATION_SCHEMA and sys schema to compile information about tables, columns, default constraints, and check constraints. + +Columns: +- FullyQualifiedTableName: The schema and table name combined. +- SchemaName: The name of the schema to which the table belongs. +- TableName: The name of the table. +- ColumnName: The name of the column in the table. +- OrdinalPosition: The ordinal position of the column in the table. +- FullyQualifiedDomainName: The schema and domain name combined, if any. +- DomainName: The domain name of the column. +- DataType: The data type of the column, formatted with length, precision, and scale where applicable. +- IsNullable: Indicates if the column allows NULL values. +- DefaultName: The name of the default constraint applied to the column, if any. +- DefaultNameDefinition: The definition of the default constraint. +- CheckConstraintRuleName: The name of the check constraint applied to the column, if any. +- CheckConstraintRuleNameDefinition: The definition of the check constraint. + +Usage: +This view is particularly useful for database administrators and developers who need to quickly retrieve detailed information about the database schema, especially when working with complex databases with many tables and columns. It can be used for schema analysis, documentation, or to aid in database migrations or upgrades. + +Example: +SELECT * FROM [Utils].[uvw_FindColumnDefinitionPlusDefaultAndCheckConstraint] +WHERE SchemaName = 'MySchema' AND TableName = 'MyTable'; + +This example retrieves detailed column information for all columns in the 'MyTable' table within the 'MySchema' schema. + +-- ============================================= +-- Author: Professor Heller +-- Create date: default +-- Description: Code taken from the 'Script as Create' result of the views within the BIClass db +-- ============================================= + +*/ SET ANSI_NULLS ON GO @@ -315,7 +405,36 @@ AS GO --- uvw_FindTablesStorageBytes View +/* +View: [Utils].[uvw_FindTablesStorageBytes] + +Description: +This view provides an estimate of the storage size in bytes for each column in tables within specified schemas (schemas starting with 'CH'). It utilizes the [Utils].[uvw_FindColumnDefinitionPlusDefaultAndCheckConstraint] view to retrieve column details and then calculates the storage size based on the data type of each column. The view handles various data types, including varchar, char, int, money, and date, providing an estimate of the storage requirement for each column. + +Columns: +- FullyQualifiedTableName: The combined schema and table name. +- ColumnName: The name of the column. +- DataType: The data type of the column. +- OrdinalPosition: The position of the column in the table. +- StorageBytes: An estimated storage size for the column in bytes. This estimate includes additional storage requirements for variable-length types. + +Usage: +This view is useful for database sizing and capacity planning. It can be used to estimate the storage requirements for each column in the database's tables, which is particularly beneficial when working with large databases or planning for data growth. + +Example: +SELECT * FROM [Utils].[uvw_FindTablesStorageBytes]; + +This example retrieves the estimated storage size for each column in tables belonging to schemas that start with 'CH'. + +Note: The storage size calculations are estimates and may not reflect the exact storage requirements, especially for variable-length fields and fields with additional storage overhead. + +-- ============================================= +-- Author: Professor Heller +-- Create date: default +-- Description: Code taken from the 'Script as Create' result of the views within the BIClass db +-- ============================================= + +*/ SET ANSI_NULLS ON GO @@ -420,7 +539,7 @@ GO -- Migrate the data from the BiClass DB to our group DB -INSERT INTO [9:15_Group1].[FileUpload].[OriginallyLoadedData] +INSERT INTO [G9:15_Group1].[FileUpload].[OriginallyLoadedData] ([SalesKey], [ProductCategory], [ProductSubcategory], [SalesManager], [ProductCode], [ProductName], [Color], [ModelName], [OrderQuantity], [UnitPrice], [ProductStandardCost], [SalesAmount], [OrderDate], [MonthName], [MonthNumber], @@ -479,7 +598,7 @@ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -CREATE TABLE Fact.[Data] +CREATE TABLE [CH01-01-Fact].[Data] ( [SalesKey] [int] NOT NULL, [SalesManagerKey] [int] NULL, @@ -562,7 +681,7 @@ AS UserAuthorizationKey, DateAdded, DateOfLastUpdate - FROM Fact.[Data] + FROM [CH01-01-Fact].[Data] GO -- DimCustomer Table -- @@ -1078,11 +1197,11 @@ ALTER TABLE [CH01-01-Dimension].[SalesManagers] ADD DEFAULT (sysdatetime()) FOR GO ALTER TABLE [CH01-01-Dimension].[SalesManagers] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] GO -ALTER TABLE Fact.[Data] ADD DEFAULT (NEXT VALUE FOR PkSequence.[DataSequenceObject]) FOR [SalesKey] +ALTER TABLE [CH01-01-Fact].[Data] ADD DEFAULT (NEXT VALUE FOR PkSequence.[DataSequenceObject]) FOR [SalesKey] GO -ALTER TABLE Fact.[Data] ADD DEFAULT (sysdatetime()) FOR [DateAdded] +ALTER TABLE [CH01-01-Fact].[Data] ADD DEFAULT (sysdatetime()) FOR [DateAdded] GO -ALTER TABLE Fact.[Data] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] +ALTER TABLE [CH01-01-Fact].[Data] ADD DEFAULT (sysdatetime()) FOR [DateOfLastUpdate] GO ALTER TABLE [DbSecurity].[UserAuthorization] ADD DEFAULT (NEXT VALUE FOR PkSequence.[UserAuthorizationSequenceObject]) FOR [UserAuthorizationKey] GO @@ -1178,50 +1297,50 @@ REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey]) GO ALTER TABLE [CH01-01-Dimension].[SalesManagers] CHECK CONSTRAINT [FK_SalesManagers_UserAuthorization] GO -ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimCustomer] FOREIGN KEY([CustomerKey]) +ALTER TABLE [CH01-01-Fact].[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimCustomer] FOREIGN KEY([CustomerKey]) REFERENCES [CH01-01-Dimension].[DimCustomer] ([CustomerKey]) GO -ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimCustomer] +ALTER TABLE [CH01-01-Fact].[Data] CHECK CONSTRAINT [FK_Data_DimCustomer] GO -ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimGender] FOREIGN KEY([Gender]) +ALTER TABLE [CH01-01-Fact].[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimGender] FOREIGN KEY([Gender]) REFERENCES [CH01-01-Dimension].[DimGender] ([Gender]) GO -ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimGender] +ALTER TABLE [CH01-01-Fact].[Data] CHECK CONSTRAINT [FK_Data_DimGender] GO -ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimMaritalStatus] FOREIGN KEY([MaritalStatus]) +ALTER TABLE [CH01-01-Fact].[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimMaritalStatus] FOREIGN KEY([MaritalStatus]) REFERENCES [CH01-01-Dimension].[DimMaritalStatus] ([MaritalStatus]) GO -ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimMaritalStatus] +ALTER TABLE [CH01-01-Fact].[Data] CHECK CONSTRAINT [FK_Data_DimMaritalStatus] GO -ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimOccupation] FOREIGN KEY([OccupationKey]) +ALTER TABLE [CH01-01-Fact].[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimOccupation] FOREIGN KEY([OccupationKey]) REFERENCES [CH01-01-Dimension].[DimOccupation] ([OccupationKey]) GO -ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimOccupation] +ALTER TABLE [CH01-01-Fact].[Data] CHECK CONSTRAINT [FK_Data_DimOccupation] GO -ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimOrderDate] FOREIGN KEY([OrderDate]) +ALTER TABLE [CH01-01-Fact].[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimOrderDate] FOREIGN KEY([OrderDate]) REFERENCES [CH01-01-Dimension].[DimOrderDate] ([OrderDate]) GO -ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimOrderDate] +ALTER TABLE [CH01-01-Fact].[Data] CHECK CONSTRAINT [FK_Data_DimOrderDate] GO -ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimProduct] FOREIGN KEY([ProductKey]) +ALTER TABLE [CH01-01-Fact].[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimProduct] FOREIGN KEY([ProductKey]) REFERENCES [CH01-01-Dimension].[DimProduct] ([ProductKey]) GO -ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimProduct] +ALTER TABLE [CH01-01-Fact].[Data] CHECK CONSTRAINT [FK_Data_DimProduct] GO -ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimTerritory] FOREIGN KEY([TerritoryKey]) +ALTER TABLE [CH01-01-Fact].[Data] WITH CHECK ADD CONSTRAINT [FK_Data_DimTerritory] FOREIGN KEY([TerritoryKey]) REFERENCES [CH01-01-Dimension].[DimTerritory] ([TerritoryKey]) GO -ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_DimTerritory] +ALTER TABLE [CH01-01-Fact].[Data] CHECK CONSTRAINT [FK_Data_DimTerritory] GO -ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_SalesManagers] FOREIGN KEY([SalesManagerKey]) +ALTER TABLE [CH01-01-Fact].[Data] WITH CHECK ADD CONSTRAINT [FK_Data_SalesManagers] FOREIGN KEY([SalesManagerKey]) REFERENCES [CH01-01-Dimension].[SalesManagers] ([SalesManagerKey]) GO -ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_SalesManagers] +ALTER TABLE [CH01-01-Fact].[Data] CHECK CONSTRAINT [FK_Data_SalesManagers] GO -ALTER TABLE Fact.[Data] WITH CHECK ADD CONSTRAINT [FK_Data_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) +ALTER TABLE [CH01-01-Fact].[Data] WITH CHECK ADD CONSTRAINT [FK_Data_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey]) GO -ALTER TABLE Fact.[Data] CHECK CONSTRAINT [FK_Data_UserAuthorization] +ALTER TABLE [CH01-01-Fact].[Data] CHECK CONSTRAINT [FK_Data_UserAuthorization] GO ALTER TABLE Process.[WorkflowSteps] WITH CHECK ADD CONSTRAINT [FK_WorkFlowSteps_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey]) @@ -1319,35 +1438,35 @@ BEGIN -- interfering with SELECT statements. DECLARE @StartingDateTime DATETIME2 = SYSDATETIME(); - ALTER TABLE Fact.[Data] + ALTER TABLE [CH01-01-Fact].[Data] ADD CONSTRAINT FK_Data_DimCustomer FOREIGN KEY (CustomerKey) REFERENCES [CH01-01-Dimension].DimCustomer (CustomerKey); - ALTER TABLE Fact.[Data] + ALTER TABLE [CH01-01-Fact].[Data] ADD CONSTRAINT FK_Data_DimGender FOREIGN KEY (Gender) REFERENCES [CH01-01-Dimension].DimGender (Gender); - ALTER TABLE Fact.[Data] + ALTER TABLE [CH01-01-Fact].[Data] ADD CONSTRAINT FK_Data_DimMaritalStatus FOREIGN KEY (MaritalStatus) REFERENCES [CH01-01-Dimension].DimMaritalStatus (MaritalStatus); - ALTER TABLE Fact.[Data] + ALTER TABLE [CH01-01-Fact].[Data] ADD CONSTRAINT FK_Data_DimOccupation FOREIGN KEY (OccupationKey) REFERENCES [CH01-01-Dimension].DimOccupation (OccupationKey); - ALTER TABLE Fact.[Data] + ALTER TABLE [CH01-01-Fact].[Data] ADD CONSTRAINT FK_Data_DimOrderDate FOREIGN KEY (OrderDate) REFERENCES [CH01-01-Dimension].DimOrderDate (OrderDate); - ALTER TABLE Fact.[Data] + ALTER TABLE [CH01-01-Fact].[Data] ADD CONSTRAINT FK_Data_DimProduct FOREIGN KEY (ProductKey) REFERENCES [CH01-01-Dimension].DimProduct (ProductKey); - ALTER TABLE Fact.[Data] + ALTER TABLE [CH01-01-Fact].[Data] ADD CONSTRAINT FK_Data_DimTerritory FOREIGN KEY (TerritoryKey) REFERENCES [CH01-01-Dimension].DimTerritory (TerritoryKey); - ALTER TABLE Fact.[Data] + ALTER TABLE [CH01-01-Fact].[Data] ADD CONSTRAINT FK_Data_SalesManagers FOREIGN KEY (SalesManagerKey) REFERENCES [CH01-01-Dimension].SalesManagers (SalesManagerKey); @@ -1437,14 +1556,14 @@ BEGIN SET NOCOUNT ON; DECLARE @StartingDateTime DATETIME2 = SYSDATETIME(); - ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimCustomer; - ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimGender; - ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimMaritalStatus; - ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimOccupation; - ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimOrderDate; - ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimProduct; - ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_DimTerritory; - ALTER TABLE Fact.[Data] DROP CONSTRAINT FK_Data_SalesManagers; + ALTER TABLE [CH01-01-Fact].[Data] DROP CONSTRAINT FK_Data_DimCustomer; + ALTER TABLE [CH01-01-Fact].[Data] DROP CONSTRAINT FK_Data_DimGender; + ALTER TABLE [CH01-01-Fact].[Data] DROP CONSTRAINT FK_Data_DimMaritalStatus; + ALTER TABLE [CH01-01-Fact].[Data] DROP CONSTRAINT FK_Data_DimOccupation; + ALTER TABLE [CH01-01-Fact].[Data] DROP CONSTRAINT FK_Data_DimOrderDate; + ALTER TABLE [CH01-01-Fact].[Data] DROP CONSTRAINT FK_Data_DimProduct; + ALTER TABLE [CH01-01-Fact].[Data] DROP CONSTRAINT FK_Data_DimTerritory; + ALTER TABLE [CH01-01-Fact].[Data] DROP CONSTRAINT FK_Data_SalesManagers; ALTER TABLE [CH01-01-Dimension].[DimProduct] DROP CONSTRAINT FK_DimProduct_DimProductSubCategory; ALTER TABLE [CH01-01-Dimension].[DimProductSubCategory] DROP CONSTRAINT FK_DimProductSubCategory_DimProductCategory; ALTER TABLE [CH01-01-Dimension].DimCustomer DROP CONSTRAINT FK_DimCustomer_UserAuthorization; @@ -1645,7 +1764,7 @@ BEGIN UserAuthorizationKey, DateAdded, DateOfLastUpdate - FROM Fact.[Data]'); + FROM [CH01-01-Fact].[Data]'); DECLARE @EndingDateTime DATETIME2; @@ -1653,9 +1772,9 @@ BEGIN DECLARE @WorkFlowStepTableRowCount INT; SET @WorkFlowStepTableRowCount = (SELECT COUNT(*) - FROM Fact.[Data]); + FROM [CH01-01-Fact].[Data]); - EXEC Process.[usp_TrackWorkFlow] 'Procedure: Project2.[Load_Data] loads data into Fact.[Data]', + EXEC Process.[usp_TrackWorkFlow] 'Procedure: Project2.[Load_Data] loads data into [CH01-01-Fact].[Data]', @WorkFlowStepTableRowCount, @StartingDateTime, @EndingDateTime, @@ -2555,7 +2674,7 @@ BEGIN SELECT TableStatus = @TableStatus, TableName = '[CH01-01-Fact].[Data]', [Row Count] = COUNT(*) - FROM Fact.[Data] + FROM [CH01-01-Fact].[Data] UNION ALL SELECT TableStatus = @TableStatus, TableName = '[DbSecurity].[UserAuthorization]', diff --git a/SQL_files/WorkFlowSteps.sql b/SQL_files/WorkFlowSteps.sql index 3da162f..39e0794 100644 --- a/SQL_files/WorkFlowSteps.sql +++ b/SQL_files/WorkFlowSteps.sql @@ -1,4 +1,4 @@ -USE [9:15_Group1] +USE [G9:15_Group1] GO -- Run the next command to populate the star schema database with all of the data From 434b0e1ecb6869fcceb5b74e16ca48365f849f5f Mon Sep 17 00:00:00 2001 From: Aleksandra Aya Georgievska Date: Wed, 15 Nov 2023 22:33:07 -0500 Subject: [PATCH 9/9] added doc strings to code --- SQL_files/MainScript.sql | 989 ++++++++++++++++++++++++++++++++------- 1 file changed, 832 insertions(+), 157 deletions(-) diff --git a/SQL_files/MainScript.sql b/SQL_files/MainScript.sql index 34c0e4b..862b3b3 100644 --- a/SQL_files/MainScript.sql +++ b/SQL_files/MainScript.sql @@ -222,7 +222,7 @@ END GO ----------------- recreating Util views using Script as Create --------- +-------------------------- recreating Util views using Script as Create --------------------- /* View: Utils.[ShowServerUserNameAndCurrentDatabase] @@ -508,7 +508,7 @@ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -CREATE TABLE FileUpload.[OriginallyLoadedData] +CREATE TABLE [FileUpload].[OriginallyLoadedData] ( [SalesKey] [int] NOT NULL, [ProductCategory] [varchar](20) NULL, @@ -684,7 +684,43 @@ AS FROM [CH01-01-Fact].[Data] GO --- DimCustomer Table -- +/* +Table: [CH01-01-Dimension].[DimCustomer] + +Description: +This table serves as a dimension table in the data warehouse schema, primarily focusing on customer-related information. +It stores key details about customers, along with auditing information about when each record was added and last updated. +The table also integrates a link to user authorization through the UserAuthorizationKey. + +Columns: +- CustomerKey: The primary key for the table, uniquely identifying each customer record. +- CustomerName: The name of the customer. +- UserAuthorizationKey: A foreign key that references the UserAuthorization table, indicating which user created or last +updated the record. This is used for tracking and auditing purposes. +- DateAdded: The date and time when the record was added to the table. +- DateOfLastUpdate: The date and time when the record was last updated. + +Primary Key: +- The primary key of the table is [CustomerKey], ensuring that each customer is uniquely identifiable. + +Index and Statistics Options: +- PAD_INDEX, STATISTICS_NORECOMPUTE, IGNORE_DUP_KEY, ALLOW_ROW_LOCKS, and ALLOW_PAGE_LOCKS are set for optimal performance +and concurrency control. OPTIMIZE_FOR_SEQUENTIAL_KEY is turned off. + +Usage: +The DimCustomer table is used in conjunction with fact tables to provide a detailed and dimensional view of customer data. +It's a key component in analyses, reports, and queries that require customer information. + +Example: +SELECT * FROM [CH01-01-Dimension].[DimCustomer] +WHERE CustomerKey = 12345; + +This example retrieves information for the customer with a CustomerKey of 12345. + +Note: The table is part of a larger dimensional model and should be maintained with consideration to data integrity and +consistency, particularly regarding the UserAuthorizationKey. + +*/ SET ANSI_NULLS ON GO @@ -717,7 +753,37 @@ AS GO --- DimGender Table -- +/* +Table: [CH01-01-Dimension].[DimGender] + +Description: +This table represents the gender dimension in the data warehouse schema. It categorizes and describes gender in a standardized format. The table includes a concise code for each gender category and a more descriptive label for each category. It also includes auditing fields for tracking the creation and modification of records. + +Columns: +- Gender: A character field that serves as the primary key, representing a concise code for the gender (e.g., 'M' for male, 'F' for female). +- GenderDescription: A descriptive label for each gender category, such as 'Male', 'Female', etc. +- UserAuthorizationKey: A foreign key that references the UserAuthorization table, indicating which user created or last updated the record. This key is used for auditing purposes. +- DateAdded: The date and time when the record was initially added to the table. +- DateOfLastUpdate: The date and time when the record was last updated. + +Primary Key: +- The primary key of the table is [Gender], ensuring a unique representation for each gender category. + +Index and Statistics Options: +- PAD_INDEX, STATISTICS_NORECOMPUTE, IGNORE_DUP_KEY, ALLOW_ROW_LOCKS, and ALLOW_PAGE_LOCKS are configured for performance and concurrency optimization. OPTIMIZE_FOR_SEQUENTIAL_KEY is disabled. + +Usage: +The DimGender table is typically used in conjunction with fact tables for gender-based analysis in reports, queries, and data mining operations. It is a key dimension in understanding and segmenting data by gender. + +Example: +SELECT * FROM [CH01-01-Dimension].[DimGender] +WHERE Gender = 'M'; + +This example retrieves the record for the gender category represented by 'M'. + +Note: Maintaining the integrity and consistency of data in this table is important, especially in terms of its relationship with the UserAuthorization table for auditing purposes. + +*/ SET ANSI_NULLS ON GO @@ -751,7 +817,37 @@ AS GO --- DimMaritalStatus Table -- +/* +Table: [CH01-01-Dimension].[DimMaritalStatus] + +Description: +The DimMaritalStatus table is part of the data warehouse dimensional model, specifically designed to represent various marital statuses. It provides a standardized way of categorizing individuals based on their marital status, using both a concise code and a more descriptive label. The table also incorporates fields for user authorization and timestamps to track when records are added or updated. + +Columns: +- MaritalStatus: A character field that serves as the primary key. It represents a concise code for the marital status (e.g., 'S' for single, 'M' for married). +- MaritalStatusDescription: A descriptive label for each marital status category, such as 'Single', 'Married', etc. +- UserAuthorizationKey: A foreign key that links to the UserAuthorization table, denoting the user responsible for creating or updating the record. This field is essential for auditing and data governance. +- DateAdded: The date and time when the record was initially added to the table. +- DateOfLastUpdate: The date and time when the record was last updated. + +Primary Key: +- The primary key of the table is [MaritalStatus], ensuring a unique and standardized representation for each marital status category. + +Index and Statistics Options: +- Configured with PAD_INDEX, STATISTICS_NORECOMPUTE, IGNORE_DUP_KEY, ALLOW_ROW_LOCKS, and ALLOW_PAGE_LOCKS for optimal performance. OPTIMIZE_FOR_SEQUENTIAL_KEY is turned off. + +Usage: +The DimMaritalStatus table is utilized in conjunction with fact tables to facilitate marital status-based analysis in reporting, querying, and data analysis operations. It is a key dimension in demographic and market segmentation analyses. + +Example: +SELECT * FROM [CH01-01-Dimension].[DimMaritalStatus] +WHERE MaritalStatus = 'M'; + +This example retrieves information about the marital status represented by 'M'. + +Note: Data integrity and consistency, especially in relation to the UserAuthorizationKey, are crucial for maintaining the reliability and auditability of this table. + +*/ SET ANSI_NULLS ON GO @@ -784,7 +880,37 @@ AS FROM [CH01-01-Dimension].[DimMaritalStatus] GO --- DimOccupation Table -- +/* +Table: [CH01-01-Dimension].[DimOccupation] + +Description: +The DimOccupation table is a dimension table in the data warehouse schema that categorizes individuals based on their occupation. It contains a unique key for each occupation type and a descriptive label. Additionally, the table tracks the user who added or last updated each record, along with the dates of these actions, to aid in data governance and auditing. + +Columns: +- OccupationKey: The primary key for the table, an integer uniquely identifying each occupation type. +- Occupation: A varchar(20) field providing a descriptive name or title for each occupation. +- UserAuthorizationKey: An integer foreign key linking to the UserAuthorization table. This key indicates which user is responsible for the creation or last update of the record and is vital for auditing. +- DateAdded: The datetime2(7) timestamp of when the record was added to the table. +- DateOfLastUpdate: The datetime2(7) timestamp of when the record was last updated. + +Primary Key: +- The primary key is [OccupationKey], ensuring that each occupation type is uniquely identifiable. + +Index and Statistics Options: +- The table is configured with PAD_INDEX, STATISTICS_NORECOMPUTE, IGNORE_DUP_KEY, ALLOW_ROW_LOCKS, and ALLOW_PAGE_LOCKS for optimal performance and concurrency management. OPTIMIZE_FOR_SEQUENTIAL_KEY is disabled. + +Usage: +The DimOccupation table is used in conjunction with fact tables for analyses that require categorization or segmentation of data based on occupation. It is essential in workforce analysis, demographic studies, and market segmentation. + +Example: +SELECT * FROM [CH01-01-Dimension].[DimOccupation] +WHERE OccupationKey = 101; + +This example retrieves information about the occupation with an OccupationKey of 101. + +Note: Maintaining the accuracy and consistency of the data in this table, especially the UserAuthorizationKey, is critical for ensuring the integrity and reliability of the data warehouse. + +*/ SET ANSI_NULLS ON GO @@ -818,8 +944,39 @@ AS FROM [CH01-01-Dimension].[DimOccupation] GO --- DimOrderDate Table -- +/* +Table: [CH01-01-Dimension].[DimOrderDate] + +Description: +The DimOrderDate table is a dimension table in the data warehouse schema focused on storing date-related information, particularly for orders. It breaks down each date into its constituent parts, such as month name, month number, and year, for more granular analysis. This table also includes fields for user authorization and timestamps to track when records are added or updated. + +Columns: +- OrderDate: The primary key of the table, a date field uniquely identifying each day. +- MonthName: A varchar(10) field representing the name of the month for the given order date. +- MonthNumber: An integer representing the numeric month of the year for the given order date. +- Year: An integer representing the year for the given order date. +- UserAuthorizationKey: An integer foreign key linking to the UserAuthorization table, denoting the user responsible for creating or updating the record. This field is important for auditing and data governance. +- DateAdded: The datetime2(7) timestamp of when the record was initially added to the table. +- DateOfLastUpdate: The datetime2(7) timestamp of when the record was last updated. + +Primary Key: +- The primary key of the table is [OrderDate], ensuring a unique representation for each date. +Index and Statistics Options: +- Configured with PAD_INDEX, STATISTICS_NORECOMPUTE, IGNORE_DUP_KEY, ALLOW_ROW_LOCKS, and ALLOW_PAGE_LOCKS for optimal performance. OPTIMIZE_FOR_SEQUENTIAL_KEY is turned off. + +Usage: +The DimOrderDate table is typically used in conjunction with fact tables for date-based analysis in reports, queries, and data mining operations. It is a key dimension in time-based analyses, such as trend analysis and temporal comparisons. + +Example: +SELECT * FROM [CH01-01-Dimension].[DimOrderDate] +WHERE OrderDate = '2023-01-01'; + +This example retrieves information for the order date of January 1, 2023. + +Note: Data integrity and consistency, especially in relation to the UserAuthorizationKey, are crucial for maintaining the reliability and auditability of this table. + +*/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON @@ -934,7 +1091,39 @@ AS FROM [CH01-01-Dimension].[DimProduct] GO --- DimTerritory Table -- +/* +Table: [CH01-01-Dimension].[DimTerritory] + +Description: +The DimTerritory table is a dimension table in the data warehouse schema, designed to categorize geographical areas into territories for analysis. It includes information about various territorial levels, such as the group, country, and region. This table also incorporates user authorization tracking and timestamps for record creation and updates. + +Columns: +- TerritoryKey: The primary key of the table, an integer that uniquely identifies each territory record. +- TerritoryGroup: A varchar(20) field representing the higher-level grouping of territories. +- TerritoryCountry: A varchar(20) field indicating the country associated with the territory. +- TerritoryRegion: A varchar(20) field specifying the region within the territory. +- UserAuthorizationKey: An integer foreign key linking to the UserAuthorization table, indicating which user is responsible for the record. This is important for auditing purposes. +- DateAdded: The datetime2(7) timestamp when the record was initially added to the table. +- DateOfLastUpdate: The datetime2(7) timestamp when the record was last updated. + +Primary Key: +- The primary key is [TerritoryKey], ensuring unique identification of each territorial record. + +Index and Statistics Options: +- Configured with PAD_INDEX, STATISTICS_NORECOMPUTE, IGNORE_DUP_KEY, ALLOW_ROW_LOCKS, and ALLOW_PAGE_LOCKS for optimized performance and concurrency. OPTIMIZE_FOR_SEQUENTIAL_KEY is disabled. + +Usage: +The DimTerritory table is used in conjunction with fact tables to perform geographical or territorial analysis. It enables data segmentation and detailed examination based on geographic regions, which is crucial for regional sales analysis, market segmentation, and strategic planning. + +Example: +SELECT * FROM [CH01-01-Dimension].[DimTerritory] +WHERE TerritoryKey = 100; + +This example retrieves details about the territory with a TerritoryKey of 100. + +Note: Data integrity and consistency, especially regarding the UserAuthorizationKey, are vital for maintaining the accuracy and auditability of this table. + +*/ SET ANSI_NULLS ON GO @@ -963,13 +1152,45 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW G9_1.[uvw_DimTerritory] +CREATE VIEW [G9_1].[uvw_DimTerritory] AS SELECT TerritoryKey, TerritoryGroup, TerritoryCountry, TerritoryRegion, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimTerritory] GO --- SalesManagers Table -- +/* +Table: [CH01-01-Dimension].[SalesManagers] + +Description: +The SalesManagers table is a dimension table within the data warehouse that provides detailed information about sales managers. It includes the manager's name, their office location, and the category they are associated with. The table also features fields for user authorization to track who added or updated the records and timestamps for these events. + +Columns: +- SalesManagerKey: The primary key of the table, an integer uniquely identifying each sales manager. +- Category: A varchar(20) field indicating the category or segment the sales manager oversees. +- SalesManager: A varchar(50) field containing the name of the sales manager. +- Office: A varchar(50) field detailing the office location of the sales manager. +- UserAuthorizationKey: An integer foreign key that links to the UserAuthorization table, indicating the user responsible for creating or updating the record. This key is crucial for auditing and governance. +- DateAdded: The datetime2(7) timestamp when the record was added to the table. +- DateOfLastUpdate: The datetime2(7) timestamp when the record was last updated. + +Primary Key: +- The primary key is [SalesManagerKey], ensuring each sales manager is uniquely identified. + +Index and Statistics Options: +- The table is configured with PAD_INDEX, STATISTICS_NORECOMPUTE, IGNORE_DUP_KEY, ALLOW_ROW_LOCKS, and ALLOW_PAGE_LOCKS for performance optimization. OPTIMIZE_FOR_SEQUENTIAL_KEY is turned off. + +Usage: +This table is utilized for analysis that involves sales performance, management efficiency, and regional sales strategies. It allows for a detailed breakdown of sales data by manager, office, and category. + +Example: +SELECT * FROM [CH01-01-Dimension].[SalesManagers] +WHERE SalesManagerKey = 101; + +This example retrieves information about the sales manager with a SalesManagerKey of 101. + +Note: It's important to maintain the accuracy and consistency of the data in this table, particularly regarding the UserAuthorizationKey, to ensure data integrity and reliable auditing. + +*/ SET ANSI_NULLS ON GO @@ -998,15 +1219,46 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW G9_1.[uvw_SalesManagers] +CREATE VIEW [G9_1].[uvw_SalesManagers] AS SELECT SalesManagerKey, SalesManager, Category, Office, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[SalesManagers] GO --- 2 additional tables DimProductCategory and DimProductSubCategory --- Table 1 +/* +Table: [CH01-01-Dimension].[DimProductCategory] + +Description: +The DimProductCategory table is a dimension table in the data warehouse, designed to categorize products into various categories. This table includes a unique key for each product category and a descriptive name for the category. It also contains fields for user authorization and timestamps to keep track of when each record was added or last updated, aiding in data governance and auditing. + +Columns: +- ProductCategoryKey: The primary key of the table, an integer uniquely identifying each product category. +- ProductCategory: A varchar(20) field providing the name or description of the product category. +- UserAuthorizationKey: An integer foreign key that references the UserAuthorization table, indicating the user responsible for creating or updating the record. This is vital for auditing purposes. +- DateAdded: The datetime2(7) timestamp when the record was initially added to the table. +- DateOfLastUpdate: The datetime2(7) timestamp when the record was last updated. + +Primary Key: +- The primary key is [ProductCategoryKey], ensuring each product category is uniquely identifiable. + +Index and Statistics Options: +- Configured with PAD_INDEX, STATISTICS_NORECOMPUTE, IGNORE_DUP_KEY, ALLOW_ROW_LOCKS, and ALLOW_PAGE_LOCKS for optimal performance and data integrity. OPTIMIZE_FOR_SEQUENTIAL_KEY is turned off. + +Usage: +The DimProductCategory table is used in conjunction with fact tables for product-based analysis. It enables businesses to segment and analyze data by product categories, which is crucial for market analysis, inventory management, and sales strategy. + +Example: +SELECT * FROM [CH01-01-Dimension].[DimProductCategory] +WHERE ProductCategoryKey = 10; + +This example retrieves information about the product category with a ProductCategoryKey of 10. + +Note: Maintaining the accuracy and consistency of the data in this table, especially the UserAuthorizationKey, is crucial for ensuring the integrity and reliability of the data warehouse. + +*/ + + SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON @@ -1037,7 +1289,38 @@ AS FROM [CH01-01-Dimension].[DimProductCategory] GO --- Table 2 +/* +Table: [CH01-01-Dimension].[DimProductSubCategory] + +Description: +The DimProductSubCategory table is a dimension table within the data warehouse schema, designed to further categorize products into subcategories. This table links each subcategory to a broader product category, and it includes a unique identifier for each subcategory, along with a descriptive name. Additionally, the table tracks user authorization details and timestamps for the creation and update of records. + +Columns: +- ProductSubcategoryKey: The primary key of the table, an integer uniquely identifying each product subcategory. +- ProductCategoryKey: An integer foreign key that references the ProductCategory dimension, linking the subcategory to its parent category. +- ProductSubcategory: A varchar(20) field providing the name or description of the product subcategory. +- UserAuthorizationKey: An integer foreign key linking to the UserAuthorization table, denoting the user responsible for creating or updating the record. This key is crucial for auditing and data governance. +- DateAdded: The datetime2(7) timestamp when the record was added to the table. +- DateOfLastUpdate: The datetime2(7) timestamp when the record was last updated. + +Primary Key: +- The primary key is [ProductSubcategoryKey], ensuring unique identification of each product subcategory. + +Index and Statistics Options: +- Configured with PAD_INDEX, STATISTICS_NORECOMPUTE, IGNORE_DUP_KEY, ALLOW_ROW_LOCKS, and ALLOW_PAGE_LOCKS for optimal performance. OPTIMIZE_FOR_SEQUENTIAL_KEY is disabled. + +Usage: +The DimProductSubCategory table is used alongside fact tables for detailed product-based analysis, allowing for segmentation and analysis at a more granular subcategory level. This is essential for detailed market analysis, inventory management, and sales strategy formulation. + +Example: +SELECT * FROM [CH01-01-Dimension].[DimProductSubCategory] +WHERE ProductSubcategoryKey = 200; + +This example retrieves information about the product subcategory with a ProductSubcategoryKey of 200. + +Note: It is important to maintain data integrity and consistency in this table, particularly concerning the UserAuthorizationKey, to ensure the reliability and auditability of the data. +*/ + SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON @@ -1064,37 +1347,13 @@ GO SET QUOTED_IDENTIFIER ON GO -CREATE VIEW G9_1.[uvw_DimProductSubCategory] +CREATE VIEW [G9_1].[uvw_DimProductSubCategory] AS SELECT ProductSubCategoryKey, ProductCategoryKey, ProductSubcategory, UserAuthorizationKey, DateAdded, DateOfLastUpdate FROM [CH01-01-Dimension].[DimProductSubCategory] GO --- ProductCategories Table - -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -CREATE TABLE FileUpload.[ProductCategories] -( - [ProductCategory] [varchar](20) NOT NULL -) ON [PRIMARY] -GO - --- ProductSubcategories Table - -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -CREATE TABLE FileUpload.[ProductSubcategories] -( - [ProductSubcategory] [varchar](20) NOT NULL -) ON [PRIMARY] -GO - /* Table: Process.[WorkflowSteps] @@ -1140,6 +1399,43 @@ CREATE TABLE Process.[WorkflowSteps] ) ON [PRIMARY] GO +----- Misc product tables from BIClass---- + +-- ProductCategories Table +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [FileUpload].[ProductCategories] +( + [ProductCategory] [varchar](20) NOT NULL +) ON [PRIMARY] +GO + +-- ProductSubcategories Table +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [FileUpload].[ProductSubcategories] +( + [ProductSubcategory] [varchar](20) NOT NULL +) ON [PRIMARY] +GO + +----------------- Prepopulating the UserAuthorization Table with the Group Names ------------- + +INSERT INTO [DbSecurity].[UserAuthorization] +([GroupMemberLastName],[GroupMemberFirstName]) +VALUES + + ('Georgievska','Aleksandra'), + ('Yakubova','Sigalita'), + ('Kong','Nicholas'), + ('Wray','Edwin'), + ('Ahmed','Ahnaf'), + ('Richman','Aryeh'); +GO --------------------- Alter Tables To Update Defaults/Constraints ------------------- @@ -1223,20 +1519,6 @@ ALTER TABLE Process.[WorkflowSteps] ADD DEFAULT (sysdatetime()) FOR [EndingDate GO ALTER TABLE Process.[WorkflowSteps] ADD DEFAULT ('9:15') FOR [Class Time] GO - -INSERT INTO [DbSecurity].[UserAuthorization] -([GroupMemberLastName],[GroupMemberFirstName]) -VALUES - - ('Georgievska','Aleksandra'), - ('Yakubova','Sigalita'), - ('Kong','Nicholas'), - ('Wray','Edwin'), - ('Ahmed','Ahnaf'), - ('Richman','Aryeh'); -GO - - ALTER TABLE [CH01-01-Dimension].[DimCustomer] WITH CHECK ADD CONSTRAINT [FK_DimCustomer_UserAuthorization] FOREIGN KEY([UserAuthorizationKey]) REFERENCES [DbSecurity].[UserAuthorization] ([UserAuthorizationKey]) GO @@ -1351,17 +1633,37 @@ GO -------------- Create Stored Procedures -------------- --- ShowWorkflowSteps +/* +Stored Procedure: Process.[usp_ShowWorkflowSteps] + +Description: +This stored procedure is designed to retrieve and display all records from the Process.[WorkFlowSteps] table. It is intended to provide a comprehensive view of all workflow steps that have been logged in the system, offering insights into the various processes and their execution details. + +Operations: +- The procedure sets NOCOUNT ON to prevent the return of the count of affected rows, thereby enhancing performance and reducing network traffic. +- A simple SELECT statement retrieves all records from the Process.[WorkFlowSteps] table, providing details such as the description of the workflow step, the start and end times, the number of rows affected, and the user authorization key associated with each step. + +Usage: +This procedure is particularly useful for administrators and analysts who need to audit or review the history of workflow steps executed in the system. It allows for an easy overview of the entire workflow history, which can be crucial for process optimization, troubleshooting, and compliance purposes. + +Example: +EXEC Process.[usp_ShowWorkflowSteps]; + +This example executes the stored procedure to retrieve and display all workflow steps from the Process.[WorkFlowSteps] table. + +Note: The effectiveness of this procedure depends on the accurate and consistent logging of workflow steps in the Process.[WorkFlowSteps] table. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Aleksandra Georgievska -- Create date: 11/13/23 -- Description: Show table of all workflow steps -- ============================================= +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Process.[usp_ShowWorkflowSteps] AS BEGIN @@ -1374,20 +1676,43 @@ END GO /* -Process.[usp_TrackWorkFlow], is used to insert records into the [WorkflowSteps] table. -When a workflow step is initiated, the procedure would be called with the appropriate -parameters, and it would log the activity in the table. -*/ -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO +Stored Procedure: Process.[usp_TrackWorkFlow] + +Description: +This stored procedure is designed to track and log each step of various workflows within the system. It inserts records into the [WorkflowSteps] table, capturing key details about each workflow step, such as its description, the number of table rows affected, and the start and end times. This procedure is instrumental in maintaining an audit trail and enhancing transparency in automated processes. + +Parameters: +- @WorkflowDescription: NVARCHAR(100) describing the workflow step. +- @WorkFlowStepTableRowCount: INT indicating the number of rows affected or processed during the workflow step. +- @StartingDateTime: DATETIME2 marking when the workflow step began. +- @EndingDateTime: DATETIME2 marking when the workflow step ended. +- @UserAuthorizationKey: INT identifying the user who initiated or is responsible for the workflow step, crucial for auditing purposes. + +Usage: +This procedure should be invoked at the start and end of each significant workflow step within automated processes or ETL jobs. It ensures that all workflow activities are logged, which aids in monitoring, troubleshooting, and analyzing process efficiency and user activity. + +Example: +EXEC Process.[usp_TrackWorkFlow] + @WorkflowDescription = 'Data Load Step 1', + @WorkFlowStepTableRowCount = 100, + @StartingDateTime = '2023-11-13T08:00:00', + @EndingDateTime = '2023-11-13T08:30:00', + @UserAuthorizationKey = 5; + +This example logs a workflow step described as 'Data Load Step 1', indicating that 100 rows were affected, starting at 8:00 AM and ending at 8:30 AM on November 13, 2023, performed by the user with authorization key 5. + +Note: Proper usage of this stored procedure is essential for accurate and reliable workflow tracking. It should be consistently implemented across all relevant workflows for effective auditability and process analysis. + -- ============================================= -- Author: Aleksandra Georgievska -- Create date: 11/13/23 -- Description: Keep track of all workflow steps -- ============================================= - +*/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Process.[usp_TrackWorkFlow] -- Add the parameters for the stored procedure here @WorkflowDescription NVARCHAR(100), @@ -1418,18 +1743,41 @@ BEGIN END; GO +/* +Stored Procedure: Project2.[AddForeignKeysToStarSchemaData] --- AddForeignKeysToStarSchemaData +Description: +This procedure is responsible for establishing foreign key relationships across various tables in the star schema database. It adds constraints to link fact and dimension tables to ensure referential integrity. The procedure also associates dimension tables with the UserAuthorization table, thereby establishing a traceable link between data records and the users responsible for their creation or updates. + +Parameters: +- @UserAuthorizationKey: INT representing the user authorizing this operation, used for auditing purposes. + +Operations: +1. Adds foreign key constraints to the [CH01-01-Fact].[Data] table, linking it to various dimension tables like DimCustomer, DimGender, DimMaritalStatus, etc. +2. Adds foreign key constraints to dimension tables, linking them to the [DbSecurity].[UserAuthorization] table. +3. Tracks the process using Process.[usp_TrackWorkFlow] to maintain an audit trail of the operation. + +Usage: +This procedure should be executed when setting up the database schema or when modifications to the schema are required. It ensures data integrity across the star schema by enforcing appropriate foreign key relationships. + +Example: +EXEC Project2.[AddForeignKeysToStarSchemaData] @UserAuthorizationKey = 5; + +This example runs the procedure to add foreign keys across tables, authorized by the user with key 5. + +Note: Proper execution of this procedure is critical to maintain data integrity and referential relationships in the star schema database. It should be executed with caution, ensuring that no data inconsistencies exist that could be affected by the new constraints. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Aleksandra Georgievska -- Create date: 11/13/23 -- Description: Add the foreign keys to the start Schema database -- ============================================= +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE [Project2].[AddForeignKeysToStarSchemaData] @UserAuthorizationKey INT AS @@ -1538,17 +1886,41 @@ BEGIN END; GO --- DropForeignKeysFromStarSchemaData +/* +Stored Procedure: Project2.[DropForeignKeysFromStarSchemaData] + +Description: +This procedure is designed to remove foreign key constraints from various tables in the star schema database. It primarily focuses on dropping constraints that link fact and dimension tables as well as the constraints linking dimension tables to the UserAuthorization table. This is typically performed in preparation for data loading operations that require constraint-free bulk data manipulations. + +Parameters: +- @UserAuthorizationKey: INT indicating the user authorizing the operation, used for auditing. + +Operations: +1. Drops foreign key constraints from the [CH01-01-Fact].[Data] table and various dimension tables, ensuring the removal of referential integrity constraints. +2. Logs the procedure execution using Process.[usp_TrackWorkFlow] for audit trails, tracking the start and end times, and user responsibility. + +Usage: +Execute this procedure before performing bulk data load operations or schema alterations that might be hindered by existing foreign key constraints. It ensures that data modifications can be performed without constraint violations. + +Example: +EXEC Project2.[DropForeignKeysFromStarSchemaData] @UserAuthorizationKey = 5; + +This example runs the procedure to drop foreign keys across the star schema tables, authorized by the user with key 5. + +Note: Care should be taken when executing this procedure as dropping foreign keys can temporarily weaken data integrity. Ensure to re-establish the foreign keys after the required operations are completed. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Aleksandra Georgievska -- Create date: 11/13/23 -- Description: Drop the foreign keys from the start Schema database -- ============================================= + +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE [Project2].[DropForeignKeysFromStarSchemaData] @UserAuthorizationKey INT AS @@ -1614,20 +1986,17 @@ Usage: The procedure should be executed when there is a need to refresh the data in the fact table as part of regular ETL operations. It ensures that all data handling is audited and associated with a specific user. -*/ - -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Sigalita Yakubova -- Create date: 11/13/23 -- Description: Fill in the data table -- ============================================= --- DROP PROC IF EXISTS Project2.[Load_Data] --- GO +*/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_Data] @UserAuthorizationKey INT AS @@ -1787,17 +2156,42 @@ BEGIN END; GO --- Load_DimProductCategory Procedure +/* +Stored Procedure: Project2.[Load_DimProductCategory] + +Description: +This procedure is designed for loading data into the [CH01-01-Dimension].[DimProductCategory] dimension table. It inserts data from the FileUpload.OriginallyLoadedData source, focusing on the ProductCategory column. The procedure also handles the tracking of data load operations with timestamps and user authorization keys. + +Parameters: +- @UserAuthorizationKey: INT representing the user performing the data loading operation, used for auditing purposes. + +Operations: +1. Inserts distinct ProductCategory values from FileUpload.OriginallyLoadedData into DimProductCategory. +2. Sets UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each new record. +3. Creates or updates a view named G9_1.uvw_DimProductCategory to reflect the updated state of the DimProductCategory table. +4. Logs the procedure execution using Process.[usp_TrackWorkFlow], capturing details such as the number of rows affected and the start and end times of the operation. + +Usage: +Execute this procedure to refresh or populate the DimProductCategory table with new data. It is particularly useful during ETL processes or when updating the dimension table with new category information. + +Example: +EXEC Project2.[Load_DimProductCategory] @UserAuthorizationKey = 10; + +This example populates the DimProductCategory table with data, authorized by the user with key 10. + +Note: This procedure should be used with caution to ensure that the data integrity of the dimension table is maintained. Proper authorization and validation of the input data are essential to prevent data quality issues. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Sigalita Yakubova -- Create date: 11/13/23 --- Description: Fill in the product category table +-- Description: Fills in the product category table -- ============================================= +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_DimProductCategory] @UserAuthorizationKey INT AS @@ -1854,18 +2248,43 @@ BEGIN END; GO +/* +Stored Procedure: Project2.[Load_DimProductSubcategory] + +Description: +This procedure is designed for loading data into the [CH01-01-Dimension].[DimProductSubCategory] dimension table. It inserts data from the FileUpload.OriginallyLoadedData source, focusing on the ProductSubcategory column and linking it to the appropriate ProductCategoryKey. The procedure also manages tracking data load operations with timestamps and user authorization keys. + +Parameters: +- @UserAuthorizationKey: INT indicating the user responsible for the data loading operation, used for auditing purposes. + +Operations: +1. Inserts distinct ProductSubcategory values from FileUpload.OriginallyLoadedData into DimProductSubCategory, along with the corresponding ProductCategoryKey. +2. Sets UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each new record. +3. Creates or updates a view named G9_1.uvw_DimProductSubCategory to reflect the updated state of the DimProductSubCategory table. +4. Logs the procedure execution using Process.[usp_TrackWorkFlow], capturing details like the number of rows affected, start and end times of the operation. + +Usage: +Execute this procedure to refresh or populate the DimProductSubCategory table with new data. It is particularly useful during ETL processes or when updating the dimension table with new subcategory information. + +Example: +EXEC Project2.[Load_DimProductSubcategory] @UserAuthorizationKey = 15; + +This example populates the DimProductSubCategory table with data, authorized by the user with key 15. + +Note: Care should be exercised when using this procedure to ensure the integrity of the dimension table. Proper authorization and validation of the input data are crucial to avoid data quality issues. + +-- ============================================= +-- Author: Sigalita Yakubova +-- Create date: 11/13/23 +-- Description: Fill in the product SUBcategory table +-- ============================================= --- Load_DimProductSubcategory Procedure +*/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --- ============================================= --- Author: Sigalita Yakubova --- Create date: 11/13/23 --- Description: Fill in the product SUBcategory table --- ============================================= CREATE OR ALTER PROCEDURE Project2.[Load_DimProductSubcategory] @UserAuthorizationKey INT AS @@ -1927,17 +2346,42 @@ BEGIN END; GO --- Load_DimCustomer Procedure +/* +Stored Procedure: Project2.[Load_DimCustomer] + +Description: +This procedure is tasked with loading data into the [CH01-01-Dimension].[DimCustomer] dimension table. It primarily focuses on inserting customer-related data from the FileUpload.OriginallyLoadedData source. Along with the customer names, the procedure also manages auditing fields such as the UserAuthorizationKey and timestamps for when records are added or updated. + +Parameters: +- @UserAuthorizationKey: INT representing the user performing the data loading operation, used for auditing purposes. + +Operations: +1. Inserts CustomerName from the FileUpload.OriginallyLoadedData into the DimCustomer table. +2. Sets the UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each record. +3. Manages an accompanying view (G9_1.uvw_DimCustomer) to reflect the current state of the DimCustomer table. +4. Uses Process.[usp_TrackWorkFlow] to log the procedure execution, including details on the number of rows affected and the operation's start and end times. + +Usage: +Run this procedure to populate or update the DimCustomer table with new customer data. It is essential for ETL processes and updating the dimension table with fresh data. + +Example: +EXEC Project2.[Load_DimCustomer] @UserAuthorizationKey = 20; + +This command executes the procedure, loading customer data into the DimCustomer table, with the operation being authorized by the user with key 20. + +Note: It is important to use this procedure carefully to maintain the integrity of the dimension table. Proper authorization and validation of input data are crucial to avoid compromising data quality. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Nicholas Kong -- Create date: 11/13/2023 -- Description: Populate the customer table -- ============================================= +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_DimCustomer] @UserAuthorizationKey INT AS @@ -1986,17 +2430,42 @@ BEGIN END GO --- Load_DimGender Procedure +/* +Stored Procedure: Project2.[Load_DimGender] + +Description: +This procedure is responsible for loading gender data into the [CH01-01-Dimension].[DimGender] table. It sources the data from FileUpload.OriginallyLoadedData, focusing on distinct gender values and providing a descriptive label for each. The procedure also handles the tracking of data load operations, including user authorization keys and timestamps for record creation and updates. + +Parameters: +- @UserAuthorizationKey: INT indicating the user responsible for the data loading operation, used for auditing purposes. + +Operations: +1. Inserts Gender and GenderDescription into the DimGender table. +2. Assigns UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each record. +3. Manages an accompanying view (G9_1.uvw_DimGender) to reflect the current state of the DimGender table. +4. Utilizes Process.[usp_TrackWorkFlow] to log the execution of the procedure, capturing details such as the number of rows affected and the operation's start and end times. + +Usage: +Execute this procedure to populate or update the DimGender table with gender data. It is crucial during ETL processes or when the dimension table needs to be refreshed with new or updated gender information. + +Example: +EXEC Project2.[Load_DimGender] @UserAuthorizationKey = 25; + +This example populates the DimGender table with data, authorized by the user with key 25. + +Note: It is important to use this procedure with care to ensure the integrity of the dimension table. Proper authorization and validation of the input data are essential to prevent data quality issues. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Nicholas Kong -- Create date: 11/13/2023 -- Description: Populate the gender table -- ============================================= +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_DimGender] @UserAuthorizationKey INT AS @@ -2044,17 +2513,41 @@ BEGIN END; GO --- TruncateStarSchemaData Procedure -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO +/* +Stored Procedure: Project2.[TruncateStarSchemaData] + +Description: +This procedure is designed to truncate tables in the star schema of the data warehouse. It removes all records from specified dimension and fact tables and restarts the associated sequences. This action is essential for data refresh scenarios where existing data needs to be cleared before loading new data. + +Parameters: +- @UserAuthorizationKey: INT representing the user authorizing the truncation operation, used for auditing purposes. + +Operations: +1. Truncates each specified dimension and fact table within the [CH01-01-Dimension] and [CH01-01-Fact] schemas. +2. Resets the sequences associated with these tables to their initial values. +3. Logs the execution of the truncation process using Process.[usp_TrackWorkFlow], capturing details like the operation's start and end times, and user responsibility. + +Usage: +Execute this procedure before performing bulk data load operations or when resetting the data warehouse for a fresh data import. It is particularly useful for maintaining a clean state in development or test environments or when reinitializing the data warehouse. + +Example: +EXEC Project2.[TruncateStarSchemaData] @UserAuthorizationKey = 30; + +This example executes the procedure to truncate the star schema tables, authorized by the user with key 30. + +Note: This procedure should be used with extreme caution as it will irreversibly remove all data from the specified tables. Ensure that backups are taken or data is otherwise preserved if needed before executing this procedure. + -- ============================================= -- Author: Nicholas Kong -- Create date: 11/13/2023 -- Description: Truncate the star schema -- ============================================= +*/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[TruncateStarSchemaData] @UserAuthorizationKey int @@ -2097,22 +2590,42 @@ END GO +/* +Stored Procedure: Project2.[Load_DimMaritalStatus] + +Description: +This procedure is designed for loading marital status data into the [CH01-01-Dimension].[DimMaritalStatus] dimension table. It pulls distinct marital status values from the FileUpload.OriginallyLoadedData source, providing a descriptive label for each status. The procedure also manages auditing fields, such as the UserAuthorizationKey, and timestamps for when records are added or updated. + +Parameters: +- @UserAuthorizationKey: INT indicating the user responsible for the data loading operation, used for auditing purposes. +Operations: +1. Inserts MaritalStatus and MaritalStatusDescription into the DimMaritalStatus table. +2. Assigns UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each record. +3. Manages an accompanying view (G9_1.uvw_DimMaritalStatus) to reflect the current state of the DimMaritalStatus table. +4. Utilizes Process.[usp_TrackWorkFlow] to log the execution of the procedure, capturing details such as the number of rows affected, start and end times of the operation. --- Load_DimMaritalStatus Procedure +Usage: +Execute this procedure to populate or update the DimMaritalStatus table with marital status data. It is crucial during ETL processes or when the dimension table needs a refresh with new or updated marital status information. +Example: +EXEC Project2.[Load_DimMaritalStatus] @UserAuthorizationKey = 20; -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO +This command populates the DimMaritalStatus table with data, authorized by the user with key 20. + +Note: Care should be exercised when using this procedure to ensure the integrity of the dimension table. Proper authorization and validation of the input data are essential to prevent data quality issues. -- ============================================= -- Author: Edwin Wray -- Create date: 11/13/2023 -- Description: Populate the marital status table -- ============================================= +*/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_DimMaritalStatus] @UserAuthorizationKey INT AS @@ -2172,20 +2685,42 @@ BEGIN FROM G9_1.uvw_DimMaritalStatus; END; GO +/* +Stored Procedure: Project2.[Load_DimOccupation] --- Load_DimOccupation Procedure +Description: +This procedure is responsible for loading occupation data into the [CH01-01-Dimension].[DimOccupation] table. It takes distinct occupation data from the FileUpload.OriginallyLoadedData source, ensuring each record is unique. The procedure also manages the audit trail by including user authorization keys and timestamps for the addition and last update of each record. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO +Parameters: +- @UserAuthorizationKey: INT specifying the user performing the data loading operation, crucial for audit purposes. + +Operations: +1. Inserts unique Occupation values into the DimOccupation table. +2. Sets UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each new record. +3. Manages an accompanying view (G9_1.uvw_DimOccupation) to reflect the updated state of the DimOccupation table. +4. Logs the procedure execution using Process.[usp_TrackWorkFlow], capturing details such as the number of rows affected, the start and end times of the operation. + +Usage: +Run this procedure to populate or refresh the DimOccupation table with new occupation data. Essential for ETL processes or when updating the dimension table with new occupation information. + +Example: +EXEC Project2.[Load_DimOccupation] @UserAuthorizationKey = 35; + +This example executes the procedure to load data into the DimOccupation table, authorized by the user with key 35. + +Note: Care must be taken to ensure the integrity of the dimension table. Proper authorization and validation of input data are vital to maintain data quality. -- ============================================= -- Author: Edwin Wray -- Create date: 11/13/2023 -- Description: Populate the occupation table -- ============================================= +*/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_DimOccupation] @UserAuthorizationKey INT AS @@ -2235,19 +2770,42 @@ BEGIN END GO --- Load_DimTerritory Procedure +/* +Stored Procedure: Project2.[Load_DimTerritory] -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO +Description: +This procedure is designed to load territorial data into the [CH01-01-Dimension].[DimTerritory] table. It extracts distinct territorial information from the FileUpload.OriginallyLoadedData source and inserts it into the table. The procedure is also responsible for managing the audit trail, including user authorization keys and timestamps for each record's creation and last update. + +Parameters: +- @UserAuthorizationKey: INT indicating the user responsible for the data loading operation, crucial for maintaining an audit trail. + +Operations: +1. Inserts unique territorial data (TerritoryRegion, TerritoryCountry, TerritoryGroup) into the DimTerritory table. +2. Assigns the UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each new record. +3. Manages a corresponding view (G9_1.uvw_DimTerritory) to provide a current representation of the DimTerritory table. +4. Logs the execution of the procedure using Process.[usp_TrackWorkFlow], capturing details such as the number of rows affected, start and end times of the operation. + +Usage: +Execute this procedure to populate or update the DimTerritory table with territorial data. It is vital for ETL processes or when updating the dimension table with fresh territorial information. + +Example: +EXEC Project2.[Load_DimTerritory] @UserAuthorizationKey = 40; + +This example populates the DimTerritory table with data, authorized by the user with key 40. + +Note: It is important to use this procedure carefully to ensure the integrity of the dimension table. Proper authorization and validation of input data are essential to prevent data quality issues. -- ============================================= -- Author: Edwin Wray -- Create date: 11/13/2023 -- Description: Populate the Territory table -- ============================================= +*/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_DimTerritory] @UserAuthorizationKey int @@ -2304,19 +2862,43 @@ BEGIN END GO +/* +Stored Procedure: Project2.[Load_DimOrderDate] --- Load_DimOrderDate Procedure +Description: +This procedure is tasked with loading order date data into the [CH01-01-Dimension].[DimOrderDate] table. It focuses on inserting distinct order date details, including the date, month name, month number, and year, from the FileUpload.OriginallyLoadedData source. The procedure also manages the audit trail by incorporating user authorization keys and timestamps for the addition and last update of each record. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO +Parameters: +- @UserAuthorizationKey: INT specifying the user responsible for the data loading operation, crucial for maintaining an audit trail. + +Operations: +1. Inserts unique order date details into the DimOrderDate table. +2. Sets UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each new record. +3. Manages an accompanying view (G9_1.uvw_DimOrderDate) to represent the current state of the DimOrderDate table. +4. Utilizes Process.[usp_TrackWorkFlow] to log the procedure's execution, capturing details such as the number of rows affected, start and end times of the operation. + +Usage: +Run this procedure to populate or update the DimOrderDate table with order date data. Essential for ETL processes or when updating the dimension table with new date information. + +Example: +EXEC Project2.[Load_DimOrderDate] @UserAuthorizationKey = 45; + +This command executes the procedure to load data into the DimOrderDate table, authorized by the user with key 45. + +Note: Care should be taken to ensure the integrity of the dimension table. Proper authorization and validation of input data are vital to avoid compromising data quality. -- ============================================= -- Author: Ahnaf Ahmed -- Create date: 11/13/2023 -- Description: Load the order date information into the table -- ============================================= +*/ + + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_DimOrderDate] @UserAuthorizationKey INT AS @@ -2377,13 +2959,30 @@ BEGIN END GO +/* +Stored Procedure: Project2.[Load_SalesManagers] + +Description: +The Project2.[Load_SalesManagers] procedure is designed to load sales manager data into the [CH01-01-Dimension].[SalesManagers] table. It extracts data from the FileUpload.OriginallyLoadedData source, focusing on unique SalesManager names and their associated categories. The procedure also handles the auditing aspect by including user authorization keys and timestamps for each record's creation and last update. --- Load_SalesManagers Procedure +Parameters: +- @UserAuthorizationKey: INT specifying the user responsible for the data loading operation, crucial for maintaining an audit trail. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO +Operations: +1. Inserts distinct SalesManager and Category data into the SalesManagers table. +2. Assigns the UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each new record. +3. Manages an accompanying view (G9_1.uvw_SalesManagers) to represent the updated state of the SalesManagers table. +4. Utilizes Process.[usp_TrackWorkFlow] to log the execution of the procedure, capturing details such as the number of rows affected, start and end times of the operation. + +Usage: +Run this procedure to populate or update the SalesManagers table with new sales manager data. It is vital during ETL processes or when refreshing the dimension table with updated sales manager information. + +Example: +EXEC Project2.[Load_SalesManagers] @UserAuthorizationKey = 50; + +This command executes the procedure to load sales manager data into the SalesManagers table, authorized by the user with key 50. + +Note: It is important to use this procedure carefully to ensure the integrity of the dimension table. Proper authorization and validation of input data are essential to avoid data quality issues. -- ============================================= -- Author: Ahnaf Ahmed @@ -2391,6 +2990,12 @@ GO -- Description: Load the Sales Manager information into the table -- ============================================= +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_SalesManagers] @UserAuthorizationKey int @@ -2446,18 +3051,40 @@ BEGIN END; GO +/* +Stored Procedure: Utils.[DropProcsInCSCI331FinalProject] --- DropProcsInCSCI331FinalProject Procedure +Description: +This procedure is specifically designed to drop a series of stored procedures associated with the CSCI331 Final Project. It ensures the removal of specific procedures from the database, typically as part of a cleanup, restructuring, or decommissioning process. The procedure also handles the tracking of this operation by including a user authorization key and timestamps. + +Parameters: +- @UserAuthorizationKey: INT indicating the user authorizing this operation, used for audit purposes. + +Operations: +1. Drops a predefined list of stored procedures related to the Project2 and Process schemas. +2. Utilizes Process.[usp_TrackWorkFlow] to log the execution of the procedure, including details like the operation's start and end times and the user's authorization key. + +Usage: +Execute this procedure to remove specific stored procedures from the database as part of maintenance or when restructuring the database setup. It's particularly useful for ensuring a clean and controlled environment, either for development or post-project cleanup. + +Example: +EXEC Utils.[DropProcsInCSCI331FinalProject] @UserAuthorizationKey = 55; + +This command executes the procedure to drop the specified stored procedures, authorized by the user with key 55. + +Note: Care must be taken when executing this procedure as it will irreversibly remove the specified stored procedures from the database. Ensure that this operation is part of a planned maintenance or cleanup process and that all necessary backups or documentation are in place. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Ahnaf Ahmed -- Create date: 11/13/2023 -- Description: Run the DropProcsInCSCI331FinalProject procedure -- ============================================= +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Utils.[DropProcsInCSCI331FinalProject] @UserAuthorizationKey INT AS @@ -2495,18 +3122,42 @@ BEGIN END; GO +/* +Stored Procedure: Project2.[Load_DimProduct] ---- Load_DimProduct Procedure +Description: +This procedure is designed to load product data into the [CH01-01-Dimension].[DimProduct] table. It extracts and inserts distinct product information from the FileUpload.OriginallyLoadedData source, including product categories, subcategories, codes, names, colors, and model names. Additionally, the procedure manages the audit trail by incorporating user authorization keys and timestamps for each record's creation and last update. + +Parameters: +- @UserAuthorizationKey: INT specifying the user responsible for the data loading operation, crucial for maintaining an audit trail. + +Operations: +1. Inserts unique product data into the DimProduct table. +2. Sets UserAuthorizationKey, DateAdded, and DateOfLastUpdate for each new record. +3. Manages an accompanying view (G9_1.uvw_DimProduct) to represent the updated state of the DimProduct table. +4. Utilizes Process.[usp_TrackWorkFlow] to log the execution of the procedure, capturing details such as the number of rows affected, start and end times of the operation. + +Usage: +Execute this procedure to populate or update the DimProduct table with new product data. It is essential for ETL processes or when updating the dimension table with new product information. + +Example: +EXEC Project2.[Load_DimProduct] @UserAuthorizationKey = 60; + +This command executes the procedure to load data into the DimProduct table, authorized by the user with key 60. + +Note: Care should be taken to ensure the integrity of the dimension table. Proper authorization and validation of input data are vital to avoid data quality issues. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Aryeh Richman -- Create date: 11/13/23 -- Description: Populate the product table -- ============================================= +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[Load_DimProduct] @UserAuthorizationKey INT AS @@ -2586,18 +3237,42 @@ BEGIN END; GO +/* +Stored Procedure: Project2.[ShowTableStatusRowCount] --- ShowTableStatusRowCount Procedure +Description: +This procedure is designed to report the row count of various tables in the database, providing a snapshot of the current data volume across different tables. It includes tables from the [CH01-01-Dimension], [CH01-01-Fact], [DbSecurity], and [Process] schemas. The procedure also logs this operation, including user authorization keys and timestamps, to maintain an audit trail. + +Parameters: +- @TableStatus: VARCHAR(64) representing the label or status description for the row count report. +- @UserAuthorizationKey: INT indicating the user responsible for the operation, used for auditing purposes. + +Operations: +1. Queries each specified table to calculate its row count. +2. Outputs the table name and its corresponding row count, along with the provided @TableStatus label. +3. Logs the execution using Process.[usp_TrackWorkFlow], capturing details such as the operation's start and end times and the user's authorization key. + +Usage: +Run this procedure to obtain a row count report of various tables, which can be useful for data auditing, capacity planning, or simply understanding the current data volume in different parts of the database. + +Example: +EXEC Project2.[ShowTableStatusRowCount] @TableStatus = 'Post-Load Analysis', @UserAuthorizationKey = 65; + +This example retrieves the row counts for various tables under the label 'Post-Load Analysis', authorized by the user with key 65. + +Note: This procedure is a utility tool for data monitoring and should be used accordingly. Ensure the correct interpretation of the row count data, especially in the context of data load operations or data audits. -SET ANSI_NULLS ON -GO -SET QUOTED_IDENTIFIER ON -GO -- ============================================= -- Author: Aryeh Richman -- Create date: 11/13/23 -- Description: Populate a table to show the status of the row counts -- ============================================= +*/ + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO CREATE OR ALTER PROCEDURE Project2.[ShowTableStatusRowCount] @TableStatus VARCHAR(64), @UserAuthorizationKey INT @@ -2738,17 +3413,17 @@ truncating existing data, loading new data into the dimensional and fact tables, workflow process. The use of @UserAuthorizationKey in various places suggests that the procedure includes some form of authorization or tracking mechanism based on the user executing the procedure. +-- ============================================= +-- Author: Aleksandra Georgievska +-- Create date: 11/14/23 +-- Description: Procedure runs other stored procedures to populate the data +-- ============================================= */ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --- ============================================= --- Author: Aleksandra Georgievska --- Create date: 11/14/23 --- Description: Procedure runs other stored procedures to populate the data --- ============================================= CREATE OR ALTER PROCEDURE [Project2].[LoadStarSchemaData] @UserAuthorizationKey INT AS