Insert Values In Table, Mysql Insert Query , Mysql Insert Statement

Enter values in the table by typing the Query

 > insert into t1(c1) values (10) ; 

This can also be written
 > insert into t1 values (10) ; 

Inserting Multiple Values in tables with Multiple Columns
 > insert into t2 values ( 2 , 3) ; 

We can also change order while inserting values by Specifying column numbers in insert query

For example:

 > insert into t2 (c2 , c1) values ( 2 , 3) ;

you will see the table has been filled with values, However in different order.

We have made 2 columns with query 'create table t2 (c1 int , c2 int);'

What if we dont want to enter two values while filling the columns

> insert into t2 values ( 2 ) ; It will give ERROR 'Column count doesn't match' However, that means we cant enter 1 value ?????

What if we just have 1 value???

Answer is YES we can, enter just 1 value but will have to specify column in the insert query,

 > insert into t2 (c1) values (5) ;

now can view the table with records and columns in same manner by typing in the query

> select * from t2 ;

you will see 10 in the second row with 'NULL' in second column

Simple and fast PlanetGhost Mysql Tutorial with Examples.

If You Think This Post has helped you buy us a Coffee :)

Make Donation

  • Other: $

Donate now