Forums
Topics för SQL Server
The structure of Microsofts T-SQL (good read for general overview with samples):
https://learn.microsoft.com/en-us/sql/t-sql/queries/select-transact-sql?view=sql-server-ver15
Guidelines on choosing an index strategy:
https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-index-design-guide?view=sql-server-ver15
- Log in to post comments
Comments
Useful scripts and procs for SQL-server
Ola Hallengren SQL-script to simplify backups, index and optimization:
https://ola.hallengren.com/
Stored procedure "mtbSearchDatabase" for searching all tables/columns after specific string:
https://www.mytecbits.com/microsoft/sql-server/search-the-whole-database-for-a-value
Below is a modified copy of "mtbSearchDatabase".
sp_generate_inserts
sp_generate_inserts
Download script from: https://github.com/lambacck/generate_inserts/blob/master/generate_inserts.sql
Samples on how to use the stored procedure:
SQL First Responder Kit (sp_Blitz)
sp_Blitz, sp_BlitzCache, sp_BlitzFirst, sp_BlitzIndex, and other SQL Server scripts for health checks and performance tuning.
https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/tree/main
spSearchTables - "Search for table/column in all databases"
Download script from: https://github.com/fededim/TSqlResources/blob/master/README.md#stored-procedures-sps-folder
Parameters:
exec spSearchTables @dbSearchPattern, @tableSearchPattern, @columnSearchPattern, @valuePattern
Examples:
Script below can be used to search in just the current database:
Free e-book "Learning SQL" (from Stack Overflow contributors)
Link below to PDF-copy of free e-book "Learning SQL" (from Stack Overflow contributors).
Error when doing SSIS-deploy from Visual Studio 2022
If getting error deploy_project_internal "A required privilege is not held by the client"

when doing deploy of SSIS from Visual Studio 2022:
Resolution:
Run repair of SQL Server installation from "SQL Server 2022 Installation Center" (this should not delete any databases)
(It is necessary to have the SQL-media folder saved from installation..)
sp_change_users_login (Auto_Fix)
Reconnect a sql-login to a sql-user:
Shrink database, log and device-files
SQL-commands to do shrinking..
Find tables containing specified column-name
Script below can be used to find tables that have the specified column-name:
SSIS Script Task - Write to file (C#)
Sample-code to put in SSIS/DTSX "Script Task" to run custom C# code.
Links on tracing/logging (for example using "Dts.Events.FireInformation"):
http://msdn.microsoft.com/en-us/library/ms136033.aspx
http://phil-austin.blogspot.com/2012/06/fireinformation-to-debug-ssis-script.html
Script to archive and delete records from "sysssislog":
(Code originally copied from https://www.sqlservercentral.com/blogs/quick-tip-speeding-up-deletes-from-ssis-execution-log)
SQL - Useful scripts -1- (SQL Server)
Use time-interval as criteria in where-statement:
Find table-relations that could prevent deletion of records from specified table:
Script to view history of SQL Job
Script below can be used to show same info as dialog "View history" in SQL SSMS:
Script to show history and details of SSIS-Jobs
Script below, modify if needed:
Tips on SSIS-logging
To get information on performance of individual tasks inside DTSX-packages set the "Job Step" to
use Logging level "Performance": https://www.mattmasson.com/2011/12/what-events-are-included-in-the-ssis-catalog-log-levels/
Refresh all views in database
When changing views containing "select *" there is a need to refresh all views that might
be using those views. Script below found on stack overflow, and can be used to create and execute "sp_refreshview".
Save and transfer db-diagram (to another db with same tables)
Script below can be used to generate a SQL-script of all existing db-diagrams, so that it can be saved/archived and
also transferred to another database having the same design (same tables in the db, possibly a db on another server..)
Search-words: database diagram design
sp_generate_merge.sql (create merge-script of table-data)
Script below is a copy from https://github.com/dnlnln/generate-sql-merge
The code was modified as described on the GitHub-page to make it installed as a "temporary procedure".
Example of how to use the procedure:
EXEC [#sp_generate_merge] @Schema='Person', @Table_Name='AddressType', @cols_to_exclude = '''ModifiedDate'',''rowguid'''
* The End *
Check permissions on a schema (for views etc)
Select-statement below can be used to check if schema has permissions to modify (DDL) objects in the schema.
(if views/tables in schema has permission to be modified.)
Statement shown below can be used to assign permission/access to "ALTER" objects in the entire database: