MySQL sql中只向表中添加一个值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13572610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:34:19  来源:igfitidea点击:

Adding only one value to the table in sql

mysqldatabase

提问by Niketa

I have a table named studentwhich consists of (rollno, name, sem, branch)

我有一个名为的表student,它由 ( rollno, name, sem, branch)

If I want to INSERTonly one value (i.e only name has to be entered) what is the query?

如果我只想输入INSERT一个值(即只需要输入名称),查询是什么?

回答by NotMyName

To insert values into specific columns, you first have to specify which columns you want to populate. The query would look like this:

要将值插入特定列,您首先必须指定要填充的列。查询将如下所示:

INSERT INTO your_table_name (your_column_name)
VALUES (the_value);

To insert values into more than one column, separate the column names with a comma and insert the values in the same order you added the column names:

要将值插入到多个列中,请用逗号分隔列名,并按照添加列名的相同顺序插入值:

INSERT INTO your_table_name (your_column_name_01, your_column_name_02)
VALUES (the_value_01, the_value_02);

If you are unsure, have a look at W3Schools.com. They usually have explanations with examples.

如果您不确定,请查看 W3Schools.com。他们通常有例子的解释。

回答by sbyd

insert into student(name) values("The name you wan to insert");

Be careful not to forget to insert the primary key.

注意不要忘记插入主键。

回答by juergen d

insert into student (name)
select 'some name'

or

或者

insert into student (name)
values ('some name')

回答by Mikko Maunu

Following works if other columns accept null or do have default value:

如果其他列接受 null 或确实具有默认值,则以下工作:

INSERT INTO Student (name) VALUES('Hyman');

Further details can be found from the Reference Manual:: 13.2.5 INSERT Syntax.

可以从参考手册:: 13.2.5 INSERT Syntax 中找到更多详细信息。

回答by Daisy

First, if the table is all empty, just wanna make the column 'name' with values, it is easy to use INSERT INTO. https://www.w3schools.com/sql/sql_insert.asp.

首先,如果表都是空的,只是想让列“名称”带有值,使用 INSERT INTO 很容易。https://www.w3schools.com/sql/sql_insert.asp

`INSERT INTO TABLE_NAME (COLUMN_NAME) VALUES ("the values")` 

Second, if the table is already with some values inside, and only wanna insert some values for one column, use UPDATE. https://www.w3schools.com/sql/sql_update.asp

其次,如果表中已经有一些值,并且只想为一列插入一些值,请使用 UPDATE。https://www.w3schools.com/sql/sql_update.asp

  UPDATE table_name SET column1 = value1 WHERE condition;

回答by arun sivaraman menon

Execute this query, if you want the rest of columns as "#", do insert #inside the single quote which is left blank in query.

执行此查询,如果您希望将其余列作为"#",请#在查询中留空的单引号内插入。

Also, there is no need of defining column name in the query.

此外,不需要在查询中定义列名。

insert into student values('','your name','','');

Thanks...

谢谢...