如何在SQL Server中运行“创建表..(col AS(选择sql))”

时间:2019-02-15 07:12:59

标签: sql sql-server

以下脚本可以成功运行:

CREATE TABLE T1 (col1 INT, col2 AS col1 * 2) 
INSERT INTO T1  (col1)VALUES ( 7 )
SELECT * FROM T1 --Result: 7,14

dbfiddle Online Demo

但是如果我希望as select sql会出错,例如:

CREATE TABLE T1 (col1 INT, col2 AS (select xxx from otherTable)) 
INSERT INTO T1  (col1)VALUES ( 7 )
SELECT * FROM T1 --Result: Error,Subqueries are not allowed in this context. Only scalar expressions are allowed.

SQL Server中还有其他等效方法吗?

0 个答案:

没有答案