Reputation: 51
I am trying to create a user defined table type in SQL Server 2008 R2 version but unable to create.
Using the following query
create type <table_type_name> as table
(
UserId int,
FirstName varchar(50)
)
It shows the error message "157, Incorrect syntax near keyword AS."
Also I want to mention one thing that in the folder hierarchy of the SQL Server under the Programmability -> Types folder I am not able to see the folder "User Defined Table Type".
Is there any way to fix this problem?
Upvotes: 3
Views: 3564
Reputation: 77737
User-defined table types were introduced in SQL Server 2008. Possibly you are connecting to a SQL Server instance whose version is lower.
Upvotes: 3
Reputation: 907
You must specify the name of your user defined table, eg [TypeName} on the query. You must include square brackets if you want to use type as your user defined table name eg [type].
Use the following:
create type [TypeName] as table
(UserId int,
FirstName varchar(50))
Upvotes: 4