?
Solved

Differences between CREATE TYPE and sp_addtype

Posted on 2009-02-12
7
Medium Priority
?
2,234 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:pivar
  • 4
  • 3
7 Comments
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 23626749
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.
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 23627072
So, in your situation, you may want to GRANT REFERENCES permission to public for the types created with CREATE TYPE as well.
0
 
LVL 22

Author Comment

by:pivar
ID: 23627177
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.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 23627414
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.
0
 
LVL 22

Author Comment

by:pivar
ID: 23627533
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.
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 23627777
True.  But like I said, I don't think there's a new equivalent for that in SQL Server now.  That capability has, afaik, been lost :-( .
0
 
LVL 22

Author Closing Comment

by:pivar
ID: 31546298
What a pity 8-(.

Thanks for your help.

/peter
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question