SQL Server:创建表变量,主键约束定义中的错误 [英] SQL Server: creating table variable, error in primary key constraint definition

查看:61
本文介绍了SQL Server:创建表变量,主键约束定义中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用主键创建一个表变量.这两个语句有什么区别?为什么第一个不起作用?

I'm trying to create a table variable with primary key. What is the difference between these two statements? Why the first one does not work?

--This does not work
declare @tabvar table (
    rowid int identity(1, 1) not null,
    var1 int null,
        constraint PK_tabvar_rowid primary key clustered (rowid)
)

--This works
declare @tabvar1 table (
    rowid int identity(1, 1) not null primary key clustered,
    var1 int null
)

推荐答案

类似的行为在 BOL 中有很好的记录.查看 DECLARE TABLE变量

Looks like this behavior is well documented in BOL. Look at the syntax definitions for DECLARE TABLE Variable vs CREATE TABLE.

这篇关于SQL Server:创建表变量,主键约束定义中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