Skip to main content

Questions tagged [sql-server-2012]

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

sql-server-2012
Filter by
Sorted by
Tagged with
2179 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.2k
589 votes
12 answers
1.7m 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,421
409 votes
17 answers
528k 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
268 votes
14 answers
452k 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,625
248 votes
18 answers
396k 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.7k
224 votes
17 answers
658k 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,497
170 votes
21 answers
383k 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
168 votes
16 answers
463k 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
162 votes
23 answers
389k 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,862
154 votes
6 answers
94k 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,803
139 votes
6 answers
49k 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,533
131 votes
3 answers
116k 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,463
129 votes
4 answers
310k 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.2k
124 votes
18 answers
344k 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
393k 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
122 votes
13 answers
166k 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
86k 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
111 votes
2 answers
154k 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,766
110 votes
8 answers
64k 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,101
102 votes
6 answers
73k 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
102 votes
2 answers
350k 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,963
94 votes
6 answers
621k 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,617
92 votes
4 answers
343k 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
  • 687
84 votes
3 answers
300k 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,616
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
77 votes
4 answers
63k 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
75 votes
8 answers
382k 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
74 votes
4 answers
205k 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.7k
72 votes
19 answers
137k 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,351
70 votes
8 answers
37k 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,664
70 votes
8 answers
209k 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
68 votes
3 answers
71k 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
67 votes
6 answers
131k 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
  • 791
66 votes
5 answers
80k 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
65 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,054
64 votes
6 answers
305k 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,174
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,593
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
65k 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
58 votes
20 answers
275k 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,699
57 votes
17 answers
212k 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
199k 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
  • 3,035
56 votes
6 answers
115k 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
236k 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
67k 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,577
55 votes
4 answers
117k 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
199k 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