Can I use varchar parameters in my stored procedure without declaring its length? For example I would like to declare my stored procedure as follows:
CREATE PROCEDURE [TEST]
@Domain varchar,
@Numbers int
AS
.....
It’s much easier for me if the stored procedure can automatically detect the parameter length, in this case if I changed the column length in my table I will not need to go and update all my stored procedures that uses this column.
Thank you,
If you omit the length, it defaults to one character.
For example:
varcharis a synonym forvarchar(1).One way to define the length in one place is a type, like:
You can then use this new type in other definitions:
However, you can’t change the definition of a type without dropping everything that uses it.
In my experience, data length changes are rare, and when they happen, they’re easy to refactor manually. So I’d stick to
varchar(x)instead of atype.