All versions of Microsoft SQL Server (not MySQL). Please also add a version-specific tag like sql-server-2016 if that is relevant to the question.

learn more… | top users | synonyms (2)

0
votes
1answer
668 views

how to extract current year and combine with specific month and date as a date

I have to get the current year with June the 16th as a date. For example, if I run the query now I want to get 2015-06-16. I tried the following: CONVERT(DATETIME,cast( (cast(YEAR(GetDate()) AS ...
2
votes
1answer
74 views

How to check what type of lock an UPDATE statement uses?

How can I determine if an update statement puts a table lock, page lock, or row lock on a table?
1
vote
1answer
3k views

Joining multiple tables results in duplicate rows

I am running SQL 2005. I am getting more rows then I expect returned by my query. I believe it has something to do with my join statements. Here is my query: There are multiple tables that have ...
1
vote
2answers
626 views

Collation conflict when running dynamic sql FOR XML PATH

I am getting the following error message when running the query below: Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "Latin1_General_BIN" in the equal to operation ...
0
votes
1answer
46 views

Tables shared information

I would like to have a table pattern on my db. I.e. every column should have Record_Insert_Date Record_LastChange_Date Record_User_Insert Record_User_Update The obvious approach is to add these ...
-2
votes
2answers
226 views

Deny database access to all users but sa/admin [closed]

How can I deny the access to a database for all the users except for the sa BY CODE? I know how to do it by using the interface in management studio, but I need to have it on the script.
2
votes
1answer
103 views

Queries that are usually fast running, sometimes take minutes?

Updating my Entity Framework edmx file takes about 10 seconds. However recently it's been taking 3 minutes. sqlsevr.exe is responsible, thrashing the CPU during that time. Running sp_whoisactive shows ...
0
votes
2answers
549 views

Why does my SQL Server Express (2014) connection break after restarting my computer?

For some reason when I install SQL Server Express (2014), it works fine for a while (usually a day or two), and then quits allowing me to sign in. I'm not just talking about remotely here, either. ...
5
votes
1answer
499 views

Is there any way to monitor execution of xp_cmdshell in SQL Server 2012?

I've been tasked with assessing the security risk involved with allowing a third party vendor to debug their queries remotely within SSMS. This means that the user's account must be in the sysadmin ...
1
vote
0answers
96 views

SQL server actual execution plan: finding bottlenecks

I have a batch (7 queries) which executes in a couple of seconds locally by takes more than an hour in production. I've have a .sqlplan XML file from that long running query on production and trying ...
0
votes
0answers
50 views

clarification of ALTER DATABASE error message

I took a SQL Server 2008 database offline: alter database FOO set offline; Then I copied its MDF and LDF physical files to a new folder on another hard drive. Then I ALTERed the database: ALTER ...
4
votes
1answer
279 views

NUMA Nodes - MAXDOP - PLE

We have a server with 8 CPUS across 2 NUMAs with hyperthreading enabled. Currently Maxdop is set to 8, but actually should be set to 4 as per the Maxdop section of this article: ...
1
vote
1answer
698 views

Different execution plans during INSERT at @table variable and #temporary table

I faced with strange situation: inserting of ~800 000 rows into table variable is much more faster than inserting (with the same select) into temporary table. INSERT is under stored procedure. SELECT ...
-1
votes
1answer
98 views

Using different aggregate functions in a pivot

I have a table of data collected in the time as shown below. I would pivot them using different aggregate functions: average for C1 and sum for the others. How could I achieve it ? DECLARE @T AS ...
1
vote
1answer
84 views

How do I use a SP in SQL Server 2014 to call a external XML source?

I am attempting to retrieve Currency Exchange rates from http://www.floatrates.com/daily/usd.xml using a SP in SQL Server 2014. The result is in XML. So I created the following SProc: --DROP ...
3
votes
1answer
500 views

Foreign keys become untrusted after bulk insert

In a SQL 2014 edition server (12.0.2430.0 - no SP1 yet) with a database in 2012 compatibility mode (working on getting it switched to 2014...) I have a handful of foreign key objects which are ...
-2
votes
2answers
1k views

SQL Server failed stored procedures log [closed]

How to find errors that was occurred in stored procedures in some timespan in Sql server management studio 2008 ?
0
votes
1answer
163 views

Loading subscription slow in SSRS

I have a SQL Server 2014 test box with SSRS installed. The site loads ok and reports are quick. When I try to go to Subscribe the page takes over a minute to load. From there if I pick a schedule it ...
0
votes
1answer
106 views

How to modify the precision of a datetimeoffset column?

In a sql-server database with data I have several columns with type datetimeoffset(7). Now I would like to change the precision part of the type to datetimeoffset(0). Is this possible without ...
0
votes
4answers
93 views

The multi-part identifier > “a.surveyid” could not be bound [closed]

I am getting the error : Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "a.surveyid" could not be bound. Below is the query ,what could be the issue? SELECT a.surveyid,* ...
2
votes
1answer
1k views

Indexed VIEW in SQL Server with PIVOT

A simplified version of my problem is as follows: I have three tables Records, Inputs, and Outputs. Records Id DTS   1  2015-01-01 00:00 ... Inputs Id RecordId ...
4
votes
1answer
263 views

Decode and aggregate a BitMask in t-sql

I have a table that contains a bitmask field that stores permissions, where each bit denotes whether a particular permission is granted or not. Here's a simplified example: DECLARE @T TABLE (id ...
2
votes
2answers
240 views

Get physical disk id and drive letters from management studio?

Can anyone tell me how I can go about getting the physical disk id and drive letters of the local server from within management studio? I know I can grab the drive letters with xp_fixed drives and ...
-1
votes
1answer
125 views

SQL Service account getting locked out [closed]

I am having this problem where my service account in SQL Server gets locked after few days, there is no event logged in the event log. How can I find out where and how is getting locked?
1
vote
3answers
3k views

Select using values from another table

I want to select specific columns from a table, let's say table A. Table B has the names of the names of the columns I would like to select. How would I write a MSSQL query that will use the distinct ...
1
vote
2answers
93 views

RIGHT() function returning blank result

I have a single column that contains information that I need to have split up into three separate columns. I currently have a SELECT statement that works partially, but my ChangeTo column is not ...
1
vote
0answers
115 views

Data compression within Internal Tables in SQL server 2008R2

We are doing downgrade from enterprise to standard for couple of servers which are not using any enterprise features: For one of our TFS(Team foundation server) database TFS_resx, when we ran ...
0
votes
2answers
517 views

SQL Server BigInt vs Decimal

I need to choose a data type for SQL Server( BigInt vs Decimal) on the basis of performance and querying (10 digit number)
0
votes
1answer
58 views

SQL Server 2008 commit overhead warnings

I have four mirrored user DB's on a pair of Server 2008 R2 machines. My Db engine is SQL Server 2008. Of the four Db's one is warning me of overhead commit latencies ( > 20ms). From some research on ...
10
votes
1answer
314 views

Reset SQL Server usage

In my development environment, I am playing around with queries. For that I need to reset SQL Server memory, plans, etc. things which can ensure me that my query is the only stress/working process on ...
1
vote
0answers
69 views

SQL Server - Project based on the TDS protocol [closed]

From what I understand, TDS is an application level request/response protocol used for communication between a client and SQL server. Now, I'm in the process of finding a master thesis (computer ...
0
votes
1answer
72 views

Unable to start the services of SQL server after Downgrading from Enterprise to Standard

We are performing the downgrade activity from SQL server 2008 R2 Enterprise to Standard. After the uninstall and re-install the standard version, (once the saved system databases were copied to the ...
1
vote
4answers
1k views

MSSQL Select all parent rows for which exists a combination of children rows with desired value

I would like to select all parent rows for which exists a combination of children rows with desired value. The easiest approach is to use multiple exists clauses, but this is not optimal - anyone ...
0
votes
0answers
237 views

SQL server developer installation language error windows 7

I am trying to install SQL Server on windows 7 and I mistakenly downloaded the Spanish version, and when i try to install it, it sends me this message: "This SQL Server startup media does not support ...
10
votes
1answer
1k views

Avoiding “Row by row” fetch method when dealing with source LOB columns

I have a legacy PostgreSQL database source (ODBC) that I'm attempting to migrate to new SQL Server schema using SSIS. I'm getting a warning saying: 'Row by Row' fetch method is enforced because ...
6
votes
4answers
705 views

How can I determine which tables are causing the database to grow over time?

I have a database in SQL Server 2008 that is growing all the time, and I'd like to know which tables have caused the most growth over the past 6 months.
1
vote
1answer
69 views

Using NOCOUNT to Improve Procedure Performance

I am looking to improve the performance of a certain procedure and I wanted to begin with the insertion of the SET NOCOUNT ON. I've read a couple of articles on the subject: Aaron Bertrand SET ...
0
votes
2answers
4k views

Cannot Restore Database in SQL Server 2014 [duplicate]

I have created a backup of a SQL database in SQL 2014 and want to use this backup to restore it to a different machine that also runs SQL 2014, hence no version issues. However, I keep receiving an ...
1
vote
1answer
369 views

Powershell function to drop table(s) from SQL Server database [closed]

### List of tables that require full sanitizing $requiredTables = 'table1','table2','table3' foreach ($table in $requiredTables){ function Delete-FromTable{ $SqlConnection = New-Object ...
2
votes
4answers
145 views

Individual SQL account per user?

I am designing a web application that will have probably around ~1000 users. The website is facing the internet but it can only be used by partners (i.e. the general public cannot just "sign up an ...
0
votes
1answer
296 views

Attaching Database Incorrect name in sys.master_files

I have been moving some databases from SQL 2008 to SQL 2012 using detach and attach method. I correctly map up all the files and the physical and logical names appear correctly in the properties of ...
0
votes
1answer
70 views

Some records are missing while selecting from table

I am trying to match the records having MAX(WORKITEM_ID) but some PROCESS_INSTANCE_ID are not coming though they are present in WORKITEM table. select WI.WORKITEM_ID as WORKITEMID, ...
1
vote
1answer
33 views

Sql Server 2008 : What is the cost of accessing an index?

I've just read this interesting blog post about selectivity notion. In the section 'When is better to not use a database index?', the author states : Accessing the index takes time, and consumes ...
0
votes
1answer
70 views

Better way to full text query across multiple tables?

I've got a rather large query across multiple tables and their fulltext-indices which (unsurprisingly) is rather slow: SELECT t0.[Key], t0.[Nr] FROM dbo.[Customers_View] AS t0 WHERE (t0.[Deleted] ...
2
votes
1answer
202 views

Trigger Performance - 1 or 2 Triggers?

I have a question about triggers performance. CREATE TABLE [dbo].[_test]( [ID] [INT] IDENTITY(1,1) NOT NULL, [Date] [DATETIME] NULL, [DateYearID] [INT] NULL, [DateQuarterID] [INT] NULL, [Date1] ...
2
votes
4answers
17k views

How can I take backup of particular tables in SQL Server 2008 using T-SQL Script

I want to take a backup of particular tables available in my database in .bak file And all these should be done using T-SQL script
0
votes
1answer
91 views

Does the scope for 'Alter Any Database' operate similar to 'Create Any Database'?

Does the scope for 'Alter Any Database' operate similar to 'Create Any Database', as in, only those databases created by Login-A under the 'Create Any Database' umbrella can be altered, and not the ...
0
votes
2answers
109 views

Select MAX DATE from joined Table

I have two tables, PROJECT and BILLINGS, as follows: Project_ID Project_Client ---------- ------------------ P1 ABC Company P2 DEF Company P3 GHI Company Proj_ID ...
3
votes
1answer
232 views

Select where bit is not 0

I have made the following query to select a record that isn't 0. SELECT * FROM Table WHERE Bit != 1 OR Bit IS NULL; Why is the check Bit != 1 not enough for a nullable BIT?
0
votes
1answer
210 views

SSIS Package Error when Scheduled in Job

I have created a package that brings in data from another database and with the data package populates a table in SQL database. The job runs fine when it is executed. I've imported it into SQL and it ...