วันอังคารที่ 14 มกราคม พ.ศ. 2557

Reset ค่าของ Identity Column ใน SQL Server

Reset ค่าของ Identity Column ใน SQL Server


ถ้าคุณเป็นคนหนึ่ง ที่ใช้ Identity column ในตารางบน SQL Server คุณสามารถที่จะกำหนดให้มันเริ่มค่าตรงไหนก็ได้ที่คุณต้องการนะครับ อย่างเช่น ถ้าคุณต้องการที่จะเริ่มค่าที่ 1000 แทนที่จะเป็น 1 คุณก็สามารถที่จะใช้คำสั่งแบบนี้ครับ

DBCC CHECKIDENT (orders, RESEED, 999)

ค่าถัดไปที่มันจะใช้ มันจะเป็น Reseed + 1 ครับ จากที่เรากำหนดให้ Reseed เป็น 999 ค่าที่จะได้ครั้งต่อไปก็คือ 1000 ครับ

อย่างในตัวอย่างเวลาที่เราทำการ Insert ข้อมูลเข้าไปที่เทเบิล orders เราจะได้ค่าใน column ที่กำหนดให้เป็น Identity column เป็น 1000 ครับ

ลองใช้ดูครับ ผมลองแล้ว Work…


เพิ่มประสิทธิภาพ ของ SQL Server DB

เพิ่มประสิทธิภาพ ของ SQL Server DB
Posted on 15/05/2012

เริ่มด้วยการย้าย TempDB

เราทำการย้าย TempDB ไปยัง Disk อื่น ที่ไม่ใช่ Disk ที่ใช้ติดตั้ง SQL Server เพื่อเพิ่มประสิทธฺิภาพในการอ่าน/เขียน ให้มากขึ้น

โดยเราจะทำการย้ายไปยังไดรฟ์ E: ครับ



ทำได้ยังไง

พิมพ์ Script ด้านล่างนี้ครับ



use master;
go
alter database tempdb
modify file (name = tempdev, filename = ‘e:\temp\tempdb.mdf’);
go
alter database tempdb
modify file (name = templog, filename = ‘e:\temp\templog.ldf’);



เมื่อเสร็จแล้วจะได้ Message คล้าย ๆ กับข้างล่างนี้ แปลว่าเสร็จสิ้นการย้าย แต่จะต้องทำการ Restart Database ก่อน จึงจะใช้ได้ครับ

The file “tempdev” has been modified in the system catalog. The new path will be used the next time the database is started.
The file “templog” has been modified in the system catalog. The new path will be used the next time the database is started.




พอเวลาที่เราใช้ DB ไปนาน ๆ แล้วข้อมูลจะเยอะขึ้นและทำให้มีปัญหาในการเข้าถึงข้อมูลที่ต้องการ หรือง่าย ๆ ก็คือมันช้านั้นเอง

ดังนั้นเราจึงควรที่จะทำ

ทำการ Reindex Table

วิธีนี้เราจะสามารถทำได้ทีละ Table นะครับ โดยจะต้องทำดังนี้



use Northwind ;
go
dbcc dbreindex (customers)

go



แล้วจะได้ Message ประมาณนี้ แปลว่าเสร็จพิธี

DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Insert ข้อมูลหลาย ๆ Record ใน Statement เดียว

Insert ข้อมูลหลาย ๆ Record ใน Statement เดียว

ผมเกิดคำถามขึ้นมาว่า ถ้าหากเราต้องการที่จะ Insert ข้อมูลหลาย ๆ Record ใน SQL Server โดยการเขียนคำสั่งแค่คำสั่งเดียว มันจะทำได้ไหม

คำตอบก็คือ “ได้” ครับ มาลองดูกันว่ามันจะทำได้ยังไง

ข้อมูลที่จะ Insert มีอยู่ด้วยกัน 4 ชุดครับ

(‘ADM’, ‘Administrator’)
(‘USR’, ‘User’)
(‘TRN’, ‘Training’)
(‘REC’, ‘Recruit’)

