diff --git a/examples/0_intro.md b/examples/0_intro.md new file mode 100644 index 0000000..bfdb45f --- /dev/null +++ b/examples/0_intro.md @@ -0,0 +1,9 @@ +# Introductions + +1. How many people have Microsoft Flavor Databases at their company, that they are in some way responsible for? +2. How many people have heard about tools like + - msbuild/dotnet build + - tsqllint + - poorsql + - sqlpackage +3. How many people have version control for their TSQL? \ No newline at end of file diff --git a/examples/1_ms_build.md b/examples/1_ms_build.md new file mode 100644 index 0000000..cdf6ff4 --- /dev/null +++ b/examples/1_ms_build.md @@ -0,0 +1,27 @@ +# msbuild + +**What is MS-Build/dotnet-build?** + +`MSBuild is a build tool that helps automate the process of creating a software product, including compiling the source code, packaging, testing, deployment and creating documentations` + +**What Does it have to offer me, a database administrator/developer?** +- A chance to ensure your T-SQL Code Binds and Parses before running it on a database +- A chance to see generic recommendations about your database design +- The creation of an artifact, a .dacpac file, that can be used to create differential scripts + +## Show Me + +**Building a model of the files in a directory** +```bash +mv hows-the-weather/bin/Debug/net8.0/hows-the-weather.dacpac archive +dotnet build hows-the-weather/hows-the-weather.csproj +``` + +**An Example of no object to bind to** +```bash +#Update the ms_build_view.sql +dotnet build hows-the-weather/hows-the-weather.csproj +``` + + +so - How can we use this to our advantage? \ No newline at end of file diff --git a/examples/2_tsqllint.md b/examples/2_tsqllint.md new file mode 100644 index 0000000..dfc8742 --- /dev/null +++ b/examples/2_tsqllint.md @@ -0,0 +1,63 @@ +# tsqllint + +**What is tsqllint?** + +`TSQLLint is a tool for describing, identifying, and reporting the presence of anti-patterns in TSQL scripts.` + +[Github Repository](https://github.com/tsqllint/tsqllint) +SSMS Plugin Available! + +**What Does it have to offer me, a database administrator/developer?** +- A chance to give warnings or fail actions based on the presences of anti-patterns in tsql +- Enforcement of opinions at a user workstation or automation pipeline + +## Show Me + +**Building a model of the files in a directory** +```bash +tsqllint . --config .tsqllint +``` + +**An Example of Catching Select Star Queries** +```bash +#Update the ms_build_view.sql +tsqllint . --config .tsqllint +``` + +**Taking a look at an example configuration** +```json +{ + "rules": { + "case-sensitive-variables": "warning", + "conditional-begin-end": "warning", + "count-star": "warning", + "cross-database-transaction": "warning", + "data-compression": "off", + "data-type-length": "warning", + "delete-where": "warning", + "disallow-cursors": "warning", + "duplicate-empty-line" : "off", + "duplicate-go" : "warning", + "full-text": "warning", + "information-schema": "warning", + "keyword-capitalization": "warning", + "linked-server": "warning", + "multi-table-alias": "warning", + "named-constraint": "warning", + "non-sargable": "warning", + "object-property": "warning", + "print-statement": "warning", + "schema-qualify": "warning", + "select-star": "warning", + "semicolon-termination": "warning", + "set-variable": "warning", + "unicode-string" : "warning", + "update-where" : "warning", + "upper-lower": "warning" + }, + "compatibility-level": 150 +} +``` + + +so - How can we use this to our advantage? \ No newline at end of file diff --git a/examples/3_poorsql.md b/examples/3_poorsql.md new file mode 100644 index 0000000..b7936d5 --- /dev/null +++ b/examples/3_poorsql.md @@ -0,0 +1,34 @@ +# PoorSQL + +``` + This is a free and open-source SQL (T-SQL) formatter: + + - Handles complete multi-batch scripts, including object definition scripts such as stored procedures, triggers, etc. + - Provides formatting options to cater to different common formatting styles/standards + - Optionally outputs "colorized" html code rather than just the formatted SQL + - Also provides "minifier" option to strip out comments and whitespace, to obfuscate rather than pretty-print your code + - Available ready-to-use in a variety of forms + - SSMS (SQL Server Management Studio) and Visual Studio Addin/Extension that allows you to format the current file or selected text with a single hotkey - supports any version of SSMS or SSMS Express, and any Full (not Express) version of Visual Studio. + - Notepad++ plugin, for quick single-key formatting in your favorite general-purpose text editor. + - Command-line utility that lets you format any number of files in bulk, or format from some other arbitrary program - for windows (.Net) or any environment (node/npm) + - Winforms app for easy offline formatting (also lets you look at the token stream and parse tree) + - WinMerge plugin, for automatically formatting SQL files before comparison, allowing WinMerge to display content changes only, ignoring formatting differences. + - JS library that exposes the same functionality in any browser or other Javascript-based context, used in the demo/online formatting site http://poorsql.com + - Also available as a .Net 2.0/3.5 library, downloadable here or through NuGet + - Written in C# using a pluggable design that should allow for other SQL dialects to be supported in future +``` + +[Website](https://poorsql.com/) + +SSMS Plugin Available! + +**What Does it have to offer me, a database administrator/developer?** +- Opinionated format of tsql +- less cognative load deciphering other's writing style + +## Show Me +```bash +echo "select a from b join c on b.id = c.id where abc = 123 and def = N'whatêver' " | sqlformat + +echo "SeleCT a,b,c as d, e, f from f join g on f.id = g.id where x = 1 and y = 2 and z = 3 group by 1,2,3,4,5,6" | sqlformat +``` diff --git a/examples/4_sqlpackage.md b/examples/4_sqlpackage.md new file mode 100644 index 0000000..3de43b4 --- /dev/null +++ b/examples/4_sqlpackage.md @@ -0,0 +1,70 @@ +# sqlpackage + +``` + SqlPackage is a command-line utility that automates the database development tasks by exposing some of the public Data-Tier Application Framework (DacFx) APIs. The primary use cases for SqlPackage focus on database portability and deployments for the SQL Server, Azure SQL, and Azure Synapse Analytics family of databases. SqlPackage can be automated using Azure Pipelines and GitHub actions or other CI/CD tools. +``` + +[Website](https://learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage?view=sql-server-ver17) + +**What Does it have to offer me, a database administrator/developer?** +- Take the build (msbuild or dotnet build) of a database and deploy it against a target +- **only change what is not the same as the model** + +## Show Me +**Create a local sql server 2022 instance** +```bash +docker rm sql1 --force +docker run \ + -e "ACCEPT_EULA=Y" \ + -e "MSSQL_SA_PASSWORD=myadminpassword123*" \ + -p 1433:1433 \ + --name sql1 \ + --hostname sql1 \ + -d \ + mcr.microsoft.com/mssql/server:2022-latest +docker logs sql1 -f +``` + +**Create the "weather" db. Build and deploy the local model** +```bash +# Deploy database if not exists +sqlcmd \ + -S 127.0.0.1,1433 \ + -d master \ + -U sa \ + -P myadminpassword123* \ + -i scripts/create-db.sql \ + -C + +# Write datbase name to stdout +sqlcmd \ + -S 127.0.0.1,1433 \ + -d master \ + -U sa \ + -P myadminpassword123* \ + -i scripts/list-dbs.sql \ + -C + +# Build the Dacpac +dotnet build hows-the-weather/hows-the-weather.csproj + +# Deploy the local model +sqlpackage /Action:Publish \ + /SourceFile:hows-the-weather/bin/Debug/net8.0/hows-the-weather.dacpac \ + /TargetServerName:"127.0.0.1,1433" \ + /TargetDatabaseName:"weather" \ + /TargetUser:"sa" \ + /TargetPassword:"myadminpassword123*" \ + /TargetTrustServerCertificate:True + +# Write datbase name to stdout +sqlcmd \ + -S 127.0.0.1,1433 \ + -d master \ + -U sa \ + -P myadminpassword123* \ + -i scripts/list-tables.sql \ + -C +``` + +**What Happened?** \ No newline at end of file diff --git a/examples/5_pre-commit-hooks.md b/examples/5_pre-commit-hooks.md new file mode 100644 index 0000000..fa632c9 --- /dev/null +++ b/examples/5_pre-commit-hooks.md @@ -0,0 +1,11 @@ +# Gating Developer Commits +One aspect of stopping bad code from getting to source control, or to your automation pipeline. Open a new branch and: + + +**To Be Demonstrated** +- Change the formatting of one file +- Make one file a select * +- Discuss MSBuild locally - is it worth the wait? + +And, attempt to commit code! + diff --git a/examples/6_Github_PR.md b/examples/6_Github_PR.md new file mode 100644 index 0000000..02da0f0 --- /dev/null +++ b/examples/6_Github_PR.md @@ -0,0 +1,6 @@ +# Gating Github Deployments +Open a new Branch and send a PR with an invalid bind reference. Do at least 1 Select *. One bad Formatting. + +**What is going to happen?** +- What controls does github offer? +- Walk through the github actions diff --git a/examples/ms_build_view.sql b/hows-the-weather/data/ms_build_view.sql similarity index 100% rename from examples/ms_build_view.sql rename to hows-the-weather/data/ms_build_view.sql