Something that's still found in SQL scripts in enterprise environment, even with newly written scripts is the use of string literals as column aliases. Although this feature has been deprecated since 2012, old habits die hard. So what's the right way to write it? You can either use alias without a whitespace or use a double quote character. Either of these examples below is … [Read more...]
How to reset SA password on Microsoft SQL Server
If you happen to forget your sa password, you can still recover it as long as you have access to the server. Here are the steps to do it. Steps Launch Sql Configuration Manager under Configuration Tools folder. Look for your SQL Server instance (the default is MSSQLSERVER) and stop the service. You can click the stop button while having the SQL Server (MSSQLSERVER) row highlighted or you … [Read more...]
Ways to Upsert a Record in SQL Server
To continue the previous post, this article demonstrates ways to do Upsert (update and insert) and how MERGE statement in SQL Server 2008 (or later) can be more efficient to perform the two operations at once. First we'll create a table for this demo. We want to do update if the Id is found on the table and insert if it's a new Id number. 1. Conventional way of doing it is by using IF … [Read more...]
How to Find a Column Name in SQL Server Database
This query was originally appeared from SQL Authority Blog and I find it really useful when you need to find a column in any tables in a database. If you need to find all column names that are in the database, just comment out or delete the highlighted line from the SQL command above. Further Reading SQL SERVER – Query to Find Column From All Tables of Database How to Get Table … [Read more...]
Using Connection Coloring in SSMS Tools Pack
From previous posting, we demonstrated a way to use custom color coding using SQL Server Management Studio's (SSMS) Registered Servers properties. But using the feature can be very dangerous if you don't have the discipline to follow a strict process of opening new query from the registered servers pane. For example, if you use Change Connection button, the color will stay the same as the last … [Read more...]