วิธีที่ ๑ ใช้การ Insert แบบปกติ
1: USE YourDB
2: GO
3: INSERT INTO MyTable (FirstCol, SecondCol)
4: VALUES ('ADM', 'Administrator');
5: INSERT INTO MyTable (FirstCol, SecondCol)
6: VALUES ('USR', 'User');
7: INSERT INTO MyTable (FirstCol, SecondCol)
8: VALUES ('TRN', 'Training');
9: INSERT INTO MyTable (FirstCol, SecondCol)
10: VALUES ('REC', 'Recruit');
11: GO

วิธีที่ ๒ ใช้ Union all ครับ

USE YourDB
1: INSERT INTO MyTable (FirstCol, SecondCol)
2: SELECT 'ADM' ,'Administrator'
3: UNION ALL
4: SELECT 'USR' ,'User'
5: UNION ALL
6: SELECT 'TRN' ,'Training'
7: UNION ALL
8: SELECT 'REC' ,'Recruit'
9: GO



วิธีที่ ๓ วิธีนี้ทำได้ใน SQL 2008 Server เท่านั้นนะครับ
1: insert into MyTable values('ADM', 'Administrator'),
2: ('USR', 'User'),
3: ('TRN', 'Training'),
4: ('REC', 'Recruit');

ลองนำไปใช้ดูนะครับ

วันพฤหัสบดีที่ 10 มกราคม พ.ศ. 2556

Proxy script

@echo off
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /t REG_DWORD /v ProxyEnable /d 1 /f > nul
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /V  ProxyServer /D "23.168.200.25:8080" /f >nul
cd /D "%APPDATA%\Mozilla\Firefox\Profiles"
cd *.default
set ffile=%cd%
echo user_pref("network.proxy.type", 1);>>"%ffile%\prefs.js"

set ffile=
cd %windir%
exit

เลือกใช้ Web Proxy แบบไหนดี

