2020年5月23日 星期六

SQLServer隔離層級RCSI和SI的比較

https://github.com/imrexhuang/SQLServerIsolation-RCSIvsSI/

  • SQL Server預設的隔離層級是RC(Read Committed)
  • 使用Row Version Base的隔離層級,要好好管理TempDB並最佳化、大型交易分批做
  • 使用RCSI要注意副作用(特別是和金額有關),最好不要在舊系統使用,新系統上線前可以完整測試比較安全
  • SQL Server 2005之後支援RSCI(Read Committed Snapshot Isolation)和SI(Snapshot Isolation)的隔離層級,但這兩種層級不支援分散式交易

GROUP BY無法使用alias column name

原因
https://stackoverflow.com/questions/3841295/sql-using-alias-in-group-by

SQL is implemented as if a query was executed in the following order:
  1. FROM clause
  2. WHERE clause
  3. GROUP BY clause
  4. HAVING clause
  5. SELECT clause
  6. ORDER BY clause
For most relational database systems, this order explains which names (columns or aliases) are valid because they must have been introduced in a previous step.
So in Oracle and SQL Server, you cannot use a term in the GROUP BY clause that you define in the SELECT clause because the GROUP BY is executed before the SELECT clause.
There are exceptions though: MySQL and Postgres seem to have additional smartness that allows it.

問題描述:
SELECT country AS c, YEAR(hiredate) AS yearhired, COUNT(*) AS numemployees
FROM HR.Employees
WHERE hiredate >= '20140101'
GROUP BY country, YEAR(hiredate)
-- GROUP BY country, yearhired -- 無效的資料行名稱 'yearhired'。
HAVING COUNT(*) > 1
ORDER BY country, yearhired DESC;
--ORDER BY c, yearhired DESC; --可以執行

2019年10月6日 星期日

The HTTP status code in IIS 7 and later versions

https://support.microsoft.com/en-us/help/943891/the-http-status-code-in-iis-7-0-iis-7-5-and-iis-8-0

IIS設定了URL Rewrite但網頁回應404 Not Found

Pattern設定如下
http://localhost:8080/{R:0}
Rewrite URL設定如下
(examples.+)
因為SSL憑證設定在IIS,目的是把https請求導到Tomcat
但是設定好之後用瀏覽器連https和http都是HTTP 404 Not Found
但用Test pattern測試都是符合的
後來找到一篇文章
https://forums.iis.net/t/1238069.aspx
Did you enable the proxy in IIS manager->server node->application request
routing cache->proxy setting->enable.
發現還需要安裝IIS的ARR(Application Request Routing)模組
安裝ARR模組並啟用"Enable proxy"就正常了
Microsoft Application Request Routing 3.0 (x64)
https://www.microsoft.com/en-us/download/details.aspx?id=47333