INF: Use User-Defined Data Type to Extract Current Time

Last reviewed: April 25, 1997
Article ID: Q67410

The information in this article applies to:

  - Microsoft SQL Server version 4.2 for OS/2

SUMMARY

You can create a user-defined data type that extracts the current time. The advantage of using user-defined data types is that you can bind rules and defaults to them for use in several different tables.

MORE INFORMATION

The following is an example of creating a data type with the functionality of extracting the current time by first creating a default, and then binding it to the user data type:

/* First, create the user type "time". Please note that it is defined
   as not null. */

sp_addtype time, "char(8)", "not null" go

/* Next, create the default "timedft". This default uses the string
   function "right" to convert it to type char. */

create default timedft as right (getdate(),8) go

/* Now, bind the result to the user data type. */

sp_binddefault timedft, time

/* Create the table with this user data type. */

create table test (curtime time,
 test int)

/* Since the data type was created as not null, any time a value is not
   supplied for the curtime column, the current time will be input into
   the column. */

insert test (test) values (1)

go

select * from test go

Curtime test ------- --------------

4:24 PM    1


Additional query words: Transact-SQL
Keywords : kbusage SSrvServer
Version : 4.2
Platform : OS/2


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.