• Shaarli
  • Tag cloud
  • Picture wall
  • Daily
  • RSS
  • Login
4252 shaares
2 / 3
Filters
51 results tagged mssql

Fundamentals of table expressions, Part 6 – Recursive CTEs - SQLPerformance.com

QRCode

Continuing a series on table expressions, Itzik Ben-Gan explains recursive CTEs, features from the standard T-SQL is lacking, and workarounds.

Remember that the syntax of a query against a CTE is as follows:

WITH <CTE name> [ ( <with column list> ) ]
AS
(
<table expression>
)
<outer query>;
https://sqlperformance.com/2020/09/t-sql-queries/fundamentals-of-table-expressions-part-6-recursive-ctes
August 16, 2021 at 8:45:18 AM EDT *
mssql sql
FILLER

The BCP (Bulk Copy Program) command in action

QRCode

The BCP (Bulk Copy Program) utility is a command line that program that bulk-copies data between a SQL instance and a data file using a special format file.

https://www.sqlshack.com/bcp-bulk-copy-program-command-in-action/
May 19, 2021 at 7:44:37 AM EDT *
mssql
FILLER

List table columns in SQL Server database - SQL Server Data Dictionary Queries

QRCode

Useful T-SQL queries for SQL Server to explore database schema.

select schema_name(tab.schema_id) as schema_name,
    tab.name as table_name, 
    col.column_id,
    col.name as column_name, 
    t.name as data_type,    
    col.max_length,
    col.precision
from sys.tables as tab
    inner join sys.columns as col
        on tab.object_id = col.object_id
    left join sys.types as t
    on col.user_type_id = t.user_type_id
order by schema_name,
    table_name, 
    column_id;
https://dataedo.com/kb/query/sql-server/list-table-columns-in-database
April 26, 2021 at 1:28:17 PM EDT *
sql mssql
FILLER

Views in SQL Server – {coding}Sight

QRCode

In this article, we briefly covered types of views in SQL Server and gave several examples of user defined views.

Creating a View Across Instances

https://codingsight.com/views-in-sql-server/
December 3, 2020 at 10:55:01 AM EST *
sql mssql
FILLER

Top Answers to 5 Burning Questions on SQL COALESCE Function – {coding}Sight

QRCode

In this article, you'll find the answers to the five most-asked questions about SQL COALESCE function in SQL Server. Explore useful examples.

The definition of COALESCE is an expression that returns the first non-null value from a list of values. The COALESCE syntax is:

COALESCE ( expression [ ,…n ] )

(4) SQL COALESCE is Converted to CASE. ISNULL Stays ISNULL

COALESCE returns the data type of the value with the highest precedence.

https://codingsight.com/top-answers-to-5-burning-questions-on-sql-coalesce-function/
December 3, 2020 at 10:53:21 AM EST *
sql mssql
FILLER

Please stop using this UPSERT anti-pattern - SQLPerformance.com

QRCode

Locating the row to confirm it exists, only to have to locate it again in order to update it, is doing twice the work for nothing.

BEGIN TRANSACTION;

UPDATE dbo.t WITH (UPDLOCK, SERIALIZABLE) SET val = @val WHERE [key] = @key;

IF @@ROWCOUNT = 0
BEGIN
  INSERT dbo.t([key], val) VALUES(@key, @val);
END

COMMIT TRANSACTION;
https://sqlperformance.com/2020/09/locking/upsert-anti-pattern
September 8, 2020 at 2:57:38 PM EDT *
mssql sql
FILLER

SQL Server Helper - Tips and Tricks - Date Formats

QRCode

SQL Server Date Formats

One of the most frequently asked questions in SQL Server forums is how to format a datetime value or column into a specific date format. Here's a summary of the different date formats that come standard in SQL Server as part of the CONVERT function. Following the standard date formats are some extended date formats that are often asked by SQL Server developers.

It is worth to note that the output of these date formats are of VARCHAR data types already and not of DATETIME data type. With this in mind, any date comparisons performed after the datetime value has been formatted are using the VARCHAR value of the date and time and not its original DATETIME value.

Standard Date Formats

http://www.sql-server-helper.com/tips/date-formats.aspx
April 7, 2020 at 11:12:38 AM EDT *
mssql dates
FILLER

What columns are in that index? - Erin Stellato

QRCode
  • Whenever you know that the column, or combination or columns, makes a unique key for a nonclustered index, I always recommend that you specify UNIQUE when you create the index. That information is great for the optimizer to have when generating query plans.

  • Think carefully about the impact of your clustering key on your nonclustered indexes. Any non-unique nonclustered index will be larger (more pages, eventually more levels) because the entire clustering key will be in the tree level.

  • If you have a clustering key with a column (or multiple columns) that are frequently modified, then those modifications have to be propagated to the tree levels of the nonclustered indexes as well.

https://www.sqlskills.com/blogs/erin/what-columns-are-in-that-index/
August 21, 2019 at 8:57:01 AM EDT *
sql mssql
FILLER

