pivar
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
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
So, in your situation, you may want to GRANT REFERENCES permission to public for the types created with CREATE TYPE as well.
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.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What a pity 8-(.
Thanks for your help.
/peter
Thanks for your help.
/peter
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.