我创建一个包含以下代码的视图
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,SUM(toplam_kullanim_T2) AS TotalUsageValue,'T2' AS UsageType FROM TblSayacOkumalari GROUP BY CONVERT(NVARCHAR,YEAR(okuma_tarihi)) + 'T3' AS sno,SUM(toplam_kullanim_T3) AS TotalUsageValue,'T3' AS UsageType FROM TblSayacOkumalari GROUP BY CONVERT(NVARCHAR,YEAR(okuma_tarihi)
我想定义CONVERT(nvarchar,YEAR(okuma_tarihi))’T1’作为sno作为主键是可能的?如果可能,我该怎么办?
解决方法
您无法在视图上创建主键.在sql Server中,您可以使用
create an index on a view,但这与创建主键不同.
如果你给我们更多的信息,为什么你想要一个关键在你的看法,也许我们可以帮助.