Udostępnij za pośrednictwem


UserDefinedDatatype Object

This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

The UserDefinedDatatype object exposes the attributes of a single Microsoft® SQL Server™ user-specified data type.

Properties

AllowIdentity Property

MaxSize Property

AllowNulls Property

Name Property

BaseType Property

NumericPrecision Property

Default Property (Column, UserDefinedDatatype)

NumericScale Property

DefaultOwner Property

Owner Property (Database, UserDefinedFunction)

ID Property

Rule Property

IsVariableLength Property

RuleOwner Property

Length Property

Methods

BindDefault Method

ListBoundColumns Method

BindRule Method

Remove Method (Objects)

GenerateSQL Method (Table, UserDefinedDatatype)

Script Method

Remarks

SQL Server allows specification of data types. User-specified data types consist of a SQL Server base data type, the data length (if applicable), the data precision or scale (if applicable), and an indication of the ability of the data type to accept NULL values.

User-specified data types are targets for SQL Server rule binding. The user-specified data type can be used in place of a SQL Server base data type when specifying the columns of a SQL Server table.

With the UserDefinedDatatype object, you can:

  • Create a SQL Server user-defined data type.
  • List columns in a database that use the data type.
  • Generate a Transact-SQL script to re-create the data type.
  • Remove a SQL Server user-defined data type.

The Name property of a UserDefinedDatatype object is the type parameter of the sp_addtype system stored procedure, which is unique within a database.

To create a SQL Server user-specified data type

  1. Create a UserDefinedDatatype object.

  2. Set the Name property.

  3. Set the BaseType property to the name of the SQL Server base data type. The names of SQL Server base data types are visible as the Name property of the SystemDatatype object.

  4. Set the Length property (if applicable). For example, to define a data type for variable character data of up to 20 characters, set the BaseType property to varchar and set the Length property to 20.

  5. Set the NumericPrecision and NumericScale properties as applicable. For example, to define a numeric data type having 1 digit to the left of the decimal and 5 to the right, set the BaseType property to decimal, the NumericPrecision property to 6, and the NumericScale property to 5.

  6. Set the AllowNulls property.

  7. Add the UserDefinedDatatype object to the UserDefinedDatatypes collection of a connected SQLServer Database object.

To remove a SQL Server user-specified data type

  1. Get the appropriate UserDefinedDatatype object from the UserDefinedDatatypes collection of a connected SQLServer Database object.

  2. Use the ListBoundColumns method to determine the SQL Server columns that depend on the data type. Drop these columns to free the data type of dependencies. You can use the Remove method of the Column object to drop columns dependent on the data type.

  3. Use the Remove method of the UserDefinedDatatype to remove the data type definition from the SQL Server.

Note

The UserDefinedDatatype object is compatible with instances of SQL Server 2000 and SQL Server version 7.0. However, the UserDefinedDatatype2 object extends the functionality of the UserDefinedDatatype object for use with features that are new in SQL Server 2000.

See Also

Reference

UserDefinedDataType2 Object

Other Resources

sp_addtype (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance