顯示具有 value was either too large or too small for an int16 標籤的文章。 顯示所有文章
顯示具有 value was either too large or too small for an int16 標籤的文章。 顯示所有文章

2015年4月13日 星期一

EOSL:MSSQL2000-取用SQL Table ID

螺絲筆記編號:MSSQL-001

老舊主機系統螺絲鬆脫,維護開始
系統環境:MS2K;SQL2K;ASP.Net1.1;VS2003

錯誤訊息:value was either too large or too small for an int16

====================================================
發現資料庫 int大小 :並未超過上限值
參考連結:https://msdn.microsoft.com/zh-tw/library/ms187745.aspx

發現資料表中欄位紀錄 int,4,數值 32768
有點微妙的印象,而且系統正常,只是無法新增,可以刪除...!?
開code確認,
  有使用Convert.ToInt16做資料型別轉換
[目標發現]
參考連結:https://msdn.microsoft.com/zh-tw/library/b1kwkfdz(v=vs.110).aspx

蠻遺憾舊系統未獲取重構申請
只好動手調資料庫資料
果然符合期待順利修復系統
  但是耗時4h+訓話1h  (螺絲金燦燦囉)
====================================================
為解決未來工時冗長勞材傷民;列載以下步驟
1.Rownumber (ms sql 2000)
這需要MSSQL2005以上才有的功能,MSSQL2000是沒有滴
頭恨大又有印象,這次找到一定要記下來
參考連結:https://support.microsoft.com/zh-hk/kb/273586/zh-tw

連結文中狀況2:非常適合系統的需求
差異是需要重建ID編號,但不需要新增資料欄

2.Select Into  (ms sql 2000)
使用新增資料表語法快速篩選出需要的資料表
select 目標欄位名稱 = identity(int,1,1),原欄位名稱 into tableNeo
 from tableOld
[ where 條件式成立 order by 排序欄位 ]

驗證結果:
select top 1 * from tableNeo
螺帽提示:中文表列無法理解的朋友,請看步驟1連結

3.drop table (ms sql 2000)
drop table tableOld

螺帽提示:這段應該大家都會,怕失手請先備份資料庫(表)

4.table rename (ms sql 2000)
EXEC sp_rename 'tableNeo', 'tableOld'
螺帽提示:這段應該大家都會,怕失手請先備份資料庫(表)
====================================================
個人筆記紀錄拙劣,各位前輩請海涵