How to insert default values in SQL table?

前端 未结 8 942
灰色年华
灰色年华 2020-11-28 06:26

I have a table like this:

create table1 (field1 int,
               field2 int default 5557,
               field3 int default 1337, 
               field4 i         


        
8条回答
  •  情深已故
    2020-11-28 07:07

    Best practice it to list your columns so you're independent of table changes (new column or column order etc)

    insert into table1 (field1, field3)  values (5,10)
    

    However, if you don't want to do this, use the DEFAULT keyword

    insert into table1 values (5, DEFAULT, 10, DEFAULT)
    

提交回复
热议问题