tsql - How do I insert data in specific columns in SQL Server 2012? -


i using adventureworks2012 database... created backup table using select clause. however, got error message when tried insert data columns using query below:

insert    sales.salesorderdetails_backup                                            (salesorderid ,                                         orderqty,                                             productid,                                           specialofferid,                                          unitprice,                                            unitpricediscount,                                            linetotal)                                        output  inserted.*                 values (57123,                          45,                          712,                            1,                         15.89,                             0,                          45.89) 

i got error msg:

cannot insert value null column 'rowguid', table 'adventureworks2014.sales.salesorderdetails_backup'; column not allow nulls. insert fails...

when define table, can specify "not null" constraint column or columns. means must put value in column insert.

this thing. example, "not null default primary key column.

you have 2 choices:

1) make sure column in question has value before "insert" (preferred)

2) "alter table" drop "not null" constraint:

alter table mytable alter column mycolumn columntype null

also: know, newid() mssql function generate guid "insert".


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -