Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we have array type data in sql server 2008

Can we have array type data in sql server 2008 currently i am using comma seperated value to be treated as array value

like image 450
Tushar T. Avatar asked Jun 22 '12 11:06

Tushar T.


People also ask

Is there an array data type in SQL Server?

Conclusion. As you can see, SQL Server does not include arrays. But we can use table variables, temporary tables or the STRING_SPLIT function. However, the STRING_SPLIT function is new and can be used only on SQL Server 2016 or later versions.

Can we declare array in SQL?

Define arrays as SQL variables. Use the ARRAY_AGG built-in function in a cursor declaration, to assign the rows of a single-column result table to elements of an array. Use the cursor to retrieve the array into an SQL out parameter. Use an array constructor to initialize an array.

How do you create an array of columns in SQL?

To create a column of an array type, the [] symbol is used. The following examples illustrate this: create table contacts ( first_name varchar, last_name varchar, phone_numbers varchar[] ); create table player_scores ( player_number integer, round_scores integer[] );

Is there a list data type in SQL?

The LIST data type is a collection type that can store ordered non-NULL elements of the same SQL data type. The LIST data type supports, but does not require, duplicate element values.


1 Answers

SQL Server 2005+ supports table-valued variables:

declare @arr table (col1 int)
insert @arr (col1) values (3), (1), (4)

These are equivalent to arrays.

like image 186
Andomar Avatar answered Oct 22 '22 20:10

Andomar