SQL Server Accidental/Involuntary/Junior DBAs Series
Shortcuts help you to do your work swiftly and with increased productivity. In this blog we’ll look at new query window shortcut every SQL Server geek should know
Window + R -> ssms.exe
Open SQL Server management studio
CTRL + N
Open a new query window
CTRL + TAB
Move among open query windows
CTRL + E
Execute All or selected queries
In this blog post we’ll look at a way to list out all week days of a week a particular date belongs too. This can be even referred to as weekly calendar. This comes handy in reporting. A SQL function to get week days of particular date is given below
First, create the below function […]
This is a very basic problem sometimes newbies struggle with. I have seen developers writing 10 different insert statements to insert 10 rows in a table. This can be simplified in multiple ways as shown below
CREATE TABLE tblinsert (Sno INT IDENTITY,col1 CHAR(1))
-- using union all
-- applies to all version
INSERT INTO tblinsert
-- Method 2: Applies to SQL Server 2008 and above
INSERT INTO tblinsert VALUES ('D'), ('E'),('F')
Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook
Follow me on Twitter | […]
A business need may arise to limit a VARCHAR column to a certain length. Consider a scenario where in an application has a 10000 character limit for a column. The VARCHAR(max) is the suitable data type choice for this column. However a VARCHAR(max) column is not limited to 10000 characters. In that case we […]
SQL Server unattended installation or silent installation can be done using the configuration.ini file. The SQL Server installation GUI application saves the setup instructions in a configuration.ini file which it further uses to install selected options. The same file can be modified and passed as a parameter to setup.exe command to do a silent/unattended installation.
Primary and Unique Key both enforce uniqueness of columns on which they are defined. Then where do they differ? They differ in following way
– A primary key doesn’t allow null value wherein a unique key allows one null value.
– A primary keys purpose is to uniquely define a row in a table wherein unique […]
Locking hints are used with SELECT/INSERTS/UPDATE/DELETE statements to enforce or change the default locking behavior. Given below are some of the locking hints available in SQL Server
The ROWLOCK hint tells query optimizer to lock rows (KEY level locks) instead of taking PAGE or TABLE level locks when reading or modifying data. A row lock […]
Difference between UNION and UNION ALL is one of the most asked interview question.
UNION and UNION ALL both combine result set from two or more queries into single result. The difference is that UNION ALL doesn’t remove duplicate rows from the combined result set.
The below snapshot demonstrates the use of UNION operator.
The UNION operator […]
Detach or take offline both causes a database to be inaccessible to users. The difference is that detach deletes database metadata from SQL Server i.e. database file information, status information and all the other details that we see in sys.databases view. On the other hand taking database offline retains database metadata in SQL server […]