New to SQL Server, so I would ask the experts.
I see a lot of tables with fields defined as nvarchar(MAX) (up to 2GB of data?) or datetime2(7) (all the way to a millisecond), etc. I like to use a ‘lean-mean’ approach to defining data types in my tables, so if my data will not (should not) exceed 7 characters, I would define my field to varchar(7), if I just need a date (no time portion), I would use DATE data type. Validate my data at the entry point in my application to ensure the limits.
Is this the right approach?
Or, should I follow the ‘other’ way and use (max) fields to be able to handle whatever is thrown my way and deal with it? The way others do.
Aside from performance issues, I also face some problems with data migrations when I grab the data from other places and try to validate it before I fit it into my structure. Checking for the length: I have 7 characters limit, who knows how long the data will be from other source? Should be up to 7, but since they do allow (max) I have to check it, and that takes time, resources, and performance hits when I have to deal with a lot of fields.
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
I see a lot of tables with fields defined as nvarchar(MAX) (up to 2GB of data?) or datetime2(7) (all the way to a millisecond), etc. I like to use a ‘lean-mean’ approach to defining data types in my tables, so if my data will not (should not) exceed 7 characters, I would define my field to varchar(7), if I just need a date (no time portion), I would use DATE data type. Validate my data at the entry point in my application to ensure the limits.
Is this the right approach?
Or, should I follow the ‘other’ way and use (max) fields to be able to handle whatever is thrown my way and deal with it? The way others do.
Aside from performance issues, I also face some problems with data migrations when I grab the data from other places and try to validate it before I fit it into my structure. Checking for the length: I have 7 characters limit, who knows how long the data will be from other source? Should be up to 7, but since they do allow (max) I have to check it, and that takes time, resources, and performance hits when I have to deal with a lot of fields.
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson