Re: declare variable to be of some table's column datatype
From: Chris Hohmann (nospam_at_thankyou.com)
Date: 06/10/04
- Next message: James Travis: "RE: SQL Query Help"
- Previous message: Clinton Bast: "String or binary data would be truncated, but fields are big enough"
- In reply to: Kanan: "declare variable to be of some table's column datatype"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 10 Jun 2004 15:21:02 -0700
"Kanan" <anonymous@discussions.microsoft.com> wrote in message
news:0B24A507-82B9-4487-9782-9D45E12EE886@microsoft.com...
> Does SQL Server have the capability to declare a variable to be of
particular table's column datatype? This is a feature
> available in Oracle. Please let me know. I am not able to find any
documentation on this in my SQL Server book.
> thanks
> Kanan
You could create a user defined type and declare both the table column and
the variable to be of that type. Note, there are some issues to be aware of:
1. If you're going to use the UDT's with temp tables, then the UDT's will
need to be define in the model database, since that's what the tempdb is
"modeled" after.
2. Modifying a UDT is a multi-step process if it's bound to a table column.
A better approach may be to use the UDT for variables/stored procedures,
being sure to update the UDT whenever you change the base data type of the
column to which it refers.
3. I'm not sure what, if any, performance issues are associated with UDT's.
I've haven't observed an appreciable difference in performance but due
diligence demands that you confirm this for yourself.
HTH
-Chris Hohmann
- Next message: James Travis: "RE: SQL Query Help"
- Previous message: Clinton Bast: "String or binary data would be truncated, but fields are big enough"
- In reply to: Kanan: "declare variable to be of some table's column datatype"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|