fbpx

SQL

Aware’s SQL Manager, Dwain Camps develops the world’s fastest Relational Division solution. The flexibility of his solution can also solve other relational division problems.  http://bit.ly/1mLZ7mL For those who aren’t that familiar with Relational Division, there are certain databases  problems that are best solved using principals from Relational...

In SQL Server 2008, Microsoft added a new SQL query type: the MERGE statement.  This flexible query provides the ability to perform INSERTs, UPDATEs and even DELETEs all within a single statement.  Used in combination with Common Table Expressions (CTEs), this can be a powerful tool...

So far in our blogs, we have talked a bit about performance, so today we’re going to show you a way you can confirm without doubt that you’re writing high-performance T-SQL code. This extremely valuable technique is something Developers and Testers alike should be familiar...

In SQL 2008, Microsoft introduced some new date and time data types to augment the options available in prior versions.  The full list of these data types with detailed explanations can be found in Microsoft Books on Line (BOL), but we’ll list them here with a very...

ผมคิดว่าหลาย ๆ ท่าน คงมีคำถามในใจว่า ทำไมสร้าง index มาแล้ว ทำไมการดึงข้อมูล (query) ยังช้าอยู่เหมือนเดิม ไม่เห็นจะเร็วขึ้นเลย ทั้งๆ ที่ในตำราก็บอกว่าสร้าง index แล้วจะทำให้ดึงข้อมูลได้เร็วขึ้น พอผมได้เข้าไปดูเลยพบว่าคอลัมน์ที่ทำมาใช้เป็น index มันไม่เหมาะสมนี่เอง ข้อมูลหลักแสนหลักล้านในตาราง แต่ดันเอาคอลัมน์ที่มีค่าที่แตกต่างกันเพียง 7 ค่า (SELECT Distinct Column_Name) มาเป็นทำเป็น index ซะงั้น ซึ่งไม่ถูกต้องตามหลักการเลือกคอลัมน์มาเป็น Index นั่นเอง ทำให้การดึงข้อมูลก็จะยังช้าอยู่เหมือนเดิมครับ ผมมีเทคนิคง่ายๆ ในการเลือกคอลัมน์เพื่อใช้สร้าง index มาฝากครับ โดยการใช้สูตรตามด้านล่างนี้ครับ SELECT Distinct Column Name / Number of Rows หมายถึงให้เรา SELECT Distinct...

When I first heard this, it struck me as being a remarkably concise wisdom applicable to virtually any programming task.  The entire quotation is actually: “Make it work, make it fast, then make it pretty… and it isn’t finished until it is pretty!” – SQL MVP Jeff Moden (RedGate’s 2011...

In an earlier blog, we covered a type of auxiliary table (the Tally Table) that can provide a lot of querying flexibility if you have one in your database or construct one in-line to your query.  Today we’re going to talk about another: the Calendar table. The...

The Tally (or Numbers) table is one of the most useful constructs in intermediate-level SQL.  Have you ever written a T-SQL WHILE loop?  How about a CURSOR?  If your answer to either of those questions is yes, you’ve probably been coding some really poor-performing SQL...

In SQL Server 2005, Microsoft introduced the Common Table Expression (CTE). CTEs share similarities with VIEWS and derived tables, but are really not the same as either. Oracle SQL also supports CTEs and while the syntax is basically the same, some of the properties that...

If you learn one new T-SQL (i.e., Microsoft SQL Server) concept today it should be ROW_NUMBER(). Introduced in SQL 2005, this function is one of 4 window ranking functions (the others are RANK(), DENSE_RANK() and NTILE()). Oracle SQL has a similar capability. Let’s first create some...