Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting an array into sql server table

create proc InsertTagsForArticle(@ArticleID int, @TagIDsList nvarchar(max))
as
--...........

The parameter @TagsList contains IDs of tags separated by comma: "18,22, 23". How to insert these IDs into table by more rational way?

EDIT: The question is how to insert an array into sql server table, but not how to parse an array. It's something like foreach operator.

like image 459
Alexandre Avatar asked Sep 24 '26 03:09

Alexandre


1 Answers

As SQL server doesn't support native arrays, there's not much that you can do.

  • Serialize this array and store in a field.
  • Create child table / relations and store individual records there.

Your requirements will dictate what's better for you. But usually normalized approach is working better.

like image 94
Sergio Tulentsev Avatar answered Sep 26 '26 17:09

Sergio Tulentsev