473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Create UDDT - good idea?

I'm designing a new database from scratch. It has some columns that I
currently have as datatype=int with check constraint of x>=1 and x
<=32, or others with a range of 1-3, etc. It occurred to me I could
create a UDDT to represent each. Benefit would be that I don't have to
enter the check constraints all the time.

Is there any consensus on whether or not this is a good idea? I am a
bit concerned my front-end application (.NET) will not be able to
recognize these types as easily as "int".

If you have any experience using a CLR-defined type in SQL Server I'd
love to hear from you too.

-Tom.
Oct 24 '08 #1
5 4198
I avoid user defined data types. In theory they should save work, but
in practice they obscure things that would be clear if the basic data
type were used. And the support for them in SQL Server can be a bit
painful to deal with, particularly if one of them has to change.

Roy Harvey
Beacon Falls, CT

On Thu, 23 Oct 2008 19:17:22 -0700, Tom van Stiphout
<to*************@cox.netwrote:
>I'm designing a new database from scratch. It has some columns that I
currently have as datatype=int with check constraint of x>=1 and x
<=32, or others with a range of 1-3, etc. It occurred to me I could
create a UDDT to represent each. Benefit would be that I don't have to
enter the check constraints all the time.

Is there any consensus on whether or not this is a good idea? I am a
bit concerned my front-end application (.NET) will not be able to
recognize these types as easily as "int".

If you have any experience using a CLR-defined type in SQL Server I'd
love to hear from you too.

-Tom.
Oct 24 '08 #2
Hello Tom,
I'm designing a new database from scratch. It has some columns that I
currently have as datatype=int with check constraint of x>=1 and x
<=32, or others with a range of 1-3, etc. It occurred to me I could
create a UDDT to represent each. Benefit would be that I don't have to
enter the check constraints all the time.

Is there any consensus on whether or not this is a good idea? I am a
bit concerned my front-end application (.NET) will not be able to
recognize these types as easily as "int".

If you have any experience using a CLR-defined type in SQL Server I'd
love to hear from you too.
In my opinion, there's a difference between user defined types and
what other engines call "domains". A CRL-based type would be a
true "user defined type", while if you're talking about an INT with
an additional constraint, you're actually sub-typing an existing types
or defining a "domain of valid values" for a data-type. SQL Server
used to call these "User Defined Datatypes" ( I believe ).

You're safe to use these (instead of the CLR type) and yes you client
applications will be able to recognize those as being of type "int".
--
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Sybase
SQL Anywhere, Oracle & MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com
Oct 24 '08 #3
Tom van Stiphout (to*************@cox.net) writes:
I'm designing a new database from scratch. It has some columns that I
currently have as datatype=int with check constraint of x>=1 and x
<=32, or others with a range of 1-3, etc. It occurred to me I could
create a UDDT to represent each. Benefit would be that I don't have to
enter the check constraints all the time.

Is there any consensus on whether or not this is a good idea? I am a
bit concerned my front-end application (.NET) will not be able to
recognize these types as easily as "int".

If you have any experience using a CLR-defined type in SQL Server I'd
love to hear from you too.
There is some confusion here. The CREATE TYPE command can be used to
define types in two ways:

CREATE TYPE mytype FROM varchar(23)
CREATE TYPE mytype EXTERNAL NAME ...

The former is known as "alias data types" in Books Online and User-Defined
Data types" in Mgmt Studio. MS appears to prefer User-Defined Types (UDT)
for the latter. I prefer to call them CLR types.

It seems that you have CLR types in mind, but I am not sure.

Anyway, I think that creating a CLR type to encode an integer value
that may only be a in certain range, is making thins overly complex.

On the other hand, using an alias data type could be a could solution
in lieu of a domain:

CREATE TYPE mytype AS tinyint
CREATE RULE myrule AS @x IN (1, 2, 3)
EXEC sp_bindrule myrule, mytype1to3

Bound rules and defaults have been deprecated, and originally Microsoft
said that SQL 2008 would be the last version to have them. I beat them
up over that, pointing out that as long as they don't have real domains,
they need to keep bound rules and defauls.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Oct 24 '08 #4
>Is there any consensus on whether or not this is a good idea?<<

Bad idea.
>I am a bit concerned my front-end application (.NET) will not be able to recognize these types as easily as INTEGER. <<
And neither will any other piece of software that uses Standard SQL.
You are locking yourself in the MS ghetto in a world of heterogeneous
data sources.
>If you have any experience using a CLR-defined type in SQL Server I'd love to hear from you too. <<
I have a client who is trying to get rid of them from a disaster. Not
all CLR languages agree on how to represent Booleans, how MOD() works
and other things.

Remember back when you were a procedural language programmer? The
late Ken Henderson had a great safety still applies to DDL and
declarative code, too. Someone maintaining code has to be much
smarter than the person who wrote it -- they have to figure out what
he did and what he meant to do.

So if you write the trickiest, most proprietary code you can, then you
have to be much smarter than yourself to even be able to read. What
chance dos the other guy have?

Repeat after me: "My favorite flavor of code is VANILLA! I will not
write Chunky Monkey Squid code! "
Oct 26 '08 #5
Bound rules and defaults have been deprecated, and originally Microsoft
said that SQL 2008 would be the last version to have them. I beat them
up over that, pointing out that as long as they don't have real domains,
they need to keep bound rules and defauls.
Nice one Erland :-)
--
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Sybase
SQL Anywhere, Oracle & MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com
Oct 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Lauzon | last post by:
This is not for a class, I have a group on SourceForge, this is what one of the Developers is asking; the more advanced you can make it right off all the better!: Can someone please create...
7
by: sea | last post by:
Is it a good idea to programatically create a primary key? For example in a table called names, I have the following fields, (1) firstname (2)lastname (3) ID - will it be ok to create a primary...
2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
2
by: Migrant | last post by:
Hi Friends; I want develop a group logic with C# (n tier refraction).I know I must create a Class and inherit it But I don't have enough know-how about develop classes. Somebody can help me? ...
6
by: Pierre Rouleau | last post by:
Hi all, Is there any reason that under Python you cannot instantiate the object class and create any attributes like you would be able for a normal class? Python 2.4.2 (#67, Sep 28 2005,...
3
by: weston | last post by:
I'm making a foray into trying to create custom vertical scrollbars and sliders, and thought I had a basic idea how to do it, but seem to be having some trouble with the implementation. My...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
12
by: tekctrl | last post by:
Environment; Win2K PC with 1Gb of RAM and plenty of HD space running Access 2002 Issue; Access presents a blank data entry form in the Forms view when the New Record icon is used. However, it...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.