我創建具有以下代碼使用主鍵創建視圖?
SELECT
CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1' AS sno,
YEAR(okuma_tarihi) AS Yillar,
SUM(toplam_kullanim_T1) AS TotalUsageValue, 'T1' AS UsageType
FROM
TblSayacOkumalari
GROUP BY
CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1', YEAR(okuma_tarihi)
UNION ALL
SELECT
CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T2' AS sno,
YEAR(okuma_tarihi) AS Yillar,
SUM(toplam_kullanim_T2) AS TotalUsageValue, 'T2' AS UsageType
FROM
TblSayacOkumalari
GROUP BY
CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1', YEAR(okuma_tarihi)
UNION ALL
SELECT
CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T3' AS sno,
YEAR(okuma_tarihi) AS Yillar,
SUM(toplam_kullanim_T3) AS TotalUsageValue, 'T3' AS UsageType
FROM
TblSayacOkumalari
GROUP BY
CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1', YEAR(okuma_tarihi)
我想定義CONVERT(nvarchar, YEAR(okuma_tarihi)) + 'T1' AS sno
作爲主鍵是可能的視圖?如果這是可能的,我該怎麼辦?
我從視圖創建模型,並將sno manualy更改爲實體鍵。當我更新模型時,我必須將其更改爲實體鍵。這對我來說不是功能上的。 – 2012-07-11 17:58:57
「如果您向我們提供更多關於您爲什麼要在視圖上顯示按鍵的信息」 - Entity Framework將發出警告,提示視圖沒有主鍵:「錯誤6002:表/視圖'mydb.dbo.myview'不定義主鍵...' – Ivan 2012-12-14 10:18:45
@Ivan以下鏈接可以幫助這種情況:http://stackoverflow.com/a/2715299/1464699 – 2012-12-14 14:04:26