将特定值插入mysql数据库

时间:2022-11-26 15:42:32

I have the following problem: I would't insert all the values in my db. So, i would insert only id,tessera,nome,sex. I thought i had to write something like this:

我有以下问题:我不会在我的数据库中插入所有值。所以,我只会插入id,tessera,nome,sex。我以为我必须写这样的东西:

INSERT INTO  registries(id,tessera,'',nome,sex) VALUES (35983,35983,'DOG', 'FABIO', 'M')

I don't want to insert the DOG value in my db cause I don't have any attribute in my schema to save it. I have 3000 rows and I take this row as example so I can't simply delete the DOG value and the attribute field in my sql query. I remember that I have to use something like this

我不想在我的数据库中插入DOG值因为我的架构中没有任何属性来保存它。我有3000行,我把这一行作为例子,所以我不能简单地删除我的SQL查询中的DOG值和属性字段。我记得我必须使用这样的东西

INSERT INTO  registries(id,tessera,'',nome,sex)

I mean, I have to write '' to not consider the value in that position. but MySQL gives me an error..

我的意思是,我必须写''不考虑那个位置的价值。但是MySQL给了我一个错误..

Can you help me?

你可以帮我吗?

2 个解决方案

#1


0  

You can handle this situation in following ways.

您可以通过以下方式处理这种情况。

  1. create temporary table on same server. Insert all data in temporary table then use insert into select statement and select required fields.

    在同一台服务器上创建临时表。在临时表中插入所有数据,然后使用insert into select语句并选择必填字段。

  2. create temporary column and insert data in that column and delete temporary column

    创建临时列并在该列中插入数据并删除临时列

    INSERT INTO registries (id,tessera,new_column,nome,sex) 
    VALUES (35983, 35983, '', 'FABIO', 'M');
    

Now

现在

DROP COLUMN new_column from registries;

#2


0  

Try this (assuming dog is a column name):

试试这个(假设dog是一个列名):

INSERT INTO  registries (id,tessera,dog_name,nome,sex) VALUES (35983, 35983, '', 'FABIO', 'M')

If dog_name is allowed to be NULL (which it is by default) you could also just not insert any value, like this:

如果允许dog_name为NULL(默认情况下是这样),您也可以不插入任何值,如下所示:

INSERT INTO  registries (id,tessera,nome,sex) VALUES (35983, 35983, 'FABIO', 'M')

#1


0  

You can handle this situation in following ways.

您可以通过以下方式处理这种情况。

  1. create temporary table on same server. Insert all data in temporary table then use insert into select statement and select required fields.

    在同一台服务器上创建临时表。在临时表中插入所有数据,然后使用insert into select语句并选择必填字段。

  2. create temporary column and insert data in that column and delete temporary column

    创建临时列并在该列中插入数据并删除临时列

    INSERT INTO registries (id,tessera,new_column,nome,sex) 
    VALUES (35983, 35983, '', 'FABIO', 'M');
    

Now

现在

DROP COLUMN new_column from registries;

#2


0  

Try this (assuming dog is a column name):

试试这个(假设dog是一个列名):

INSERT INTO  registries (id,tessera,dog_name,nome,sex) VALUES (35983, 35983, '', 'FABIO', 'M')

If dog_name is allowed to be NULL (which it is by default) you could also just not insert any value, like this:

如果允许dog_name为NULL(默认情况下是这样),您也可以不插入任何值,如下所示:

INSERT INTO  registries (id,tessera,nome,sex) VALUES (35983, 35983, 'FABIO', 'M')