如何在SQL Server的单个列中插入逗号值 [英] How to insert comma values in a single column in SQL server
本文介绍了如何在SQL Server的单个列中插入逗号值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
有谁能告诉我,如何在sql server的单个列中插入逗号值,并使用split by comma函数加入它们。
我尝试了什么:
Hi
Can anyone tell me ,How to insert comma values in a single column in sql server and Join them using split by comma function.
What I have tried:
ID Name Dept Sal Techids
1 Abc Mech 20000 1,2,3
Techid Techname
1 Abc
2 def
3 ghi
推荐答案
不要。它是一个使用的PITA,虽然插入值很简单,但它很快就会变成肮脏的。
相反,有一个链接表:
Don't. It's a PITA to use, and though it's simple to insert the values to start with, it rapidly descends into nastiness.
Instead, have a "linking" table:
ID Name Dept Sal
1 Abc Mech 20000
Techid Techname
1 Abc
2 def
3 ghi
DeptTechs
ID DeptId TechId
1 1 1
2 1 2
3 1 3
然后使用当你想要检索它时,JOIN组合信息。
You then use a JOIN to combine information when you want to retrieve it.
SELECT d.*, t.TechName FROM Depts d
JOIN DeptTech dt ON d.ID = dt.DeptId
JOIN Techs t ON d.TechID = t.ID
这样,添加和删除技术是一项微不足道的工作:只需删除链接行。
That way, adding and removing techs is a trivial job: just delete the linking row.
这篇关于如何在SQL Server的单个列中插入逗号值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文