在網上查了一些關於更改SQL SERVER2012資料庫安裝後的默認排序規則(Server Collation)的方法。經過實踐測試,把成功的方法記錄於此,方便大家查閱。具體的操作還是比較簡單的:1.首先打開命令提示符,即win+r,在彈出的窗口中輸入cmd即可進入命令提示符窗口;2.在命令提示符窗口中定位在你的SQL SERVER 2012安裝包的根目錄(注意:是SQL SERVER 2012的安裝包喲)如我的安裝在D盤的Download文件夾下的SQLSERVER2012SP1文件夾下,那麼就進行到SQLSERVER2012SP1這個目錄下3.最後運行如下命令:D:DownloadSQLServer2012SP1>Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=account /SAPWD=xxxxxxxx /SQLCOLLATION=Chinese_PRC_CI_AS
即可更改SQL SERVER 2012的默認排序規則(Server Collation)。第三步中的參數說明:INSTANCENAME:資料庫的實例名,默認的就是:你的資料庫管理賬號SAPWD:sa賬戶的密碼,可選SQLCOLLATION:需要修改成的排序規則
2. sql表中數據排列問題
selectpersonid,dressdate,name,casewhencolumn_1!=''then'column_1'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_1!=''unionall
selectpersonid,dressdate,name,casewhencolumn_2!=''then'column_2'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_2!=''unionall
selectpersonid,dressdate,name,casewhencolumn_3!=''then'column_3'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_3!=''unionall
selectpersonid,dressdate,name,casewhencolumn_4!=''then'column_4'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_4!=''unionall
selectpersonid,dressdate,name,casewhencolumn_5!=''then'column_5'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_5!=''unionall
selectpersonid,dressdate,name,casewhencolumn_6!=''then'column_6'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_6!=''unionall
selectpersonid,dressdate,name,casewhencolumn_7!=''then'column_7'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_7!=''unionall
selectpersonid,dressdate,name,casewhencolumn_8!=''then'column_8'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_8!=''unionall
selectpersonid,dressdate,name,casewhencolumn_9!=''then'column_9'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_9!=''unionall
selectpersonid,dressdate,name,casewhencolumn_10!=''then'column_10'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_10!=''unionall
selectpersonid,dressdate,name,casewhencolumn_11!=''then'column_11'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_11!=''unionall
selectpersonid,dressdate,name,casewhencolumn_12!=''then'column_12'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_12!=''unionall
selectpersonid,dressdate,name,casewhencolumn_13!=''then'column_13'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_13!=''unionall
selectpersonid,dressdate,name,casewhencolumn_14!=''then'column_14'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_14!=''unionall
selectpersonid,dressdate,name,casewhencolumn_15!=''then'column_15'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_15!=''unionall
selectpersonid,dressdate,name,casewhencolumn_16!=''then'column_16'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_16!=''unionall
selectpersonid,dressdate,name,casewhencolumn_17!=''then'column_17'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_17!=''unionall
selectpersonid,dressdate,name,casewhencolumn_18!=''then'column_18'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_18!=''unionall
selectpersonid,dressdate,name,casewhencolumn_19!=''then'column_19'endcolumn_fromZG_JUDGMENTDETAIL_Cwherecolumn_19!=''
3. sql資料庫數字排序問題
ORDER BY cast(你的欄位名 as int)
這里的原因是因為你的那個欄位雖然存儲了數字值,但是它是一個字元型
而字元型的 '2' 比 '11'要大 因為是從第一個字母開始比其的
4. sql 根據數量進行排序
Select Top 10 A.p_id, B.p_name, SUM(A.p_number) as SumNumber, SUM(A.p_price) as SumPrice from OrderDetails A left join Proct B ON A.p_id = B.p_id Group By A.p_id, B.p_name Order by SUM(A.p_number) DESC說明:查詢結果中p_id是商品ID, p_name是商品名稱,SumNumber是總數量,SumPrice是總售價記錄根據總數量(SumNumber)來排序取前十條記錄。另外,在聯合查詢中使用left join 查詢時最有效率的查詢方法
5. sql中表的數據的排序方式如何修改
系統默認是以聚集索引排序,主鍵默認是聚集索引,也可手動改成非聚集索引,你可以添加一列標識列,就是自增列,然後把聚集索引給這列,系統就會默認按添加順序排了
6. sql數據排序
最簡單的方法是增加一個置頂欄位,每個公司只有唯一一個。然後先按置頂欄位排序,再按時間排序。
select * from company,proct
where company.id = proct.company_id
order by proct.ding ,datetime
如果非要在一個query里解決。
select count(*),* from company,proct
where company.id = proct.company_id
group by company.id
union
select 1,* from company,proct
where company.id = proct.company_id
and proct.id not in (
select proct.id from (select count(*),* from company,proct
where company.id = proct.company_id
group by company.id))
order by datetime
但是這樣的效率非常差。
7. sqlserver數據表排序問題
不曉得你這個NewId()方法是怎麼寫的,我自己也寫過一個類似的方法,思路是這樣的:
首先,獲取數據表的行數。
然後在NewId()方法里int id=行數+1,這樣就保證了插入的數據永遠排在最後一行。
8. 怎麼把sql資料庫里記錄排序
資料庫裡面的順序本來就不受你控制,除非是使用聚集索引。
正常情況下查詢數據是可以使用order
by來將輸出結果排序,至於資料庫內部你控制不了也沒必要關心。
9. sql獲取記錄總數後,按總數排序
SELECT user表.id, COUNT(news.title)
FROM user表 LEFT JOIN news
ON user表.id = news.userid
GROUP BY user表.id
ORDER BY COUNT(news.title) DESC
10. sql資料庫自動排序
那就不要在資料庫處理的時候排序
你取出來的數據放到數組里
自己寫個方法來排序