Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a table with array column ms sql

I use ms sql and i need to create a table with a array column of nvarchar. What is the correct query ?

like image 949
Attilio Iurlaro Avatar asked Mar 18 '26 12:03

Attilio Iurlaro


1 Answers

You don't want an array column. You want a separate table (or perhaps a JSON/XML column, but I won't focus on that).

The normal method would be:

create table main (
    main_id int identity primary key,
    . . .
);

create table element (
    element_id int identity primary key,
    position int,
    value varchar(255),
    . . .
);

create table main_elements (
    main_element_id int identity primary key,
    main_id int references main(main_id),
    element_id int references elements(element_id)
);
like image 116
Gordon Linoff Avatar answered Mar 20 '26 00:03

Gordon Linoff



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!