如何使用SQL在表中部分更新列值? [英] How to update column value partially in table using SQL?

查看:50
本文介绍了如何使用SQL在表中部分更新列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在表格中部分更新特定列的值。但是不知道在sql查询中使用哪个命令。



例如

I need to update a value of particular column partially in a table. but don't getting the idea about which command to use in sql query.

e.g.

Id   |Status
-------------
1    |lvl1=100;lvl2=100\rank=2\...





假设lvl1和lvl2是一种游戏等级。



每当玩家重放游戏时值应该是 lvl1 = 0 \\\ nck = 0 \ ...

或积分越高,等级应相应更改。



请帮忙。



Let's say lvl1 and lvl2 are kind of levels of a game.

whenever player replays the game value should be lvl1=0\rank=0\...
or points get higher then rank should be changed accordingly.

Please help.

推荐答案

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

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

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


数据库规范化 [ ^ ]



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.


这篇关于如何使用SQL在表中部分更新列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