且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用SQL在表中部分更新列值?

更新时间:2023-11-18 19:45:28

有一个列有很多值是一个非常糟糕的设计。

那是为什么你问你的问题。

我***的建议是学习如何规范你的数据库,因为你现在的设计将来会给你带来很多麻烦。

>
数据库规范化 [ ^ ]



3普通表格数据库教程 [ ^ ]



数据库规范化基础知识 [ ^ ]



如果这种方法是唯一的方法,则可以使用正则表达式来提取值。

Having one column with many values is a very bad design.
That is why you asking your question.
My best advice is to learn how to normalize your database as your current design will give you lots of headaches in the future.

Database normalization[^]

3 Normal Forms Database Tutorial[^]

Database Normalization Basics[^]

If this approach is the only way, then a regular expression can be used to extract the values.
Regex regex = new Regex(@"lvl(?<level>[0-9]+)\=(?<value>[0-9]+)(\\rank=(?<rank>[0-9]+))?");
foreach (Match m in regex.Matches(@"lvl1=100;lvl2=100\rank=2\..."))
{
    int level = int.Parse(m.Groups["level"].Value);
    int value = int.Parse(m.Groups["value"].Value);
    int rank = int.Parse((m.Groups["rank"].Value == "") ? "0" : m.Groups["rank"].Value);
}



如果没有关于逻辑的更多信息,我可以做到***。


Without more info about the logic it is the best I can do.