-1

I've created a table schema and specified that for some attributes, values cannot be null. For one column of this table, values are to be imported from a column of some another table but the problem i am facing is that when i use insert statement to copy values from that column of another table to the column of this newly created table, the attributes of this new column start screaming because they kind of have a constraint on them that while insertion their values cannot be NULL! How do i cope with this?

One solution is that for other attributes, just for time being, i can state that null values can be accommodated so that i can successfully import values from column of other table and then later on put condition on the remaining attributes that values are not be NULL. But how do i do do this?

Aisha Javed
  • 169
  • 13
  • can you post the code you are using for the insertion and also what sql engine you are using? – Fuzzy Mar 02 '16 at 19:08
  • you're trying to put null value in non null column, what do you expect to see in result? such row should be either skipped or null value should be replaced with some real one – Iłya Bursov Mar 02 '16 at 19:11

2 Answers2

0

You need to convert NULL to some DEFAULT values while importing.

I am not sure which DB engine you are using, in mysql: Use something like IFNULL(column_name, "").

Reference

cosmos
  • 2,263
  • 1
  • 17
  • 30
-1

You may simply be looking for the default clause. When you define a column, you can specify;

intcol int not null default 0

If the column is not specified for an insert, then it will default to 0. In some databases, if a NULL value is supplied, it will also get the default value.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786