I don't know whether it is problem with the database or what. For all the tables in my database, for the columns which are declared as primary key are taking NULL values or default values when query like
INSERT INTO TABLE (emp_name,emp_addr,emp_contact,salary)
values ('Jack','127 N F 14 Stillwater','3456786543',8)
where the table consists of emp_id(primary key), emp_name, emp_addr, emp_contact and salary
.
And if i am trying to insert a tuple with
INSERT INTO EMPLOYEE values (NULL,'Jack','127 N F 14 Stillwater','345678543',8)
, it is throwing the error that primary key cannot be null which is supposed to be.
My script for the table creation is..
create table Employee(
emp_id int(11) primary key,
emp_name varchar(25) not null,
emp_addr varchar(40) not null,
emp_contact varchar(10),
salary float(2)
)ENGINE=INNODB;
This is what is happening in my DB
create table sale(sale_id varchar(10) primary key not null,sold_vehicle varchar(12),sm_id int(11), sale_date date)ENGINE=INNODB;
Query OK, 0 rows affected (0.01 sec)
mysql> insert into sale values('s2389','AP28DJ5093',1290,'05-12-2010');
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> insert into sale values('s2420','AP28MY0545',1290,'24-10-2012');
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from sale;
+---------+--------------+-------+------------+
| sale_id | sold_vehicle | sm_id | sale_date |
+---------+--------------+-------+------------+
| s2389 | AP28DJ5093 | 1290 | 0000-00-00 |
| s2420 | AP28MY0545 | 1290 | 0000-00-00 |
+---------+--------------+-------+------------+
2 rows in set (0.00 sec)
mysql> update sale set sale_id = null where sale_id = 's2389';
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> select * from sale;
+---------+--------------+-------+------------+
| sale_id | sold_vehicle | sm_id | sale_date |
+---------+--------------+-------+------------+
| | AP28DJ5093 | 1290 | 0000-00-00 |
| s2420 | AP28MY0545 | 1290 | 0000-00-00 |
+---------+--------------+-------+------------+
2 rows in set (0.00 sec)
mysql> desc sale;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| sale_id | varchar(10) | NO | PRI | NULL | |
| sold_vehicle | varchar(12) | YES | | NULL | |
| sm_id | int(11) | YES | | NULL | |
| sale_date | date | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)