MS SQL Basics Tutorial: Database defaults

Source: Internet
Author: User

The default value (default) is data that is automatically inserted in a column that does not specify specific data when the user enters a record. The default value object is similar to the default value specified by the "default" option when the ALTER TABLE or CREATE TABLE command action table, but the default value object can be used with multiple columns or user-defined data types, and its management and application have many similarities to the rules. A column of a table or a user-defined data type can only be bound to a default value.

9.3.1 Create default values

(1) Create default value with creation default command

The Create default command is used to create a default value object in the current database with the following syntax:

CREATE DEFAULT Default_name as Constant_expression

Where the constant_expression clause is the definition of the default value. The constant_expression clause can be a mathematical expression or function, or it can contain a table's column name or other database object.

Example 9-11: Create a birthday default value Birthday_defa.

Create Default Birthday_defa

As ' 1978-1-1 '

Example 9-12: Create a name default value Name_defa.

Create Default Name_defa

As user

(2) Create default values with Enterprise Manager

Select the database object "Defaults" in Enterprise Manager, right-click, and select N "ew Default" from the shortcut menu, which pops up the Create Default Properties dialog box as shown in Figure 9-6. After you enter the default value name and value expression, click OK to complete the creation of the default value.

9.3.2 View default values

(1) Use Enterprise Manager to view default values

Select the "Defaults" object in enterprise Manager to see most of the default values from the taskpad on the right. As shown in Figure 9-7. You can also select the default value to view, right-click, and choose Properties from the shortcut menu, which shows the default Value Properties dialog box shown in Figure 9-8, where you can edit the default value of the

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.