วันอังคารที่ 14 มกราคม พ.ศ. 2557
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
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 ใน 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
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 แบบไหนดี
วันอาทิตย์ที่ 14 ตุลาคม พ.ศ. 2555
Running A Pathping
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 > 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.