แอดมินหลายๆ คน มักเจอคำถามนี้เหมือนกัน บทความนี้จึงขอนำเสนอวิธีต่างๆ และข้อดี ข้อเสีย ของแต่ละวิธีครับ การทำงานของ proxy แบ่งตามมุมมองจากไคลเอนท์ได้ 2 กลุ่มหลักๆ คือ A) Explicit Proxy B) Transparent Proxy Explicit Proxy เป็นการบอกให้ไคลเอนท์รู้ว่า proxy อยู่ที่ไหน และให้ส่งมาที่ proxy ก่อน 1) Manual หรือทำมือ ซึ่งเป็นวิธีที่ง่ายที่สุด วิธีทำ - เปิด IE > Tools > Internet Options > Connections > LAN Settings แล้วระบุชื่อ proxy ลงไป ข้อดี - ง่าย ไม่ซับซ้อน ข้อเสีย - หากมีเครื่องไคลเอนท์จำนวนมาก แอดมินอาจมือหงิกได้ - เวลาเปลี่ยน proxy ก็มือหงิกอีกรอบ 2) Proxy Script วิธีทำ - เอา java script ไปวางไว้ในเวปภายในของบริษัท แล้วทำเช่นเดียวกับ manual แต่ให้ระบุโดยใช้ Use automatic configuration script ชี้ไปยัง url ของ java script ข้อดี - ยังง่ายอยู่ เพราะสามารถหาตัวอย่าง proxy script ได้ในเน็ต - สามารถกำหนดเงื่อนไขแปลกๆ เช่น ทำ load balance กับ proxy สองตัว หรือเลือกได้ว่าเวปไหนออกตรง เวปไหนผ่าน proxy - การแก้ไขทำได้ง่าย เพราะแก้แค่ที่เดียว ข้อเสีย - เวลากำหนดครั้งแรกยังต้องทำทีละเครื่องเช่นเดิม 3) WPAD หรือที่ในหน้า proxy ของ IE บอกว่า Automatically detect setting นั่นเอง วิธีทำ - ใช้ proxy script เจ้าเดิม เพียงแต่เราจะวางให้ถูกที่ถูกทาง โดยมันจะค้นหา proxy script ตามชื่อโดเมนของไคลแอนท์ เช่น ไคลเอนท์ชื่อ pc1.sale.bangkok.modplusplus.com เวลามันค้นหา proxy script ก็จะวิ่งตามนี้ http://wpad.sale.bangkok.modplusplus.com/wpad.dat http://wpad.bangkok.modplusplus.com/wpad.dat http://wpad.modplusplus.com/wpad.dat ดังนั้นหน้าที่เราคือต้องสร้าง DNS A record ชื่อ wpad.modplusplus.com และเปลี่ยนชื่อ proxy script เป็น wpad.dat จากนั้นไปวางในเวปเซิร์ฟเวอร์ที่ชื่อ wpad.modplusplus.com ข้อดี - คอนฟิกที่ไคลเอนท์น้อยกว่าสองแบบแรก ข้อเสีย - ต้องยุ่งกับ DNS - ไคลเอนท์ที่ไม่ได้ join AD อาจใช้งานลำบาก เนื่องจากจะไม่ทราบโดเมนในการค้นหา - ไม่ใช่ทุกแอพพลิเคชั่นที่ใช้งาน WPAD ได้ รายละเอียดเพิ่มเติมอ่านได้ที่ Wikipeia คลิ๊กที่นี่ 4) DHCP ถ้าใครที่ใช้ DHCP กันอยู่แล้วอาจพ่วง proxy script ไปกับ DHCP แทนการใช้ WPAD ก็ได้ครับ วิธีทำ เข้าไปกำหนด proxy option 252 ให้ชี้ไปที่ url ของ proxy script วิธีการขึ้นอยู่กับยี่ห้อของ DHCP server ครับ ถ้าเป็น Microsoft เข้าไป คลิ๊กที่นี่ แล้วอย่าลืมมาเพิ่มในแต่ละ DHCP scope ด้วยนะครับ ข้อดี - ไม่ต้องแตะไคลเอนท์เลย ข้อเสีย - ไคลเอนท์ที่ทำ static IP จะใช้ไม่ได้ ดังนั้นแนะนำให้ทำร่วมกับ WPAD ครับ 5) Microsoft Group Policy Object (GPO) วิธีทำ - เข้าไปกำหนดแบบ manual หรือ proxy script ผ่าน Microsoft Group Policy Management Console (GPMC) ซึ่งจะกระจายให้กับไคลเอนท์ที่อยู่ใน AD ทั้งหมด ข้อดี - ไม่ต้องไปยุ่งกับไคลเอนท์ - ไม่ต้องเข้าไปแก้ไข DNS หรือ DHCP ข้อเสีย - อาจมีปัญหากับอุปกรณ์ mobile หรือ table ซึ่งไม่สามารถ join AD ได้ Transparent Proxy เป็น proxy ใสแจ๋ว ฝั่งไคลเอนท์ไม่รับรู้ว่ามี proxy อยู่ เวลาติดตั้งไม่ต้องยุ่งกับไคลเอนท์ แต่จะมีขั้นตอนติดตั้งที่ยุ่งยากกว่า และแพงกว่า 6) L4 Switch วิธีทำ - ใช้ L4 switch ตรวจสอบว่ามี traffic ใช้พอร์ต 80 หรือ 443 หรือไม่ ถ้ามีจะโยน traffic ดังกล่าวให้ proxy แต่ถ้าไม่ใช่ก็จะปล่อยผ่าน ข้อดี - ไม่ต้องไปยุ่งกับไคลเอนท์ - ไม่ต้องเข้าไปแก้ไข DNS หรือ DHCP - สามารถใช้ได้กับทุกแอพพลิเคชั่น ทุกแพลตฟอร์ม ข้อเสีย - อุปกรณ์ L4 switch มักจะมีราคาแพง บางครั้งอาจแพงกว่า proxy ด้วย 7) WCCP หรือ Web Cache Communication Protocol พัฒนาโดย Cisco ให้ใช้งาน proxy ร่วมกับ Cisco switch แทนการพึ่ง L4 หรือ L7 switch ที่มีราคาแพง วิธีทำ - ทำงานเช่นเดียวกับ L4 switch คือ WCCP router (หรือ WCCP switch) จะส่ง web traffic มาให้ proxy ก่อน แต่ถ้าไม่ใช่ก็จะปล่อยตรง ข้อดี - เหมือนกับ L4 switch - ราคาของ WCCP router มักจะถูกกว่า L4 switch และบางครั้งก็มีมาพร้อมกับ L2/L3 switch เลย ข้อเสีย - proxy ต้องสนับสนุน WCCP protocol ด้วย 8) In-line (or Bridge)< วิธีทำ - เป็น proxy ที่วางขวาง traffic ทั้งหมด ซึ่งบางผู้ผลิตจะทำเป็น firewall/ISP ที่เพิ่มความสามารถในการสแกนข้อมูลที่เป็น HTTP/HTTPS protocol ข้อดี - หากเป็นความสามารถเสริมของ firewall/IPS ก็เพียงแค่เรียกเปิดใช้งาน ไม่จำเป็นต้องติดตั้งอุปกรณ์เพิ่ม ข้อเสีย - หากต้องมี downtime อาจส่งผลกระทบให้ไม่สามารถใช้งานอินเทอร์เน็ตได้ทั้งองค์กรได้ หรือต้องใช้รุ่นที่มี hardware bypass traffic เวลาอุปกรณ์ไม่ทำงาน ซึ่งจะมีราคาสูง

