sql server - Replace varchar length with a constant macro -
normally define varchar in sql server this.
in store procedure, input varaible @name declared
@name varchar(32); however, "32" hard coded. other developer use 24, 64 or else in other store procedure.
it hard maintain.
is there way write this?
@name varchar(var_name_length); var_name_length defined somewhere globally, c
#define var_name_length 32 then developer stick use macro instead of hard code 32.
not sure if possible in sql server.
or other idea?
note: sql server version 2008 sp2.
it possible using user-defined data types. but, in practice not useful, because can't change definition of custom type.
see article bad habits kick : using alias types aaron bertrand more details.
in comments article alexander kuznetsov said:
actually badly need ability define type once , use many times. accomplish that, use macros , run standard c++ preprocessor against sql code expand them.
for example, convert in include file used define
#define max_varchar varchar(8000)in code, can write on system:
[comments] max_varchar,which expand to
[comments] varchar(8000),converting 2005, replaced macro with:
#define max_varchar varchar(max)and let sql compare take care of details.
so, if have database objects scripted (which have in case), becomes matter of running step of preprocessor before running final t-sql scripts create database.
Comments
Post a Comment