T-SQL: Deleting all duplicate rows but keeping one [duplicate]

QRCode

You didn't say what version you were using, but in SQL 2005 and above, you can use a common table expression with the OVER Clause. It goes a little something like this:

WITH cte AS (
SELECT[foo], [bar],
row_number() OVER(PARTITION BY foo, bar ORDER BY baz) AS [rn]
FROM TABLE
)
DELETE cte WHERE [rn] > 1

https://stackoverflow.com/questions/6025367/t-sql-deleting-all-duplicate-rows-but-keeping-one
February 7, 2019 at 10:42:03 AM EST *
sql mssql
FILLER

Nullable columns and performance

QRCode

NULL values are special. For instance, a comparison between two NULL values, or even a comparison between a NULL value and a non-value, will always be false. This is because NULL values aren’t real values as such, but rather “unknowns”.

https://sqlsunday.com/2019/01/03/nullable-columns-and-performance/
January 7, 2019 at 10:46:57 AM EST *
sql mssql
FILLER

When should a primary key be declared non-clustered?

QRCode

Say that I have a table of People, and these people have a Country column and a unique Primary Key. It's a demographics table, so these are the only things I care about; what Country and how many unique people are tied to that country.

I am thus only ever likely to SELECT WHERE or ORDER BY the Country column; a clustered index on the Primary Key doesn't do me any good, I'm not accessing this data by PK, I'm accessing it by this other column. Since I can only have one clustered index on a table, declaring my PK as Clustered would prevent me from using a Clustered Index on Country.

https://dba.stackexchange.com/questions/7741/when-should-a-primary-key-be-declared-non-clustered
August 6, 2018 at 9:24:03 AM EDT *
sql mssql
FILLER

Some Common Unicode Problems and Solutions using Perl DBD::ODBC and MS SQL Server

QRCode
https://www.easysoft.com/developer/languages/perl/sql-server-unicode.html
February 13, 2018 at 11:08:34 AM EST *
perl mssql unicode
FILLER

What is a Key Lookup? - theBoredDBA.com

QRCode

Therefore I thought I would give a quick explanation for anyone still unsure what a Key Lookup is actually doing and why it’s considered bad.

We all know that Non-Clustered indexes all include the “Clustered Key” of the table. If not, then you do now. And if you have no Clustered Key (ie. Your table is a Heap) then the non-clustered will contain a Row Identifier which is unique and refers back to a specific record within your Heap. This is how a non-clustered index is linked to your table… whether it be via the Clustered Key or the RID.

http://www.theboreddba.com/Categories/indexes/What-is-a-Key-Lookup.aspx
January 17, 2018 at 4:40:08 PM EST *
mssql sql
FILLER

What’s an “Index” and how do they work?

QRCode

We often hear indexes explained using the analogy of an index in the back of a book. You want to find the information about “rabbits” for instance – and so you look that up in the back and find the list of pages that talk about rabbits.

https://matthewmcgiffen.com/2017/06/12/what-is-an-index/
June 19, 2017 at 10:47:06 AM EDT *
sql mssql
FILLER

COALESCE vs. ISNULL T-SQL Functions | T-SQL content from SQL Server Pro

QRCode

The COALESCE and ISNULL T-SQL functions are used to return the first nonnull expression among the input arguments. SQL Server practitioners often wonder what the difference is between the two functions.

http://sqlmag.com/t-sql/coalesce-vs-isnull
June 7, 2017 at 9:41:40 AM EDT *
sql mssql
FILLER

Tricky TSQL: NOT IN (NULL) > The MidnightDBA Star-Times

QRCode
http://www.midnightdba.com/Jen/2016/08/tricky-tsql-not-in-null/
November 15, 2016 at 9:07:00 AM EST *
mssql sql
FILLER

14 SQL Server Indexing Questions You Were Too Shy To Ask

QRCode
https://www.simple-talk.com/sql/performance/14-sql-server-indexing-questions-you-were-too-shy-to-ask/
April 11, 2014 at 11:50:56 AM EDT *
sql mssql
FILLER

Download Microsoft® SQL Server® 2008 R2 Best Practices Analyzer from Official Microsoft Download Center

QRCode
http://www.microsoft.com/en-us/download/details.aspx?id=15289
September 24, 2013 at 10:46:39 AM EDT *
mssql
FILLER

How to Master SQL Server Index Tuning in One Step | Brent Ozar Unlimited

QRCode
http://www.brentozar.com/archive/2013/08/how-to-master-sql-server-index-tuning/
August 21, 2013 at 3:32:54 PM EDT *
mssql
FILLER

The First Things I Look At On A SQL Server – Part 1

QRCode
http://www.i-programmer.info/programming/database/6028-the-first-things-i-look-at-on-a-sql-server-part-1.html
August 21, 2013 at 3:26:55 PM EDT *
mssql
FILLER
2 / 3
Shaarli · The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community · Documentation
Fold Fold all Expand Expand all Are you sure you want to delete this link? Are you sure you want to delete this tag? The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community