ID Number: Q67410
1.10 1.11 4.20
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.
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 reference words: 1.10 1.11 4.20 Transact-SQL