sql - How are you supposed to choose K when creating a VARCHAR(K) column? Or are you? -


this i've never understood. let's want column storing email address. think,

"ok, email addresses no more 15 characters, i'll 50 max characters play safe."

and making column varchar(50). of course, means have create code, possibly both client- , server-side validation of entries column.

that brings question of why not use nvarchar time except in rare circumstances logic of application dicates fixed or maximum length. understand, if create varchar(50) , none of entries more 25 characters, not mean 50% of space wasted, database knows how optimize everything.

again, brings question of why not use nvarchar.

nvarchar has nothing "unlimited length of string" since unicode version of varchar. @ present time there no reasons use varchar (except backward compatibility issues) , nvarchar should preferred.

so i'm supposing you're asking why don't use nvarchar(max) everywhere unlimited (2 gbyte of storage) instead of specifying nvarchar(n) concrete columns.

there many reasons of using nvarchar(n) instead of nvarchar(max).

for example, if column should included in index - can't nvarchar(max).

also nvarchar(max) data internally stored differently nvarchar(n) , somtimes can affect performance.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -