|
| 1 | +# Dedicated SQL Pool: Store Procedure Dynamically Remove Space |
| 2 | + |
| 3 | +Costa Rica |
| 4 | + |
| 5 | +[](https://github.com) |
| 6 | +[](https://github.com/) |
| 7 | +[brown9804](https://github.com/brown9804) |
| 8 | + |
| 9 | +Last updated: 2025-01-24 |
| 10 | + |
| 11 | +---------- |
| 12 | + |
| 13 | +## Wiki |
| 14 | + |
| 15 | +<details> |
| 16 | +<summary><b>List of References </b> (Click to expand)</summary> |
| 17 | + |
| 18 | + |
| 19 | +</details> |
| 20 | + |
| 21 | +## Content |
| 22 | + |
| 23 | +<details> |
| 24 | +<summary><b>Table of Content </b> (Click to expand)</summary> |
| 25 | + |
| 26 | + |
| 27 | +</details> |
| 28 | + |
| 29 | +## Demo |
| 30 | + |
| 31 | +### Set Up a Dedicated SQL Pool |
| 32 | + |
| 33 | +1. **Sign in to the Azure Portal**: Go to the Azure Portal and sign in with your Azure account. |
| 34 | +2. **Navigate to Your Synapse Workspace**: In the Azure Portal, search for your Synapse workspace or create a new one if you don't have one. |
| 35 | + |
| 36 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/92a5e451-1868-47e2-b32b-858591c306ee" /> |
| 37 | + |
| 38 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/51e3b091-855d-4481-89e0-623705e3cf2a" /> |
| 39 | + |
| 40 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/7d03bfa8-e1e3-4706-970f-a89c7b8cd904" /> |
| 41 | + |
| 42 | +### Create a Dedicated SQL Pool |
| 43 | + |
| 44 | +1. **Launch Synapse Studio**: From the Synapse workspace overview, click on the `Open Synapse Studio` button. |
| 45 | + |
| 46 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/302b1fd8-49a6-427e-93dc-8e952f1667e6" /> |
| 47 | + |
| 48 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/a368036b-c859-47fc-a1c5-d045b6910790" /> |
| 49 | + |
| 50 | +2. **Create a Dedicated SQL Pool**: |
| 51 | + - In Synapse Studio, go to the `Manage` hub by clicking on the `Manage` icon in the left navigation pane. |
| 52 | + - Under `Analytics pools`, select `SQL pools` and click on the `+ New` button. |
| 53 | + |
| 54 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/6d96ac07-57f1-4efd-917b-200a43091311" /> |
| 55 | + |
| 56 | + - Enter the following details: |
| 57 | + - **SQL pool name**: Enter a name for your SQL pool (e.g., `SQLPOOL1`). |
| 58 | + - **Performance level**: Choose a performance level (e.g., `DW1000c`). |
| 59 | + - Click `Review + create` and then `Create` to provision the dedicated SQL pool. |
| 60 | + |
| 61 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/89ca427b-20f1-4df5-ae20-847b76cdd9a7" /> |
| 62 | + |
| 63 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/b8b2c94b-76e6-4ced-8812-c386c6a55f32" /> |
| 64 | + |
| 65 | +### Create Tables with Spaces in Names and Columns |
| 66 | + |
| 67 | +1. **Open the SQL Script Editor**: |
| 68 | + - In Synapse Studio, go to the `Develop hub` by clicking on the `Develop` icon in the left navigation pane. |
| 69 | + - Click on `+ New SQL script` to open the SQL script editor. |
| 70 | + |
| 71 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/3382ea4a-06eb-4e32-93d9-569cef7fc2f5" /> |
| 72 | + |
| 73 | +2. **Create Sample Tables**: Use the following script to create tables with spaces in their names and columns. Click [here to see the .sql file](). |
| 74 | + |
| 75 | + ```sql |
| 76 | + -- Create sample tables with spaces in names |
| 77 | + CREATE TABLE [Employee Records] ( |
| 78 | + [Employee ID] INT, |
| 79 | + [Employee Name] NVARCHAR(255), |
| 80 | + [Employee Address] NVARCHAR(255) |
| 81 | + ); |
| 82 | + |
| 83 | + CREATE TABLE [Sales Data] ( |
| 84 | + [Sale ID] INT, |
| 85 | + [Sale Date] DATE, |
| 86 | + [Employee ID] INT, |
| 87 | + [Sale Amount] DECIMAL(10, 2) |
| 88 | + ); |
| 89 | + |
| 90 | + CREATE TABLE [Inventory Details] ( |
| 91 | + [Item ID] INT, |
| 92 | + [Item Name] NVARCHAR(255), |
| 93 | + [Item Category] NVARCHAR(255), |
| 94 | + [Item Price] DECIMAL(10, 2) |
| 95 | + ); |
| 96 | + |
| 97 | + -- Insert sample data into the tables |
| 98 | + INSERT INTO [Employee Records] ([Employee ID], [Employee Name], [Employee Address]) |
| 99 | + VALUES (1, 'Alice Johnson', '789 Pine St'); |
| 100 | + |
| 101 | + INSERT INTO [Employee Records] ([Employee ID], [Employee Name], [Employee Address]) |
| 102 | + VALUES (2, 'Bob Brown', '101 Maple St'); |
| 103 | + |
| 104 | + INSERT INTO [Sales Data] ([Sale ID], [Sale Date], [Employee ID], [Sale Amount]) |
| 105 | + VALUES (1, '2023-02-01', 1, 200.00); |
| 106 | + |
| 107 | + INSERT INTO [Sales Data] ([Sale ID], [Sale Date], [Employee ID], [Sale Amount]) |
| 108 | + VALUES (2, '2023-02-02', 2, 250.00); |
| 109 | + |
| 110 | + INSERT INTO [Inventory Details] ([Item ID], [Item Name], [Item Category], [Item Price]) |
| 111 | + VALUES (1, 'Gadget', 'Electronics', 49.99); |
| 112 | + |
| 113 | + INSERT INTO [Inventory Details] ([Item ID], [Item Name], [Item Category], [Item Price]) |
| 114 | + VALUES (2, 'Tool', 'Hardware', 29.99); |
| 115 | + ``` |
| 116 | + |
| 117 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/6f8a154d-2fcb-4aa5-bc9f-27f6b8334017" /> |
| 118 | + |
| 119 | +3. **Run the Script**: Execute the script in the SQL script editor to create the tables and insert sample data. |
| 120 | + |
| 121 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/1d02fd74-7246-4aa6-8247-b98619d70c47" /> |
| 122 | + |
| 123 | +> [!NOTE] |
| 124 | +> Once you refresh, the tables will be visible: |
| 125 | + |
| 126 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/3e6fc8a1-ad34-4a0b-8940-ae27b303190d"> |
| 127 | + |
| 128 | + ### Create Views with Modified Tables/Column Names |
| 129 | + |
| 130 | +1. **Create a Stored Procedure to Remove Spaces from Column Names**: Use the following script to create a stored procedure that removes spaces from column names and creates views. Click [here to see the .sql file](). |
| 131 | + |
| 132 | + ```sql |
| 133 | +
|
| 134 | + ``` |
| 135 | + |
| 136 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/13b3b5f2-3142-448f-b03a-3eeae00a1509" /> |
| 137 | + |
| 138 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/575905c1-bcf7-4800-981b-6ff4ab2b3302" /> |
| 139 | + |
| 140 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/a7244b21-c787-4f64-8689-fe66670aa86a" /> |
| 141 | + |
| 142 | +2. **Execute the Stored Procedure**: Click on `Run`, to create the stored procedure. |
| 143 | + |
| 144 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/17be4e92-9816-43ff-9cc3-23d9737a9056" /> |
| 145 | + |
| 146 | + | Before | After | |
| 147 | + | --- | --- | |
| 148 | + | <img width="550" alt="image" src="https://github.com/user-attachments/assets/d081329c-b5f6-452f-826b-50a2dd614a1c" /> | <img width="550" alt="image" src="https://github.com/user-attachments/assets/588aa482-ac5c-4013-b926-e01db58d1733" /> | |
| 149 | + |
| 150 | +3. Run the stored procedure to create views with modified column names. |
| 151 | + |
| 152 | + ```sql |
| 153 | + EXEC RemoveSpacesFromColumnNames |
| 154 | + ``` |
| 155 | + |
| 156 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/015b9c07-10f6-4895-bdba-4945e3277923" /> |
| 157 | + |
| 158 | + <img width="550" alt="image" src="https://github.com/user-attachments/assets/1ccf430e-1dff-4968-980c-a4f3913a8369" /> |
| 159 | + |
| 160 | +> [!NOTE] |
| 161 | +> Once you refresh, the views will be visible: |
| 162 | + |
| 163 | +| Before | After | |
| 164 | +| --- | --- | |
| 165 | +<img width="360" alt="image" src="https://github.com/user-attachments/assets/b0de5118-bf67-4f75-9dd7-2ae5ba33cb28" /> |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | +<div align="center"> |
| 173 | + <h3 style="color: #4CAF50;">Total Visitors</h3> |
| 174 | + <img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/> |
| 175 | +</div> |
0 commit comments