Questions tagged [sql-server]

Microsoft SQL Server is a relational database management system (RDBMS). Use this tag for all Microsoft SQL Server editions including Compact, Express, Azure, Fast-track, APS (formerly PDW) and Azure SQL DW. Do not use this tag for other types of DBMS (MySQL, PostgreSQL, Oracle, etc.). Do not use this tag for issues on software and mobile development, unless it is directly related to the database.

How to write a good SQL Server question

There are six ingredients to this recipe:

  1. Provide a clear textual explanation of the problem at hand.
  2. Provide proper sample data, as DDL (Create table statement(s)) and DML (Insert statement(s)). The sample data should be enough to demonstrate the problem, including edge cases. Usually, a few relevant rows are enough. (You can use SQLFiddle or db-fiddle as an online tool to generate DDL and DML statements for you from tabular data using their Text To DDL button.)
  3. Provide expected output for the sample data you've posted.
  4. Show your attempts to solve the problem.
  5. Tag properly. In addition to , also provide the tag for the lowest version you need the solution for. (I.e., if you're developing on SQL Server 2016, but the production server is SQL Server 2012, use .)
  6. Do not include images of data or code!

A link to an online SQL test environment such as SQL Fiddle or DB Fiddle might help, but it is not a replacement for having all the data inside the question.

For more information, read Why should I provide an MCVE for what seems to me to be a very simple SQL query? and Help me write this query in SQL.

Questions about performance tuning should include, along with all of the above, the execution plan of the query. (How do I obtain a Query Execution Plan?). You can paste the execution plan on Brent Ozar's Paste The Plan and share a link to it in the question.

General Information:

Microsoft's SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality. It originated from the Sybase SQL Server 4.x codebase and Transact-SQL dialect (), but it has forked significantly since then.

SQL Server is available in multiple versions (typically identified by release year), each of which are subdivided into editions to distinguish between product functionality. The latest released version is SQL Server 2019 which was released on November 4th, 2019.

The SQL Server product range is split broadly into six categories:

  1. SQL Server () is the main suite of enterprise and developer server products. The primary differences are licensing costs, capacities, and components included in the product, with some minor differences supported language features. Standard components include database language and storage server, developer tools, ETL tools (), schedulers, and replication. Other components include OLAP (), reporting (), and parallel computation. Components runs as NT Services.

  2. SQL Server Express () is free for use and distribution, but it has reduced engine performance, functionality and capacity than found in its other server siblings. It is focused on small deployments and runs as an NT service.

  3. SQL Server Compact Edition () is an embeddable subset of SQL Server. Like the Express edition it has a reduced language, functionality and capacity, but it is free to distribute. It's focused on small installations and desktop applications where its small footprint and no-management-required features are a great advantage.

Note: SQL Server Compact Edition is deprecated. Customers should use SQL Server Express and possibly LocalDB).

  1. Azure SQL Database () is a completely managed, hosted, high-availability product with similar features to SQL Server, operated in Microsoft Azure data centers. Notable differences are language syntax support for federated queries, and lack of support for CLR integration.

  2. SQL Server Analytics Platform System (or APS), formerly known as SQL Server Parallel Data Warehouse (PDW), is a pre-built data warehouse appliance that offers massively parallel processing for SQL Server, allowing support for many hundreds of terabytes.

  3. Azure SQL Data Warehouse is an enterprise-class distributed database in the Azure Cloud capable of processing up to petabyte volumes of relational and non-relational data. It is the industry's first cloud data warehouse with grow, shrink, and pause in seconds.

Microsoft offers a comparison table of the different SQL Server editions.

SQL Server Release History

+-------------+------+---------------------------+----------------------+
|   Version   | Year |       Release Name        |       Codename       |
+-------------+------+---------------------------+----------------------+
| 15.0        | 2019 | SQL Server 2019           | Seattle              |
| 14.0        | 2017 | SQL Server 2017           | Helsinki             |
| 13.0        | 2016 | SQL Server 2016           | SQL16                |
| 12.0        | 2014 | SQL Server 2014           | Hekaton              |
| 11.0        | 2012 | SQL Server 2012           | Denali               |
| 10.5        | 2010 | SQL Server 2008 R2        | Kilimanjaro (aka KJ) |
| 10.25       | 2010 | SQL Azure DB              | CloudDatabase        |
| 10.0        | 2008 | SQL Server 2008           | Katmai               |
| 9.0         | 2005 | SQL Server 2005           | Yukon                |
| 8.0         | 2003 | SQL Server 2000 x64       | Liberty              |
| 8.0         | 2000 | SQL Server 2000           | Shiloh               |
| -           | 1999 | SQL Server 7.0 OLAP Tools | Palato mania         |
| 7.0         | 1998 | SQL Server 7.0            | Sphinx               |
| 6.5         | 1996 | SQL Server 6.5            | Hydra                |
| 6.0         | 1995 | SQL Server 6.0            | SQL95                |
| 4.21(WinNT) | 1993 | SQL Server 4.21           | SQLNT                |
| 1.1 (OS/2)  | 1991 | SQL Server 1.1            | - (16-bit)           |
| 1.0 (OS/2)  | 1989 | SQL Server 1.0            | Ashton-Tate (16-bit) |
+-------------+------+---------------------------+----------------------+

