以下脚本可以成功运行:
CREATE TABLE T1 (col1 INT, col2 AS col1 * 2)
INSERT INTO T1 (col1)VALUES ( 7 )
SELECT * FROM T1 --Result: 7,14
但是如果我希望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中还有其他等效方法吗?