Questions tagged [sql-server-2012]

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

Filter by
Sorted by
Tagged with
2172 votes
33 answers
1.7m views

How to check if a column exists in a SQL Server table

I need to add a specific column if it does not exist. I have something like the following, but it always returns false: IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE ...
Maciej's user avatar
  • 22.1k
584 votes
12 answers
1.6m views

Auto increment primary key in SQL Server Management Studio 2012

How do I auto increment the primary key in a SQL Server database table? I've had a look through the forum but can't see how to do this. I've looked at the properties but can't see an option. I saw an ...
Ledgemonkey's user avatar
  • 7,361
409 votes
17 answers
526k views

Enable remote connections for SQL Server Express 2012

I just installed SQL Server Express 2012 on my home server. I'm trying to connect to it from Visual Studio 2012 from my desktop PC, and repeatedly getting the well-known error: A network-related ...
Ryan Lundy's user avatar
  • 208k
266 votes
14 answers
438k views

SQL Server Configuration Manager cannot be found

After installing SQL Server 2008, I cannot find the SQL Server Configuration Manager in Start / SQL Server 2008 / Configuration Tools menu. What should I do to install this tool?
Jin Ho's user avatar
  • 3,605
247 votes
18 answers
387k views

Recover unsaved SQL query scripts

How to recover the unsaved scripts if the SSMS crashes / unsaved tab gets accidentally closed?
BumbleBee's user avatar
  • 10.6k
224 votes
17 answers
657k views

Where is SQL Server Management Studio 2012?

I had SQL Server 2008 R2 and Visual Studio 2008 and 2010 on my laptop. I've installed SQL Server 2012 and have finally got SQL Server Data Tools to show up, so that I can create SSRS reports in Visual ...
Andy Brown's user avatar
  • 5,469
169 votes
21 answers
378k views

"No backupset selected to be restored" SQL Server 2012

I have a SQL Server 2012 database with filestream enabled. However, when I backup it and try to restore it on another SQL Server 2012 instance (on another machine), I simply get this message that: ...
Saeed Neamati's user avatar
167 votes
16 answers
449k views

The server principal is not able to access the database under the current security context in SQL Server MS 2012

I am trying to access my hosting server’s database through SQL Server Management Studio, everything till login is fine but when I use the command use myDatabase it gives me this error: The server ...
user avatar
160 votes
23 answers
380k views

No process is on the other end of the pipe (SQL Server 2012)

I've got this error: A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the ...
Iter Ator's user avatar
  • 8,618
153 votes
6 answers
93k views

Identity increment is jumping in SQL Server database

In one of my tables Fee in column "ReceiptNo" in SQL Server 2012 database identity increment suddenly started jumping to 100s instead of 1 depending on the following two things. if it is 1205446 it ...
kashif's user avatar
  • 3,773
135 votes
6 answers
48k views

SQL Server Management Studio won't let me add an index to a table

When I right click on the indexes folder in the table the "New Index" menu item is grayed out. I don't understand why. I've deleted all data in the table just in case, and refreshed and restarted SSMS,...
yarning's user avatar
  • 1,493
131 votes
3 answers
115k views

SQL Server 2012 column identity increment jumping from 6 to 1000+ on 7th entry [duplicate]

I have a strange scenario in which the auto identity int column in my SQL Server 2012 database is not incrementing properly. Say I have a table which uses an int auto identity as a primary key it is ...
Andy Clark's user avatar
  • 3,433
129 votes
4 answers
303k views

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified. I am getting the above said ...
Kamran Ahmed's user avatar
  • 12.1k
124 votes
18 answers
336k views

Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0

I have an Insert stored procedure which will feed data to Table1 and get the Column1 value from Table1 and call the second stored procedure which will feed the Table2. But when I call The second ...
Vignesh Kumar A's user avatar
123 votes
13 answers
388k views

Index was outside the bounds of the Array. (Microsoft.SqlServer.smo)

I am using SQL Server 2008 R2. It is working fine. But recently, I have changed my hosting server and I came to know that they have installed SQL Server 2012 on Server. Now, Issue is that after ...
Jeeten Parmar's user avatar
120 votes
13 answers
162k views

Cannot execute script: Insufficient memory to continue the execution of the program

I have a 123MB sql file which I need to execute in my local PC. But I am getting Cannot execute script: Insufficient memory to continue the execution of the program How to solve this issue?
Imran Qadir Baksh - Baloch's user avatar
116 votes
4 answers
85k views

Getting total row count from OFFSET / FETCH NEXT

So, I've got a function that returns a number of records that I want to implement paging for on my website. It was suggested to me that I use the Offset/Fetch Next in SQL Server 2012 to accomplish ...
CrystalBlue's user avatar
  • 1,817
110 votes
8 answers
63k views

Is there a way to persist a variable across a go?

