gt6*_*89b 13 sql sql-server create-table
我创建了我定义的表类型
CREATE TYPE dbo.MyTableType AS TABLE
(
Name varchar(10) NOT NULL,
ValueDate date NOT NULL,
TenorSize smallint NOT NULL,
TenorUnit char(1) NOT NULL,
Rate float NOT NULL
PRIMARY KEY (Name, ValueDate, TenorSize, TenorUnit)
);
Run Code Online (Sandbox Code Playgroud)
我想创建一个这种类型的表.从这个答案,建议是尝试
CREATE TABLE dbo.MyNewTable AS dbo.MyTableType
Run Code Online (Sandbox Code Playgroud)
在我的SQL Server Express 2012中产生以下错误消息:
关键字"OF"附近的语法不正确.
SQL Server Express不支持此功能吗?如果是这样,我可以用其他方式创建它,例如使用DECLARE
?
Dav*_*son 23
--Create table variable from type.
DECLARE @Table AS dbo.MyTableType
--Create new permanent/physical table by selecting into from the temp table.
SELECT *
INTO dbo.NewTable
FROM @Table
WHERE 1 = 2
--Verify table exists and review structure.
SELECT *
FROM dbo.NewTable
Run Code Online (Sandbox Code Playgroud)
它就像 sql server 中的其他日期类型。创建用户定义类型的表在 sql server 中没有这样的东西。你可以做的是声明一个这种类型的变量并填充它,但你不能创建一个这种类型的表。
像这样的东西...
/* Declare a variable of this type */
DECLARE @My_Table_Var AS dbo.MyTableType;
/* Populate the table with data */
INSERT INTO @My_Table_Var
SELECT Col1, Col2, Col3 ,.....
FROM Source_Table
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
29426 次 |
最近记录: |