You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 0_Azure/2_AzureAnalytics/1_SynapseAnalytics/demos/2_synapse_views_dynamically_remove_space/0_serverlessSQLPool/README.md
+93-33Lines changed: 93 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,19 +10,20 @@ Last updated: 2025-01-26
10
10
11
11
----------
12
12
13
-
## Wiki
14
-
15
-
<details>
16
-
<summary><b>List of References </b> (Click to expand)</summary>
17
-
18
-
19
-
</details>
20
-
21
13
## Content
22
14
23
15
<details>
24
16
<summary><b>Table of Content </b> (Click to expand)</summary>
25
17
18
+
-[Content](#content)
19
+
-[Overview](#overview)
20
+
-[Demo](#demo)
21
+
-[Set Up a Synapse Workspace](#set-up-a-synapse-workspace)
22
+
-[Upload Sample Data to Storage Account](#upload-sample-data-to-storage-account)
23
+
-[Create User Database](#create-user-database)
24
+
-[Create an External Data Source and File Format](#create-an-external-data-source-and-file-format)
25
+
-[Create an External Table](#create-an-external-table)
26
+
-[Create Views with Modified Tables/Column Names](#create-views-with-modified-tablescolumn-names)
6. **Query the External Table**: You can now query the external table to see the sample data.
173
+
3. **Query the External Table**: You can now query the external table to see the sample data.
174
+
147
175
```sql
148
-
SELECT * FROM [Table With Spaces];
176
+
SELECT * FROM {Table Name};
149
177
```
150
178
179
+
### Create Views with Modified Tables/Column Names
151
180
181
+
> This script is designed to dynamically create views for each table in a database, renaming columns to remove spaces. It starts by creating a temporary table to store the SQL statements and assigns a unique row number to each statement. The script then loops through these statements, executing each one in turn. Finally, it cleans up by dropping the temporary table.
182
+
>1. **Temporary Table Creation**: A temporary table `#CreateViewStatements` is created to store the dynamic SQL statements and their corresponding row numbers. <br/>
183
+
>2. **Inserting SQL Statements**: The script generates SQL statements to create views for each table in the database. It uses the `INFORMATION_SCHEMA.COLUMNS` to get the table and column names, renaming columns to remove spaces. These statements, along with a row number, are inserted into the temporary table. <br/>
184
+
>3. **Variable Declaration**: Variables are declared to hold the current SQL statement, the current row number, and the maximum row number. <br/>
185
+
>4. **Getting Maximum Row Number**: The script retrieves the maximum row numberfrom the temporary table to determine how many statements need to be executed. <br/>
186
+
>5. **Executing SQL Statements**: A loop iterates through each row in the temporary table, retrieves the SQL statement, executes it, and increments the row number until all statements are executed. <br/>
187
+
>6. **Cleanup**: The temporary table is dropped to clean up after the script has finished executing. <br/>
152
188
189
+
```sql
190
+
-- Create a temporary table to store the dynamic SQL statements
0 commit comments