Questions tagged [sql-server-2008-r2]

Use this tag for questions specific to the 2008 R2 version of Microsoft's SQL Server.

Important Note: Extended support for SQL Server 2008 (including 2008 R2) ended on July 9, 2019.

Microsoft will no longer release security updates for any version of SQL Server 2008. Don't let your infrastructure and applications go unprotected. We're here to help you migrate to current versions for greater security, performance and innovation.

If you are still using 2008 R2 version you should seriously consider upgrading.

SQL Server 2008 R2 (codename Kilimanjaro, version 10.50), released in April 2010, is the successor to SQL Server 2008.

This version of Microsoft SQL Server is the 3rd form to utilize the .Net framework for operating with a database framework.

This product includes:
  • Server/Database/Table Triggers
  • Stored Procedure (SProc) & Functions
  • Database Maintenance processes & features
  • Automated SQL Agent with time triggers

Reference

11316 questions
350
votes
21 answers

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated

I have many users on my web site (20000-60000 per day), which is a download site for mobile files. I have remote access to my server (windows server 2008-R2). I've received "Server is unavailable" errors before, but am now seeing a connection…
SilverLight
  • 17,622
  • 58
  • 171
  • 277
263
votes
14 answers

Script to kill all connections to a database (More than RESTRICTED_USER ROLLBACK)

I have a development database that re-deploy frequently from a Visual Studio Database project (via a TFS Auto Build). Sometimes when I run my build I get this error: ALTER DATABASE failed because a lock could not be placed on database 'MyDB'. Try…
Vaccano
  • 70,257
  • 127
  • 405
  • 747
229
votes
18 answers

Exit single-user mode

Currently, my database is in Single User mode. When I try to expand me database, I get an error: The database 'my_db' is not accessible.(ObjectExplorer) Also, when I try to delete the database, I get the error: Changes to the state or options of…
Liondancer
  • 13,368
  • 38
  • 121
  • 222
204
votes
8 answers

How to check date of last change in stored procedure or function in SQL server

I need to check when function was changed last time. I know how to check creation date (it is in function properties window in SQL Server Management Studio). I found that in SQL Server 2000 it wasn't possible to check modify date ( look at this…
198
votes
1 answer

CREATE TABLE IF NOT EXISTS equivalent in SQL Server

CREATE TABLE IF NOT EXISTS works on mysql but fails with SQL Server 2008 R2. What is the equivalent syntax?
Sourabh
  • 3,859
  • 9
  • 35
  • 44
182
votes
10 answers

Error on renaming database in SQL Server 2008 R2

I am using this query to rename the database: ALTER DATABASE BOSEVIKRAM MODIFY NAME = [BOSEVIKRAM_Deleted] But it shows an error when excuting: Msg 5030, Level 16, State 2, Line 1 The database could not be exclusively locked to perform the…
Vikram Bose
  • 2,827
  • 2
  • 14
  • 30
174
votes
10 answers

Select SQL Server database size

how can i query my sql server to only get the size of database? I used this : use "MY_DB" exec sp_spaceused I got this : database_name database_size unallocated space My_DB 17899.13 MB 5309.39 MB It returns me several column that i…
Adeel ASIF
  • 2,924
  • 9
  • 24
  • 41
141
votes
8 answers

Check if table exists and if it doesn't exist, create it in SQL Server 2008

I am writing a Stored procedure in SQL Server 2008. I need to check if a table exists in the database. If it doesn't then I need to create it. How do I do this?
Prady
  • 9,658
  • 38
  • 120
  • 170
126
votes
15 answers

SQL Server 2008: How to query all databases sizes?

I have MS SQL 2008 R2, 500 databases. What is the most efficient, easiest and 'modern' way to query all databases sizes. The output should have columns: DatabaseName DataFilesSize LogFilesSize
Alex Aza
  • 70,453
  • 24
  • 147
  • 129
123
votes
7 answers

SQL Server - Create a copy of a database table and place it in the same database?

I have a table ABC in a database DB. I want to create copies of ABC with names ABC_1, ABC_2, ABC_3 in the same DB. How can I do that using either Management Studio (preferably) or SQL queries ? This is for SQL Server 2008 R2.
sequel.learner
  • 2,671
  • 7
  • 18
  • 24
123
votes
9 answers

SQL Update with row_number()

I want to update my column CODE_DEST with an incremental number. I have: CODE_DEST RS_NOM null qsdf null sdfqsdfqsdf null qsdfqsdf I would like to update it to be: CODE_DEST RS_NOM 1 qsdf 2 …
user609511
  • 3,450
  • 11
  • 44
  • 81
117
votes
12 answers

Could not load file or assembly Microsoft.SqlServer.management.sdk.sfc version 11.0.0.0

I have installed MS SQL Server 2008 R2 and when I try to update model from database under EDMX file I am facing that error. Could not load file or assembly Microsoft.SqlServer.management.sdk.sfc version 11.0.0.0 I have tried to install…
DmitryBoyko
  • 32,983
  • 69
  • 281
  • 458
108
votes
9 answers

Search of table names

I use the following to search for strings within the stored procedures of a specific database: USE DBname SELECT Name FROM sys.procedures WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%xxx%' Is it easy to amend the above so that it searches Table names…
whytheq
  • 31,528
  • 57
  • 155
  • 255
95
votes
4 answers

How to query for Xml values and attributes from table in SQL Server?

I have a table that contains a Xml column: SELECT * FROM Sqm A sample of the xml data of a row would be:
Ian Boyd
  • 220,884
  • 228
  • 805
  • 1,125
95
votes
6 answers

Calculating distance between two points (Latitude, Longitude)

I am trying to calculate the distance between two positions on a map. I have stored in my data: Longitude, Latitude, X POS, Y POS. I have been previously using the below snippet. DECLARE @orig_lat DECIMAL DECLARE @orig_lng DECIMAL SET…
Waller
  • 1,599
  • 3
  • 16
  • 32
1
2 3
99 100