Most Popular
1500 questions
41
votes
3 answers
N prefix before string in Transact-SQL query
Would you tell me, please, when should I use N prefix before string in Transact-SQL query? I have started to work with a database where I don't get any results using query like this
SELECT * FROM a_table WHERE a_field LIKE '%а_pattern%'
until I…
Alexander Prokofyev
- 511
- 1
- 4
- 6
41
votes
1 answer
SLEEP_TASK Wait Type in SQL Server - What does it indicate?
I haven't seen the SLEEP_TASK wait type before, and today I seem to be getting a ton of them.
I'm not the official DBA, just a SQL Server developer who knows some DBA stuff. We upgraded our servers last weekend to 10.52.2500.0 - R2SP1 I think.
All…
JNK
- 17,956
- 5
- 59
- 97
41
votes
3 answers
What is the difference between Shrink Database and File?
DBCC ShrinkDatabase()
DBCC ShrinkFile()
Do I need to run both DBCC commands in order to shrink the database?
What is the difference between these two above?
Jango
40
votes
2 answers
SQL Server unpredictable select results (dbms error?)
Below is simple example, which returns strange results, that are unpredictable and we cannot explain it in our team. Are we doing something wrong or is it SQL Server error?
After some investigation we reduced the search area to union clause in…
Ryszard Bocian
- 501
- 5
- 4
40
votes
3 answers
Performance of Non Clustered Indexes on Heaps vs Clustered Indexes
This 2007 White Paper compares the performance for individual select/insert/delete/update and range select statements on a table organized as a clustered index vs that on a table organized as a heap with a non clustered index on the same key columns…
Martin Smith
- 84,644
- 15
- 245
- 333
40
votes
6 answers
Why do sequential GUID keys perform faster than sequential INT keys in my test case?
After asking this question comparing sequential and non-sequential GUIDs, I tried to compare the INSERT performance on 1) a table with a GUID primary key initialized sequentially with newsequentialid(), and 2) a table with an INT primary key…
someName
- 591
- 1
- 4
- 5
40
votes
3 answers
check storage engine from shell
I'm upgrading to 3.0 and ran into some issues with the upgrade. Specifically, I got an error when trying to start up mongod via ssh, it tried to use the default dbpath instead of the one I specified in my new YAML config file. I went ahead and…
anon
40
votes
6 answers
What is the best way to get a random ordering?
I have a query where I want the resulting records to be ordered randomly. It uses a clustered index, so if I do not include an order by it will likely return records in the order of that index. How can I ensure a random row order?
I understand that…
goric
- 1,626
- 3
- 18
- 25
40
votes
6 answers
How to execute SQL against all DBs on a Server
I have some standard SQL that I run against multiple databases on a single server to help me diagnose problems:
select
so.name,
so.type,
MAX(case when sc.text like '%remote%' then '' ELSE 'N' END) AS Relevant,
@@ServerName as…
Andrew Bickerton
- 3,234
- 5
- 29
- 38
40
votes
6 answers
Management Studio System.OutOfMemoryException
I'm using Microsoft SQL Server 2012 and trying to run a simple query against it within Management Studio. I'm getting the following error (in SSMS, running on the server):
An error occurred while executing batch. Error message is: Exception
of…
Ben Durkin
40
votes
3 answers
Should every table have a single-field surrogate/artificial primary key?
I understand one benefit of surrogate/artificial keys in general - they do not change and that can be very convenient. This is true whether they are single or multiple field - as long as they are 'artificial'.
However, it sometimes seems to be a…
Jack Douglas
- 39,869
- 15
- 101
- 176
40
votes
5 answers
When a previously-fast SQL query starts running slow, where do I look to find the source of the issue?
Background
I have a query running against SQL Server 2008 R2 that joins and/or left-joins about 12 different "tables". The database is fairly large with many tables over 50 million rows and about 300 different tables. It's for a large-ish company…
Trevor
- 503
- 1
- 4
- 5
40
votes
1 answer
GO After every T-SQL statement
What is the reasoning behind using the GO statement after every SQL statement? I understand that GO signals the end of batch and/or allows the reputation of statements but what advantage does it have using it after every statement.
I am just…
TheIdiot
- 503
- 1
- 4
- 4
40
votes
4 answers
On a dedicated database server, how much memory to reserve for the OS?
Assuming you have a dedicated server explicitly for database functions -- how much memory should you reserve for the operating system?
I realize this will probably vary somewhat depending on the specific OS, the specific database software, and so…
Jeff Atwood
- 2,364
- 2
- 21
- 15
40
votes
4 answers
What is the optimal way to upgrade production RDS instance?
I have MySQL small RDS instance as part of my production system and I want to upgrade it to medium instance with provided IOPS.
As old-school DBA I'm aware about "add slave; promote to master; switch clients" method, but AWS promises to provide…
Vitaly Karasik DevOps
- 613
- 2
- 6
- 12