6

I have created a table named 'students'. It has following fields :

 roll_no <- type:Integer Not Null,
 course_name <- type:varchar(40) Not Null,     
 std_surname <- type:varchar(40) Not Null,
 std_firstname <- type:varchar(40) Not Null,      
 emailid <- type:varchar(40) ,   
 address <- type:varchar(40) Not Null,
 income <- type:Integer,        
 gender <- type:varchar(10) Not Null,         
 experience <- type:Integer, 

in the above fields mentioned some accept null values and most of them don't accept null values or null values are not allowed.

What I want to do is I want to insert some information or data into the columns that do not accept null values and then I want to insert remaining data into the remaining columns later. How can I achieve this?

More specifically how can I insert only few data into specific fields in a record at a time using insert query leaving other fields empty and then insert remaining field values like email or experience ???

Please help me with this problem?

Abhijit
  • 129
  • 1
  • 2
  • 11

2 Answers2

7

Insert into selected fields

for ex

    INSERT INTO 
            students
            (roll_no, course_name, dob, gender)
    VALUES
            (111, 'MBA', '1991-01-01', 'F');

for inserting NULL values, have a look at

Insert NULL value into INT column

Community
  • 1
  • 1
Hytool
  • 1,358
  • 1
  • 7
  • 22
3

First insert, you can insert an empty string into the NOT NULL fields, later you can update those fields.

INSERT INTO yourTable (field1, field2, field3) VALUES ("information1", "", "");
UPDATE yourTable SET field2 = "information2", field3 = "information3" WHERE rowId = x;

Forget inserting the empty strings, MySQL will do it by default when you do it as Hytool wrote.

Philipp
  • 2,787
  • 2
  • 25
  • 27