Insert values and default on all others columns

683 views Asked by At

I have a very complexeSQL Server table (over 200 columns) and I want to insert new rows manually. My problem is that i want to manually insert only 3 columns, and the others have to be default. Is there a way to mix

INSERT INTO [my_table] DEFAULT VALUES and

INSERT INTO [my_table] ([column_3],[column_5],[column_6]) VALUES ('1','2','3')

so the added row would be

DEFAULT | DEFAULT | 1 | DEFAULT | 2 | 3 | DEFAULT | DEFAULT ..and so on..

Can't find any trick on the net, and I don't want to write 190 "DEFAULT" in a VALUES list.

1

There are 1 answers

7
Mureinik On BEST ANSWER

When you specify a column list in an insert statement, all the columns not specified will get the default value defined for them, or null is a value isn't explicitly defined. So, to make a long story short, you should only specify the columns and the values you care about, and let the database handle the other columns itself:

INSERT INTO [my_table] 
([column_3], [column_5], [column_6])
VALUES ('1', '2', '3')