Tag Archives | MSSQL

List all triggers in SQL Server database with table name and schema

Sample query: Here is and another version where you can the code of the trigger:

Read full story Comments { 0 }

Converting UTC Time To Local Time in T-SQL – Sample

Sample 1: Sample with a table: Results (New York Time):

Read full story Comments { 0 }

Tips for Effective SQL Server Database Maintenance

“ I have been asked several times for advice on how to effectively maintain a production database. Sometimes the questions come from none-DBAs who are implementing new solutions and want help fine-tuning maintenance practices to fit their new databases’ characteristics. As with the majority of tasks and procedures in the IT world, there isn’t an easy […]

Read full story Comments { 0 }

Get Numbers from Alpha Numeric String – Get Numeric Numbers Only

So, someone had stored thousands of SSN numbers in a table but now they have an issue because some of them are incomplete or are not correctly formatted. Thank you to blog.sqlauthority.com and little creativity I have come up with a SQL script that fixes this issue. Here is the T/SQL script:

Read full story Comments { 0 }

T-SQL: RIGHT, LEFT, SUBSTRING and CHARINDEX Functions

This article explains the base functionality and uses of the LEFT, RIGHT, SUBSTRING and CHARINDEX functions in SQL. Samples script: Sample Results: Variable Data Results ——————– HELLO WORLD RIGHT Results ————- RLD LEFT Results ———— HEL CHARINDEX Results —————– 6 SUBSTRING Results —————– LO WO Combined Results ——————– HELLO  

Read full story Comments { 0 }

Find the Server Name or Instance Name using T-SQL

The following instructions are supposed to return the same results,  but sometimes the results can be different. The reason is that SERVERPROPERTY automatically reports changes in the network name of the computer, while @@SERVERNAME don’t. SELECT CONVERT(sysname, SERVERPROPERTY(N’servername’)) GO SELECT @@SERVERNAME When they are run on the default instance they return just the server name, […]

Read full story Comments { 0 }

SQL SERVER – Concat Strings in SQL Server using T-SQL

Concatenating string is one of the most common tasks in SQL Server and every developer has to come across it. We have to concat the string when we have to see the display full name of the person by first name and last name. Here are some samples:

Read full story Comments { 0 }

List All The Constraint of Database – Find Primary Key and Foreign Key Constraint in Database

Following script are very useful to know all the constraint in the database. I use this many times to check the foreign key and primary key constraint in database. This is simple but useful script from my personal archive.

Read full story Comments { 0 }