sql - Cannot insert the value NULL into column XXX. INSERT fails. Insert valid only -


i above message when inserting multiple records table. fair enough data invalid, , cannot inserted. how can tell sql insert valid ones.

currently when error, whole insert fails. sql not insert invalid rows, insert valid rows.

i using syntax similar this

insert mynewtable (columnname1, columnname2, columnname3)     select myvalue1, myvalue2, myvalue3     myoldtable 

i cannot change sql exclude values in clause because database uses eta structure table, if table incorrectly configured, when insert fails.

i wondering if there settings or statement can call first before insert, when set identity_insert on, or something

assuming 1 of myvalue1, myvalue2, myvalue3 null, , there not null constraint on columns of table mynewtable, can choose values constraint not violated using where clause.

insert mynewtable (columnname1, columnname2, columnname3) select myvalue1, myvalue2, myvalue3 myoldtable myvalue1 not null; --myvalue2 , myvalue3 can added                              --with or if table structure has columns                              --defined not null 

here, instead of worrying getting valid values inserted , invalid ones dropped, avoiding invalid values altogether. better solution rather finding way ignore constraint violations.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -