INF: Use User-Defined Data Type to Extract Current Time
ID: Q67410
|
The information in this article applies to:
-
Microsoft SQL Server for OS/2, version 4.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
Issue type :