18

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

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

Kermit
  • 33,827
  • 13
  • 85
  • 121
Niketa
  • 453
  • 2
  • 9
  • 24

6 Answers6

23

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.

NotMyName
  • 682
  • 2
  • 7
  • 15
7
insert into student(name) values("The name you wan to insert");

Be careful not to forget to insert the primary key.

sbyd
  • 242
  • 2
  • 4
6

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 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 table_name SET column1 = value1 WHERE condition;
Daisy
  • 288
  • 3
  • 8
2
insert into student (name)
select 'some name'

or

insert into student (name)
values ('some name')
juergen d
  • 201,996
  • 37
  • 293
  • 362
2

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

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

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

Mikko Maunu
  • 41,366
  • 10
  • 132
  • 135
0

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...

B--rian
  • 5,578
  • 10
  • 38
  • 89
  • Here, `student` is the table and no columns are specified, so all columns `(rollno, name, sem, branch)` are taken over from the table. The order of the values is important. – B--rian Nov 05 '19 at 11:45