Bunion
Bunion

Reputation: 461

Insert INTO table where one table has a NOT NULL

I have two identical tables bar one column, (one live, one test)

The test table has an extra not null Column called "MatchOrderNo"

I'm trying to extract data from Live to test, how can i populate this not Null for all rows?

basically my current statement is

INSERT INTO test SELECT * FROM live;

Upvotes: 0

Views: 33

Answers (2)

sagi
sagi

Reputation: 40481

Depends what do you want to insert to the NOT NULL column? For a constant value :

INSERT INTO test
SELECT t.* , 'Val_For_NotNull_Col' FROM live t

Upvotes: 3

Jens
Jens

Reputation: 69440

You can use a Default value like:

INSERT INTO test SELECT live.col1, live.co2, '1' FROM live;

Upvotes: 1

Related Questions