Sybase Blog -Anything About Sybase ASE,REP,IQ.

Sunday, February 6, 2011

Default,Rules and User Defined Datatype

Question
=======
Consider a table creation script
create table table1(id int not null,
cost smallmoney default $10
)
will it allow null value in column "cost"?

Answer
======
No


Source (Unleashed)
Question
=======
How to find all tables and columns which are bind with a rule/default?
Answer
======
select "table"=o.name, "column"=c.name,"user"=user_name(uid),"rule"=object_name(domain)
from sysobjects o,syscolumns c
where o.id=c.id
and object_name(c.domain)='rule/default name'

Sequence of events when using datatypes
=================================
sp_addtype ssn_type, 'char(9)', 'not null'
go

create rule ssn_rule as
@ssn between '001111' and '1111111'
or @ssn = 'N/A'
go

create default ssn_default as
'N/A'

sp_bindrule ssn_rule,ssn_type
sp_bindefault ssn_default,ssn_type

create table ssn_table
(ssn ssn_type, name varchar(30))
go
==================
A rule or default bound explicitly to a column override a rule or default bound to a datatype. A subsequent bind to the datatype replaces the bind to the column as long as the column and datatype have the same rule or default prior to modification.

No comments:

Post a Comment