วันอาทิตย์ที่ 14 ตุลาคม พ.ศ. 2555

Running A Pathping

Untitled Document

Running A Pathping Test
Keywords: pathping, disconnect, connection, patch, patching, ISP, path ping, packet loss…
What is a pathping?

A pathping is a tool used to check for losses of network packet integrity between your computer and our servers. As online games are extremely sensitive to packet or data loss, running a pathping is a great way to discover connection issues that may not show up in latency tests like trace routes.
Running a pathping

1. Click Start

2. Depending on OS-

Windows XP: Click Run.
Windows Vista: Click the Start Search text field.
Windows 7: Click in the Search for Programs and Files text field.

3. Depending on OS-

Windows XP: Type CMD and press Enter.
Windows Vista/7: Type CMD. Right-click on the first result, cmd.exe, and select Run as Administrator.

4. In the command window, type the following:

pathping xxx.xxx.xxx.xxx &gt; c:\pathping.txt

Replace the string of x with a server address related to the game connection being tested and press Enter. The list of server addresses for our various games is below.

List of Server AddressesStarCraft II 12.129.202.154
World of Warcraft Get your realm's IP address from Wowpedia
Diablo III
US - 12.129.209.68
EU - 213.155.155.233
KR - 182.162.134.1
Legacy (Diablo, StarCraft, Warcraft) uswest.battle.net
useast.battle.net
asia.battle.net
europe.battle.net

6. A file will be created on your C: drive called "pathping.txt" that contains the pathping information. Please be patient while waiting for the pathping command to complete; it will take several minutes to finish unless an error occurs. You will know it is done when the command prompt reappears.
Reading a pathping

The first block of data that a pathping shows is essentially a mini trace route. Skip that section and look at the second block of data with the percentages.

A clean pathping will have nothing but 0% from your computer to the last hop before our servers. Anything other than 0% indicates loss of packet integrity.

Our servers, usually identified as "attens.net" scramble pathping data once it reaches them. You can disregard any data which typically shows as 100% packet loss once the pathping reaches that point.

If there is consistent packet loss of 1% or more at your router or modem, usually hops zero and one, these components either need a firmware update or have become faulty and will need to be replaced. Packet loss anywhere else along the route should be reported to your ISP. Making a post of your pathping data on our tech forums will alert us of the ISP issue as well, and is much appreciated.

Here is a sample pathping test:

Note. This pathping is for teaching purposes only, and does not indicate any past or current ISP issues.

วันพุธที่ 19 กันยายน พ.ศ. 2555

Restore the Unread Mail folder

Restore the Unread Mail folder The Unread Mail folder is a default Outlook Search Folder. If deleted, you can create it again.

1.In Mail, on the Folder tab, in the New group, click New Search Folder.

Keyboard shortcut To create a new Search Folder, press CTRL+SHIFT+P.

2.In the Reading Mail section, click Unread Mail.

3.Click OK.