473,804 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using User defined type instead of varchars

A common request for enhancement to applications is to "make this
field bigger". I know I've been caught with increasing a field size,
and then spending hours debugging because another stored proc has a
variable or temp table that uses the field defined as the original
varchar size. SQL Server just truncates to fit the data into the
smaller varchar, and so there are no errors raised.

An option suggested by a colleague is to no longer use varchars, but
use User Defined Types instead. To make this work effectively,
though, they suggest we would need to make it a rule that we do not
use varchars anywhere except to define user defined types.

Though there will be one point of changes I can't help thinking this
isn't a very good idea ! Any thoughts ?

Thanks.
Jul 20 '05 #1
2 1994
ma*****@tmw.co. uk (Miles Ashton) wrote in message news:<bb******* *************** ****@posting.go ogle.com>...
A common request for enhancement to applications is to "make this
field bigger". I know I've been caught with increasing a field size,
and then spending hours debugging because another stored proc has a
variable or temp table that uses the field defined as the original
varchar size. SQL Server just truncates to fit the data into the
smaller varchar, and so there are no errors raised.

An option suggested by a colleague is to no longer use varchars, but
use User Defined Types instead. To make this work effectively,
though, they suggest we would need to make it a rule that we do not
use varchars anywhere except to define user defined types.

Though there will be one point of changes I can't help thinking this
isn't a very good idea ! Any thoughts ?

Thanks.


MSSQL will raise an error and will not INSERT the data if SET
ANSI_WARNINGS is ON, so I guess for some reason you have it OFF. This
is not recommended, because some queries (distributed queries, indexed
views) require it to be ON.

If you were to use a UDDT, then you would have the issue that you
cannot modify a UDDT, you can only drop and recreate it. So to change
your definition, you would need to unbind it, drop it, recreate it and
bind it again. This may or may not be less effort than modifying your
stored procedure code.

I suspect that the best solution to your issue is to use source code
control, and understand what your dependencies are. Although
sp_depends is not 100% reliable, you can query syscomments directly to
find out which procedures reference a table.

Simon
Jul 20 '05 #2
Simon Hayes (sq*@hayes.ch) writes:
MSSQL will raise an error and will not INSERT the data if SET
ANSI_WARNINGS is ON, so I guess for some reason you have it OFF. This
is not recommended, because some queries (distributed queries, indexed
views) require it to be ON.
But this only applies to INSERT and UPDATE. Not when assigning to
variables or parameters, so if the truncation happens already there,
you won't be noticed.
If you were to use a UDDT, then you would have the issue that you
cannot modify a UDDT, you can only drop and recreate it. So to change
your definition, you would need to unbind it, drop it, recreate it and
bind it again. This may or may not be less effort than modifying your
stored procedure code.


But it has the distinct advantage of that you know where the problems are.
The actual change will take longer time, but once you are completed, you
can feel confident that your SQL code is fine.

By the way, the typical procedure to make a UDDT longer would be to first
rename the old type, create the new definition and the change the tables.

In the database I work with, almost all character columns defined through
UDDTs. There are a few exceptions, usually because there are some odd
special case in some odd table.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

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

Similar topics

4
2943
by: Jari Kujansuu | last post by:
I can successfully parse XML document using SAX or DOM and I can also validate XML document against schema. Problem is that my program should deal with user-defined schemas which means that when I parse some element from XML document I don't know until runtime the type of the element (it depends on the type used in user-defined schema). XML parser obviously validates that the value of the element is correct type but still I receive that...
3
24039
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked tables in the database where the code resides. If we move the database with the data tables to a new directory, the links are no longer valid. I tried to update the links by changing the Connect property and refreshing: Set td = db.TableDefs(0)...
17
4234
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset Set rs = Me.RecordsetClone rs.Find "=" & lngContractID If Not rs.EOF Then Me.Bookmark = rs.Bookmark I must site the Heisenberb Uncertainty Principal here, as it
11
6607
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am not logged into the server, Access is not able to print to the printer. The error is pretty...
1
4013
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the live databases on the network. Is there a way, via code, when I get back in-house from being on the road to click a button, and select the backends I want to link to? I would want to delete all the current links and link to the "live"
30
6103
by: junky_fellow | last post by:
I was looking at the source code of linux or open BSD. What I found that lots of typedefs were used. For example, consider the offset in a file. It was declared as off_t offset; and off_t is typedefed as typedef long off_t; I wanted to know what advantage do we get by typedefs ? Why we did not declare
5
3410
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character text field. I want to know which Data type I need to use so that it doesnt waste memory. thanks in advance, rAinDeEr
23
14526
by: Bjorn | last post by:
Hi. Every time i post data in a form the contents are being checked for validity. When i click the back-button, all data is gone and i have to retype it. It's obvious that only a few or none of the visitors will retype it all so i'm asking: "how to preserve POST-data when clicking the back-button?" i've already tried to print post data as a value in a HTML tag but
14
2205
by: aaragon | last post by:
Hi everyone, I've been writing some code and so far I have all the code written in the .h files in order to avoid the linker errors. I'm using templates. I wanted to move the implementations to the .cpp files. After some reading, I found that the only way to do this is to add the actual template instantiations in the .cpp file. But, how do you do that if you're not working with built-in types? For example, a template class might be,
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10324
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.