I declare a war to any NVARCHAR(N) except NVARCHAR(4000), and from now on any column designed to hold variable-length text will be declared in my applications simply as TString.
Like that:
CREATE TYPE dbo.TString FROM NVARCHAR(4000);
CREATE TABLE dbo.Note
(
...
, Title TString NULL
, NoteText TString NOT NULL
I am not ready yet to get rid of NVARCHAR entirely and simply move to NVARCHAR(MAX), but I believe this day will also come.
I am not lazy. I believe I am smart.
You cannot set the maximum size for String variable in .Net, and you don't complain.
You use signed int as a type for an array Length property, and you are just happy.
Why would you be so mad to my proposal? Well, perhaps you are not.
So what is the point to restrict the maximum size of the text data?
Data integrity? Performance?
Let's say we have FirstName and LastName fields. Normally, you would make them something like NVARCHAR(50). So what is really going to happen if we make them NVARCHAR(4000) instead?
Until we don't put there anything larger than 50 characters, nothing. Simply nothing.
There will be no difference at all.
Ok, now what is going to happen if user does enter text longer than 50 characters?
Well, he will have more data in the database.
If that is what user wants - that is exactly what he is going to get. What exactly is the problem?
I tell you what. In most cases when user will try to enter something longer that 50 characters into the FirstName field, this will only mean one thing: there is probably a very good business reason to have it that long.
And I bet in this case all you are going to do is to go ahead and change that column length anyways.
There will be no difference at all. Again.
So what's the point?
I have never seen the problem that some text was that long that the user regretted it was so long and wished he never entered it so long in the first place.
But I have seen a lot of cases when field was so short that the user could not enter everything he wanted to put into that field.
And I have seen a lot of cases when the need to increase the column length caused the cascades of changes in the enterprise application. And stored procedures and UDF's with parameters which were not updated properly.
Talk to me about it.
Man, you are so great )))) I love your blog!
ReplyDelete