Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error While creating user defined table type in SQL Server 2008 R2

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?

like image 353
Ashu Avatar asked Nov 18 '25 05:11

Ashu


1 Answers

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))
like image 66
John W. Mnisi Avatar answered Nov 20 '25 10:11

John W. Mnisi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!