Link to home
Start Free TrialLog in
Avatar of pivar
pivarFlag for Sweden

asked on

Differences between CREATE TYPE and sp_addtype

Hi,

Can anybody answer if there is any practical differences between CREATE TYPE and sp_addtype. The reason I ask is because of a problem I've got with ODBC API SQLColumns. If I create an udt with CREATE TYPE, SQLColumns will not enumerate columns of that datatype, but if I create the same udt with sp_addtype it works as expected.

Thanks,

/peter
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Hmm, maybe it's a security thing, found this in Books Online:

For backward compatibility purposes, the public database role is automatically granted REFERENCES permission on alias data types that are created by using sp_addtype. Note when alias data types are created by using the CREATE TYPE statement instead of sp_addtype, no such automatic grant occurs.
So, in your situation, you may want to GRANT REFERENCES permission to public for the types created with CREATE TYPE as well.
Avatar of pivar

ASKER

Yes, that was the case, had to give it permission. Can I add one small question? Do you know the MS SQL 2005 equivalent of sp_binddefault? If there is any.
You create a DEFAULT constraint.

For example, say you want col1 (which is numeric) to have a a default of 0:

ALTER TABLE tablename
    ADD CONSTRAINT col1_default
        DEFAULT 0  FOR col1

There is no new version of basically assigning a "name" to a default value, where you could say "DEFAULT default_is_zero" and then create the "default_is_zero" "rule" yourself.  Instead, you just put a specific, individual value for each column DEFAULT.
Avatar of pivar

ASKER

Yes, but ALTER TABLE ... DEFAULT creates a default on the column, so I have to do that on every column having this udt. When I bind the default to a udt I don't need to think about setting the default of the column, that comes with the udt.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pivar

ASKER

What a pity 8-(.

Thanks for your help.

/peter