[英]Can I add a variable value in mySQL query to table?
I have a table in my database in which I have three fields: Field_1
, Field_2
, Field3
.我的数据库中有一个表,其中包含三个字段:
Field_1
, Field_2
, Field3
。
Field_1
is auto-incremented integer. Field_1
是自动递增的 integer。 Field_2
will be a string value provided by the user. Field_2
将是用户提供的字符串值。 Field_3
should be a concatenation of Field_2
and Field_1
. Field_3
应该是Field_2
和Field_1
的串联。
Example: (1, Dog, Dog1)
should be added to my table without me providing the "Dog1"
input.示例:
(1, Dog, Dog1)
应添加到我的表中,而无需我提供"Dog1"
输入。
How to do this?这个怎么做? I want to make
Field_3
my primary key.我想让
Field_3
我的主键。 I have tried to look for solutions online, but to no use.我试图在网上寻找解决方案,但没有用。 Sorry, if this is a very easy question.
抱歉,如果这是一个非常简单的问题。
How is your values being provided?你的价值观是如何被提供的? If you are having an insert command you could do something like:
如果您有一个插入命令,您可以执行以下操作:
INSERT INTO table (Field_2, Field_3) VALUES (value2, CONCAT(value2, (SELECT MAX(Field_1) FROM table) +1 ))
I am not 100% for the +1 increase you need to check if that works or if you need to do a set before.我不是 100% 的 +1 增加,你需要检查它是否有效,或者你是否需要先做一组。 (dont have an SQL server available right now to check it for you))
(现在没有可用的 SQL 服务器为您检查))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.