I am doing an exercise which removes the IDENTITY property from the target table when using a select into statement.
source table name: Sales.Orders
column name: orderid
column property: int type, not null, defined as a primary key, identity property is defined on the column)
Column name: custid
column property: int type, foreign key, null
target table name: Sales.MyOrders
In the 70-461 exam book - Querying Microsoft SQL Server 2012, chapter 10 p336:
it gives code
ISNULL (orderid + 0, -1) as orderid, --this will remove IDENTITY property and make column not null
Make custid column not null in target able
ISNULL (custid, -1) as custid, --make column not null
I don't understand these two code items, though it works.
Could someone tell me the concepts behind the code?
The code provided in the book:
select isnull (orderid + 0, -1) as orderid, isnull (custid, -1) as custid, empid, isnull (cast(orderdate as date), '19000101') as orderdate, shipcountry, freight into Sales.MyOrders from Sales.Orders where shipcountry = N'Norway';