January 27, 2021
Hot Topics:

Quick Start Guide to SQL Server 7 -- Part 3

  • By Karl Moore
  • Send Email »
  • More Articles »

Defaults are one of the simplest concepts within SQL Server. They're just default values set to one side, which you can tie to particular fields.

You can add defaults whilst designing your tables. However the default method demonstrated here allows you to store the default value for multiple fields in one single location, allowing for easier maintenance.

To create a Default:

  • View your Database in Enterprise Manager (as before)
  • Right-click the grey 'Defaults' icon, and select 'New Default'
  • Type in a Name for your Default
  • Specify a Default Value
    • If you're specifying a default text value, enclose it in quotation marks
    • Dates and numbers do not require surrounding quotation marks
  • Click OK to save

To bind a Default to a Field:

  • Create your Default (as before)
    • You can't bind a default until you've first saved and closed it. So ensure you save and close it, then open again at the next step
  • Open your Default by double-clicking on it in Enterprise Manager
  • To bind a Default to a field, click 'Bind Columns', select your table, add the individual fields, then click OK
  • To bind a Default to a particular user defined type (we'll explain these on the next page), click 'Bind UDTs', then check the 'Bind' box for all those to be affected
    • Checking the 'Future Only' box means existing columns using the UDT won't inherit the new default
  • Click OK to save

To edit a Default:

  • Open your Default, remove all dependencies of the Default, then close it by clicking OK
    • In this instance, dependencies are items that relies on this default to work, such as a bound column
    • To view dependencies, right-click on your default, select 'All Tasks', 'Display Dependencies'
    • To remove dependencies, open your Default, then click on both the 'Bind Columns' and 'Bind UDTs' buttons, removing all items that rely on the default
  • Open your Default again and edit as required
  • Click OK
  • Open your Default yet again and rebind the columns as before, closing and saving when finished

Page 4 of 6

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date