References

Tagging Recommendation

There are several version- and edition-specific tags. It is recommended to use the tag together with the version- and/or edition-specific tag; for example, or . Do not use this tag for other types of DBMS (, , , etc.).

331896 questions
60
votes
4 answers

Check for file exists or not in sql server?

Solution : http://www.tech-recipes.com/rx/30527/sql-server-how-to-check-if-a-file-exists-in-a-directory/ Made a post about this question using stackoverflow question to help others. id filepath 1 C:\vishwanath\21776656.docx 2 …
Vishwanath Dalvi
  • 35,388
  • 41
  • 123
  • 155
60
votes
6 answers

Calculate running total / running balance

I have a table: create table Transactions(Tid int,amt int) With 5 rows: insert into Transactions values(1, 100) insert into Transactions values(2, -50) insert into Transactions values(3, 100) insert into Transactions values(4, -100) insert into…
Pritesh
  • 1,938
  • 7
  • 32
  • 46
60
votes
8 answers

SQL Server compare results of two queries that should be identical

I am modifying a sql server 2005 stored procedure slightly for performance, and I would like to quickly make sure the old stored proc and the new one return the exact same results (the columns are the same, I want to make sure the rows are the…
Oxed Frederik
  • 1,331
  • 1
  • 12
  • 12
60
votes
7 answers

Unique key vs. unique index on SQL Server 2008

I have a table called countries and I define the country_name column to be unique by creating a “Index/Key” of type “Unique Key” on SQL Server 2008 R2. But I have the following questions: will creating “Index/Key” of type “Unique Key”…
John John
  • 1
  • 72
  • 238
  • 501
60
votes
3 answers

Is there a difference between SQL Server Express (2012) and LocalDB?

In his excellent and popular comparision chart, ErikEJ draws a distinction between SQL Server Express 2012, and SQL Server 2012 LocalDB. However, I can't find such a distinction anywhere else in the MSDN documentation ("LocalDB" isn't even mentioned…
kmote
  • 16,095
  • 11
  • 68
  • 91
59
votes
9 answers

How to find out what is locking my tables?

I have a SQL table that all of a sudden cannot return data unless I include with (nolock) on the end, which indicates some kind of lock left on my table. I've experimented a bit with sys.dm_tran_locks to identify that there are in fact a number of…
59
votes
10 answers

"Adaptive Server is unavailable or does not exist" error connecting to SQL Server from PHP

I'm attempting to connect to a SQL Server 2005 DB from my Mac using unixODBC and FreeTDS as I have outlined here. However, when I try to connect in to a different DB using the same setup, I get: Connection Failed:[FreeTDS][SQL Server]Unable to…
wonder95
  • 3,825
  • 8
  • 45
  • 74
59
votes
11 answers

Delete data with foreign key in SQL Server table

I'm going to delete data in an SQL Server table (parent) which has a relationship with another table (child). I tried the basic Delete query. But it isn't working (and I know it won't). DELETE FROM table WHERE ... It returned following error The…
Andha
  • 907
  • 2
  • 11
  • 22
59
votes
3 answers

How to find slowest queries

Using Sql Server 2005 Profiler, what events, columns, and filters do you trace to find your slowest queries and stored procedures? Slow = greater than N seconds, 10 for sake of argument.
KM.
  • 101,727
  • 34
  • 178
  • 212
59
votes
9 answers

Know relationships between all the tables of database in SQL Server

I wish to all know how the tables in my database are related to each other (i.e PK/FK/UK) and hence i created a database diagram of all my tables in SQL Server. The diagram that was created was not easily readable and had to scroll (horizontally and…
xorpower
  • 17,975
  • 51
  • 129
  • 180
59
votes
5 answers

SQL Server giving logins(users) db_owner access to database

We have a test database and some test logins that we would like to give db_owner access to through a script. Usually we would have to go into logins and right click on the username and go to user mapping and select the database to associate it with…
user516883
  • 8,868
  • 23
  • 72
  • 114
59
votes
8 answers

Update if different/changed

Is it possible to perform an update statement in sql, but only update if the updates are different? for example if in the database, col1 = "hello" update table1 set col1 = 'hello' should not perform any kind of update however, if update table1 set…
nami
  • 1,186
  • 5
  • 19
  • 22
59
votes
15 answers

Fastest way to delete all the data in a large table

I had to delete all the rows from a log table that contained about 5 million rows. My initial try was to issue the following command in query analyzer: delete from client_log which took a very long time.
Ron Skufca
  • 2,028
  • 5
  • 27
  • 34
59
votes
10 answers

Drop all databases from server

I have a server (SQL Server 2005) with more than 300 databases. I don't want to right-click one by one and select Delete. How can I delete all databases easily?
Moslem7026
  • 3,290
  • 6
  • 40
  • 51
59
votes
4 answers

SSMS version 18 – no Database Diagrams

I notice that Database Diagrams are not supported in SSMS version 18, any idea why, and is there a way to get the same functionality? And why is the T-SQL debugger gone now?
Brian Battles
  • 971
  • 1
  • 7
  • 19
1 2 3
99
100