ใน MS SQL Server มี Stored Procedure ตัวหนึ่งที่มีประโยชย์ในการจะทำอะไรกับ Table ทุก Table ใน Database ตัวอย่างการใช้ Stored Procedure sp_MSForEachTable นับจำนวน record ทั้งหมดของทุก Table ใน Database EXEC sp_MSForEachTable ‘SELECT ”?”, COUNT(*) FROM ?’ หรือ sp_MSforeachtable @command1=” declare @tmp int select @tmp=count(*) from ?…
Author: ธีระยุทธ์ ประสมพงศ์
c# string concatenations
การต่อ String ใน C# ทำได้ 4 แบบดังนี้ ใช้เครื่องหมาย plus (+) แบบยอดนิยมใช้งานกันบ่อยๆ. string txt = “aaa”+”bbb”+”ccc”; ใช้ string.Concat() สะดวกับการต่อ list หรือ array มาก. string [] s = { “ManU”, “Liverpool”, “Asenal” }; Console.WriteLine(string.Concat(s)); ใช้ string.Format() เหมาะสำหรับต่อ string และจัดการรูปแบบการแสดงผลด้วยไปในคราวเดียวกันเลย. string value1 =…
SQL Server All about DataTime data type
Function GETDATE() AND SYSTEMDATETIME() GETDATE แสดงข้อมูลระดับ miliseconds SYSDATETIME แสดงข้อมูลระดับ nanoseconds. ::select GETDATE() >> “2013-11-14 10:25:24.337” ::select SYSDATETIME() >> “2013-11-14 10:26:14.4002569” การเปรียบเทียบ DataTime data column จะมีปัญหาให้ปวดหัวทุกที่จะทำอย่างไร ถึงจะสะดวกและ Performance ดีที่สุด ตัวอย่างทางเลือกที่ผมใช้งานครับ Convert ให้เป็น INT ไปเลยครับ ดังตัวอย่างนี้ครับ cast(convert(char(8), d.DocCreateDate, 112) as int) between…
Magic table for trigger in SQL Server
ใน SQL Server ในการ insert ,Update and delete ข้อมูลต่างๆที่เกิดขึ้นจะถูกเก็บไว้ใน magic table อยู่ 2 table คือ inserted,deleted tables inserted table จะเก็บข้อมูล recordที่ถูกดำเนินการ และจะเก็บข้อมุลหลังจากการ Update เสร็จสิ้น Deleted table จะเก็บข้อมูล record ที่มีการลบไปล่าสุดและเก็บข้อมุลเก่าก่อนการ Update Record ไว้ ในการเขียน Trigger สำหรับ table ใน SQL Server สำหรับการ…