You are here: Home >Archive for the ‘Optimization Performance’ Category

MySQL Maintaining Database Tables

Summary: MySQL provides several commands to allow you to maintain database table more efficiently. Those commands enable you to analyze, optimize, check, and repair the database tables. In this tutorial, you will learn those MySQL command to maintain database tables. Analyze table statement Basically analyze table statement allows you to update cardinality of an index column. [...]

Tags: ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Create table dynamically in Procedure Monthly

CREATE PROCEDURE [dbo].[SP_CreateTableMonthly] AS /***************ประกาศตัวแปร***************/ DECLARE @month_n varchar(4) DECLARE @year_n varchar(4) DECLARE @database varchar(100) /**********************************************/ SET @year_n = YEAR(GETDATE()) /***กำหนดปีปัจจุบัน***/ SET @month_n = MONTH(GETDATE()) /***กำหนดเดือนปัจจุบัน***/ IF len(@month_n) <2 /***นับจำนวนเดือนน้อยกว่า 2 ให้เติม 0 นำหน้า**/ BEGIN SET @month_n=’0′+@month_n END SET @database = ‘TableMonthly_’ + @year_n + ” + @month_n /***กำหนดชื่อตารางใหม่**/ /**********************************************/ IF OBJECT_ID (‘dbo.’+@database+”) IS NULL BEGIN [...]

Tags: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL-Difference between Truncate and Delete

Introduction สวัสดีครับ วันนี้จะมาพูดถึงเรื่อง “ความแตกต่างระหว่าง Truncate และ Delete” ซึ่งทั้งสองคำสั่งดังกล่าวก็ใช้สำหรับการลบข้อมูลในตารางเหมือกัน และไม่กระทบกับโครงสร้างตาราง structure แต่ทั้งสอง Command แตกต่างกันทั้งด้าน Syntax, performance, resources etc. เรามาดูข้อกำหนดเหล่านี้กันครับ

Tags: ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Alternative way to get the table’s row count

To get the total row count in a table, we usually use the following select statement: SELECT count(*) FROM table_name This query performs full table scan to get the row count. You can check it by setting SET SHOWPLAN ON for SQL Server 6.5 or SET SHOWPLAN_TEXT ON for SQL Server 7.0/2000. So, if the [...]

Tags: ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Why UNION ALL is faster than UNION?

UNION and UNION ALL เป็นคำสั่งของ SQL Query สำหรับการรวมดาต้าจาก Table ต่างกันตั้งแต่สอง Table ขึั้นไป ซึ่งเป็นการรวมกันโดยจะต้องมีฟิลล์หรือคอลัมน์ที่เท่ากัน เป็นการรวมกันในแนวนอนหรือ Horizontally เรียงตางรำดับจากบนลงล่าง UNION จะนำข้อมูลมารวมกันแล้วเอาค่าที่ไม่ซ้ำกัน(Distinct) ในสองตารางมาแสดงผล UNION ALL จะนำข้อมูลมารวมกันโดยไม่สนใจค่าที่ซ้ำกันหรือ duplicates กัน

Tags: , , , , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS