Due to an added field in a MsSql Database, I have to change the records in a table from NULL to something more usefull.
I’ve got a table with addresses. Because customers have multiple addresses we’d like to mark certain addresses as default and others as something like shipping.
How can I, using a query, change only the first of every address to “Default” and every other to “Shipping”? Every address has a foreign key relation to the Customers table thru a CustomerId.
It doesn’t really matter which one is made default, as long as one is default and the rest something else. Just to be able to edit the default address in thru the UI of our application and show a table with every other adress.
Assuming that Address table uses a surrogate primary key that is integer based (like an IDENTITY column), and if you really don’t care which one gets marked as DEFAULT, you could do something like the following (which updates the row with the lowest integer value as the DEFAULT).