Is there a way to persist a variable across a go? Declare @bob as varchar(50); Set @bob = 'SweetDB'; GO USE @bob --- see note below GO INSERT INTO @bob.[dbo].[ProjectVersion] ([DB_Name], [Script]) ...
NitroxDM's user avatar
  • 5,091
110 votes
2 answers
152k views

SQL Server IIF vs CASE

I recently came to know about the availability of IIF function in SQL Server 2012. I always use nested CASE in my queries. I want to know the exact purpose of the IIF statement and when should we ...
neophyte's user avatar
  • 1,756
101 votes
6 answers
72k views

Sequence vs identity

SQL Server 2012 introduced Sequence as a new feature, same as in Oracle and Postgres. Where sequences are preferred over identities? And why do we need sequences?
Sleiman Jneidi's user avatar
101 votes
2 answers
341k views

Last executed queries for a specific database

I know how to get the last executed queries using the following SQL in SSMS - SELECT deqs.last_execution_time AS [Time], dest.text AS [Query] FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys....
Mukus's user avatar
  • 4,957
90 votes
6 answers
603k views

SQL Server IF EXISTS THEN 1 ELSE 2

Using Sql Server 2012. I have a stored procedure and part of it checks if a username is in a table. If it is, return a 1, if not, return a 2. This is my code: IF EXISTS (SELECT * FROM ...
Michael's user avatar
  • 2,567
90 votes
4 answers
335k views

How to subtract 30 days from the current date using SQL Server

I am unable subtract 30 days from the current date and I am a newbie to SQL Server. This is the data in my column date ------------------------------ Fri, 14 Nov 2014 23:03:35 GMT Mon, 03 Nov 2014 ...
Madpop's user avatar
  • 667
83 votes
7 answers
118k views

SQL Server 2012 can't start because of a login failure

I recently installed Microsoft SQL Server 2012 on a fresh Windows 7 installation, but whenever I want to run the server, I get the following error: Error 1069: The service did not start due to a ...
xsl's user avatar
  • 17.3k
82 votes
3 answers
290k views

Count the Number of Tables in a SQL Server Database [duplicate]

I have a SQL Server 2012 database called MyDatabase. How can I find how many tables are in the database? I'm assuming the format of the query would be something like the following, but I don't know ...
Tot Zam's user avatar
  • 8,556
77 votes
4 answers
62k views

Cannot load Counter Name data because an invalid index -Exception

I am using C# and WPF - Operating System is windows 7 Professional and Visual Studio 2012, SQL Server 2012. I used Devexpress Grid in wpf. I want to bind it to database using ADO.Net Server mode. I ...
Annie Sheikh's user avatar
76 votes
5 answers
46k views

How to remove cached server names from the Connect to Server dialog?

Or, to put it another way, where is SqlStudio.bin for SQL Server 2012? It doesn't seem to be in the place that would be expected by looking at this other SO question.
Damian Powell's user avatar
74 votes
8 answers
373k views

Conversion failed when converting from a character string to uniqueidentifier - Two GUIDs

I don't understand why I can't insert this. I can't spot the problem. The error message is Conversion failed when converting from a character string to uniqueidentifier. The GUIDs are the ones that I ...
Simon Edström's user avatar
73 votes
4 answers
202k views

How can I tell if a VARCHAR variable contains a substring?

I thought it was CONTAINS, but that's not working for me. I'm looking to do this: IF CONTAINS(@stringVar, 'thisstring') ... I have to run one select or another, depending on whether that variable ...
Yatrix's user avatar
  • 13.6k
72 votes
19 answers
136k views

New Line Issue when copying data from SQL Server 2012 to Excel

I recently upgraded to SQL2012 and am using Management Studio. One of my columns in the database has a CHAR(13) + CHAR(10) stored in it. When I was using SQL Server 2008, this would copy and paste ...
MrPink's user avatar
  • 1,353
70 votes
8 answers
207k views

What is the connection string for localdb for version 11

I'm trying to do the Code First Walkthrough of the entity framework ( http://blogs.msdn.com/b/adonet/archive/2011/09/28/ef-4-2-code-first-walkthrough.aspx ). I have the latest SQL Server Express and ...
Bill Nielsen's user avatar
69 votes
8 answers
36k views

Why is "close existing connections to destination database" grayed out on SQL Server 2012 Management Studio?

I am normally using SQL Server 2012 Management Studio to restore a SQL Server database from a "bak" file. I do this by overwriting an existing database. In the "Options" page, there is a check-box ...
schlingel's user avatar
  • 1,624
68 votes
3 answers
69k views

sql server restoring back up error

I have backed up a database I had created on an other machine running SQL server 2012 express edition and I wanted to restore it on my machine, which is running the same. I have ticked the checkbox ...
danarj's user avatar
  • 1,818
66 votes
5 answers
78k views

What is (are) difference between NOLOCK and UNCOMMITTED

I use SQL Server 2012. I write two queries but what is a different between NOLOCK and UnCommitted ? SELECT lastname, firstname FROM HR.Employees with (READUNCOMMITTED) SELECT lastname, firstname ...
Ardalan Shahgholi's user avatar
66 votes
6 answers
127k views

What is the difference between a primary key and a surrogate key?

I googled a lot, but I did not find the exact straight forward answer with an example. Any example for this would be more helpful.
Dom's user avatar
  • 781
64 votes
12 answers
1.0m views

Convert Date format into DD/MMM/YYYY format in SQL Server

I have a query in SQL, I have to get a date in a format of dd/mm/yy Example: 25/jun/2013. How can I convert it for SQL server?
Krish KvR's user avatar
  • 1,044
64 votes
6 answers
297k views

Get last 30 day records from today date in SQL Server

I have small question about SQL Server: how to get last 30 days information from this table Sample data: Product: Pdate ---------- 2014-11-20 2014-12-12 2014-11-10 2014-12-13 2014-10-12 2014-11-15 ...
user3224208's user avatar
64 votes
2 answers
142k views

Possible to restore a backup of SQL Server 2014 on SQL Server 2012?

I know that you can't (at least not easily) restore a SQL Server 2012 backup on SQL Server 2008. But how does it work for SQL Server 2014 to SQL Server 2012 ? On database level there is the property ...
RayofCommand's user avatar
  • 4,154
63 votes
3 answers
48k views

How to fix the embedded text qualifier issue while exporting data to CSV flat file?

###RFC 4180: RFC 4180 defines Common Format and MIME Type for Comma-Separated Values (CSV) Files. One of the requirements of the RFC 4180 is stated as below. This is the point #7 in the RFC link. If ...
user avatar
62 votes
4 answers
65k views

Scope of temporary tables in SQL Server

I wrote a stored procedure to import and transform data from one database to another. Each import would take a single company ID and import all data related to this company. To help with the ...
Cogslave's user avatar
  • 2,603
61 votes
6 answers
73k views

Ctrl R not working in SQL Server 2012

In SQL Server 2012, Ctrl+R not working. Any other shortcuts for that. Any setting changes available or is there any alternative?
Yajuvendra Vant's user avatar
59 votes
3 answers
64k views

Identity column value suddenly jumps to 1001 in sql server [duplicate]

I am using Sql server 2012(Denali). I wonder why all identity column values start from 1001 and so on. At the beginning Identity column starts from 1,2 and so on and adding identity smoothly, but ...
Rajaram Shelar's user avatar
56 votes
17 answers
209k views

SSIS Excel Connection Manager failed to Connect to the Source

I have a server that is capable of creating and running an Excel Import task using the Import Wizard. I am trying to automate that process by using a visual Studio 2010 Integration Services package, ...
PatFromCanada's user avatar
56 votes
2 answers
198k views

Cannot Resolve Collation Conflict

I have moved one of our databases (DB1) from SQL Server 2008 to 2012 and when I run the stored procedures I get the following error Cannot resolve the collation conflict between "...
Silentbob's user avatar
  • 2,975
56 votes
20 answers
267k views

System.Data.SqlClient.SqlException: Login failed for user

Working with my project in debug I have no issues. However running it in IIS I am getting this error: System.Data.SqlClient.SqlException: Login failed for user 'domain\name-PC$'. Stack Trace [...
joetinger's user avatar
  • 2,659
56 votes
6 answers
113k views

How do I add a “last modified” and "created" column in a SQL Server table?

I'm design a new db schema for a SQL Server 2012 database. Each table should get two extra columns called modified and created which should be automatically change as soon a row gets inserted or ...
stevo's user avatar
  • 2,244
56 votes
5 answers
233k views

How to enable bulk permission in SQL Server

I am trying to insert images using "bulk" into SQL Server 2012. But, am ending up with the error message stating tha: Msg 4834, Level 16, State 1, Line 2 You do not have permission to use the ...
Esh's user avatar
  • 735
56 votes
3 answers
66k views

Count Number of Consecutive Occurrence of values in Table

I have below table create table #t (Id int, Name char) insert into #t values (1, 'A'), (2, 'A'), (3, 'B'), (4, 'B'), (5, 'B'), (6, 'B'), (7, 'C'), (8, 'B'), (9, 'B') I want to count consecutive ...
FLICKER's user avatar
  • 6,497
55 votes
4 answers
114k views

Get current value from a SQL Server SEQUENCE

I want to get the current value from my sequence - the same value that is shown in the sequence properties window SQL Server Management Studio My sequence is created with this statement: CREATE ...
Henrik Stenbæk's user avatar
54 votes
13 answers
197k views

Insert/Update/Delete with function in SQL Server

Can we perform Insert/Update/Delete statement with SQL Server Functions. I have tried with but SQL Server error is occured. Error: Invalid use of side-effecting or time-dependent operator in 'DELETE'...
Pankaj Agarwal's user avatar

1
2 3 4 5
343