Re: declare variable to be of some table's column datatype

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Chris Hohmann (nospam_at_thankyou.com)
Date: 06/10/04


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



Relevant Pages

  • Re: declare variable to be of some tables column datatype
    ... "Kanan" wrote in message ... > Does SQL Server have the capability to declare a variable to be of ... particular table's column datatype? ... documentation on this in my SQL Server book. ...
    (microsoft.public.sqlserver.programming)
  • [NT] Microsoft SQL Server 2000 OpenDataSource Buffer Overflow
    ... Microsoft's database server SQL Server 2000 has a remotely exploitable ... Please see the "Fix Information" section for more details. ... attacker in an exploit of the overflow will run uninhibited. ... declare @saved_return_address nvarchar ...
    (Securiteam)
  • Re: Timing out????
    ... I didn't know the column name from tbDateDiff. ... Vyas, MVP ... and means something different to SQL Server. ... > DECLARE @IPResetCount BIGINT ...
    (microsoft.public.sqlserver.programming)
  • Re: Assertion: SQL Server 2000 cant issue a SOAP call
    ... > middle tier) and not in SQL Server. ... > the SOAP endpoint. ... > sp_OA* family of system stored procedures to invoke this COM component. ... > DECLARE @object INT ...
    (microsoft.public.sqlserver.programming)
  • Re: 17805 Starting up Java App server, with SQL Server 2000 Backend
    ... network issue although you would expect a network issue to be more random. ... declare @P1 int ... On another machine running SQL Server 2000 Standard on Win2K advanced, ...
    (microsoft.public.sqlserver.clients)