{"id":15676947,"url":"https://github.com/rgl/sql-server-vagrant","last_synced_at":"2025-05-07T00:34:55.418Z","repository":{"id":139753306,"uuid":"80338673","full_name":"rgl/sql-server-vagrant","owner":"rgl","description":"SQL Server Express Vagrant environment","archived":false,"fork":false,"pushed_at":"2024-01-16T19:51:41.000Z","size":184,"stargazers_count":14,"open_issues_count":2,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T04:36:04.090Z","etag":null,"topics":["powershell","sql-server","vagrant"],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rgl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"Security.Cryptography.dll","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-29T09:47:57.000Z","updated_at":"2024-01-17T13:20:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"aa05388e-9a03-4d73-bbd5-9903f5075283","html_url":"https://github.com/rgl/sql-server-vagrant","commit_stats":{"total_commits":105,"total_committers":1,"mean_commits":105.0,"dds":0.0,"last_synced_commit":"7835ccb45fdb80800ceb8c8a6fdcef889d50347e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fsql-server-vagrant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fsql-server-vagrant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fsql-server-vagrant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Fsql-server-vagrant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rgl","download_url":"https://codeload.github.com/rgl/sql-server-vagrant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252792406,"owners_count":21804963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["powershell","sql-server","vagrant"],"created_at":"2024-10-03T16:07:34.827Z","updated_at":"2025-05-07T00:34:55.385Z","avatar_url":"https://github.com/rgl.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is an example Vagrant environment for a SQL Server 2022 Express installation.\r\n\r\nIt will:\r\n\r\n* Change the SQL Server Settings\r\n  * Mixed mode authentication\r\n  * Allow TCP/IP connections\r\n  * Allow encrypted connections (using a private CA)\r\n* Create Users\r\n  * SQL Server Users: `alice.doe` (in the `sysadmin` role), `carol.doe`, `eve.doe` and `grace.doe`.\r\n  * Windows Users: `bob.doe`, `dave.doe`, `frank.doe` and `henry.doe`.\r\n  * All have the `HeyH0Password` password.\r\n* Create the `TheSimpsons` Database\r\n  * Create the `db_executor` database role with permissions to execute stored procedures.\r\n  * Add users to database roles\r\n    * `carol.doe` in the `db_datawriter`, `db_datareader` and `db_executor` roles.\r\n    * `eve.doe` in the `db_datareader` and `db_executor` roles.\r\n* Run PowerShell, Python, Java, C# and Go [examples](examples/).\r\n\r\n\r\n# Usage\r\n\r\nInstall the [Windows 2022 base box](https://github.com/rgl/windows-vagrant).\r\n\r\nRun `vagrant up --no-destroy-on-error` to launch the environment.\r\n\r\nLogin into the Windows VM, open ConEmu/bash, and dump the SQL Server TLS details:\r\n\r\n```bash\r\n# see the TLS certificate validation result:\r\necho | openssl s_client -connect $COMPUTERNAME:1433 -servername $COMPUTERNAME -CAfile /c/vagrant/tmp/ca/example-ca-crt.pem\r\n# see the TLS certificate being returned by the server:\r\necho | openssl s_client -connect $COMPUTERNAME:1433 -servername $COMPUTERNAME -CAfile /c/vagrant/tmp/ca/example-ca-crt.pem | openssl x509 -noout -text -in -\r\n```\r\n\r\n\r\n# Reference\r\n\r\n* [TDS 8.0 and TLS 1.3 support](https://learn.microsoft.com/en-us/sql/relational-databases/security/networking/tds-8-and-tls-1-3?view=sql-server-ver16)\r\n\r\n\r\n# Example queries\r\n\r\n## List active connections\r\n\r\nList active connections details:\r\n\r\n```sql\r\nselect\r\n  c.client_net_address,\r\n  s.login_name,\r\n  db_name(s.database_id) as database_name,\r\n  s.program_name,\r\n  c.encrypt_option,\r\n  c.connect_time\r\nfrom\r\n  sys.dm_exec_connections as c\r\n  inner join sys.dm_exec_sessions as s\r\n    on c.session_id = s.session_id\r\norder by\r\n  c.client_net_address,\r\n  s.login_name,\r\n  s.program_name\r\n```\r\n\r\n**NB** you can customize what appears on `s.program_name` by setting the `Application Name`\r\nconnection string property, e.g., `Application Name=Example Application;`.\r\n\r\n## List database principals permissions\r\n\r\n```sql\r\nselect\r\n  principals.principal_id,\r\n  principals.name,\r\n  principals.type_desc, \r\n  principals.authentication_type_desc,\r\n  permissions.state_desc,\r\n  permissions.permission_name\r\nfrom\r\n  sys.database_principals as principals\r\n  inner join sys.database_permissions as permissions\r\n    on principals.principal_id = permissions.grantee_principal_id\r\norder by\r\n  principals.name,\r\n  principals.type_desc,\r\n  principals.authentication_type_desc,\r\n  permissions.state_desc,\r\n  permissions.permission_name\r\n```\r\n\r\n## List database schema tables row count\r\n\r\n```sql\r\nselect\r\n  schema_name(schema_id) as schema_name,\r\n  t.name as table_name,\r\n  sum(p.rows) as row_count\r\nfrom\r\n  sys.tables as t\r\n  inner join sys.partitions as p\r\n    on t.object_id = p.object_id\r\n    and p.index_id in (0, 1)\r\ngroup by\r\n  schema_name(schema_id),\r\n  t.name\r\n```\r\n\r\n## List database row count and storage usage\r\n\r\n```sql\r\nselect\r\n  sum(p.rows) as row_count,\r\n  (select sum(case when type = 1 then size end) * cast(8 * 1024 as bigint) from sys.master_files where database_id = db_id()) as data_size_bytes,\r\n  (select sum(case when type = 0 then size end) * cast(8 * 1024 as bigint) from sys.master_files where database_id = db_id()) as log_size_bytes\r\nfrom\r\n  sys.tables as t\r\n  inner join sys.partitions as p\r\n    on t.object_id = p.object_id\r\n    and p.index_id in (0, 1)\r\n```\r\n\r\n## List databases storage usage\r\n\r\n```sql\r\nselect\r\n  db_name(database_id) as database_name,\r\n  sum(case when type = 1 then size end) * cast(8 * 1024 as bigint) as data_size_bytes,\r\n  sum(case when type = 0 then size end) * cast(8 * 1024 as bigint) as log_size_bytes\r\nfrom\r\n  sys.master_files\r\ngroup by\r\n  database_id\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgl%2Fsql-server-vagrant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frgl%2Fsql-server-vagrant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgl%2Fsql-server-vagrant/lists"}