sql-server – 使用主键创建视图?

前端之家收集整理的这篇文章主要介绍了sql-server – 使用主键创建视图?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建一个包含以下代码的视图
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,但这与创建主键不同.

如果你给我们更多的信息,为什么你想要一个关键在你的看法,也许我们可以帮助.

原文链接:/mssql/82462.html

猜你在找的MsSQL相关文章