Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding only one value to the table in sql

Tags:

database

mysql

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?

like image 712
Niketa Avatar asked Nov 26 '12 20:11

Niketa


2 Answers

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.

like image 92
NotMyName Avatar answered Sep 21 '22 02:09

NotMyName


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

Be careful not to forget to insert the primary key.

like image 38
sbyd Avatar answered Sep 22 '22 02:09

sbyd