字段长度解决办法

字段长度
刚才发了给贴子,都说设的长一点就行了。
结果不是这样的。我设的倒是长了。结果提示我:而此值超出了允许的 8060 字节的最大表行大小
         title nchar(50) NULL,
time nchar(50) NULL,
range nchar(50) NULL,
conent nchar(300) NULL,
explain1 nchar(800) NULL,
explain2 nchar(800) NULL,
explain3 nchar(800) NULL,
explain4 nchar(800) NULL,
explain5 nchar(800) NULL,
explain6 nchar(800) NULL
这样字段值太长不允许
怎么解决,哎我都要没分啦,噗

------解决方案--------------------
char是定长。
 title nvarchar(50) NULL,
time nvarchar(50) NULL,
range nvarchar(50) NULL,
conent nvarchar(300) NULL,
explain1 nvarchar(800) NULL,
explain2 nvarchar(800) NULL,
explain3 nvarchar(800) NULL,
explain4 nvarchar(800) NULL,
explain5 nvarchar(800) NULL,
explain6 nvarchar(800) NULL
------解决方案--------------------
title varchar(50) NULL,
 time varchar(50) NULL,
 range varchar(50) NULL,
 conent varchar(300) NULL,
 explain1 varchar(800) NULL,
 explain2 varchar(800) NULL,
 explain3 varchar(800) NULL,
 explain4 varchar(800) NULL,
 explain5 varchar(800) NULL,
 explain6 varchar(800) NULL 

------解决方案--------------------
nchar类型为固定长度,nvarchar类型可变长度。
如:
nchar(100) 即使你只存储'abc'三个字符,后面会自动填充空格够100位
nvarhcar(100) 存储'abc'三个字符,后面不会自动加字符

检验方法:
select len(nchar字段),len(nvarchar字段)
------解决方案--------------------

-- 尝试建表
create table tt
(title nchar(50) NULL,
 time nchar(50) NULL,
 range nchar(50) NULL,
 conent nchar(300) NULL,
 explain1 nchar(800) NULL,
 explain2 nchar(800) NULL,
 explain3 nchar(800) NULL,
 explain4 nchar(800) NULL,
 explain5 nchar(800) NULL,
 explain6 nchar(800) null)

-- 错误信息
/*
Msg 1701, Level 16, State 1, Line 1
Creating or altering table 'tt' failed because the minimum row size would be 10508, 
including 8 bytes of internal overhead. 
This exceeds the maximum allowable table row size of 8060 bytes.
*/


-- 计算行长度
select 50*2*3+300*2+800*2*6+8 'row_length'

/*
row_length
-----------
10508

(1 row(s) affected)
*/

--> 10508大于8060,所以不允许.

------解决方案--------------------
4楼高手啊!
------解决方案--------------------
A table can contain a maximum of 8,060 bytes per row. In SQL Server 2008, this restriction is relaxed for tables that contain varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns. The length of each one of these columns must still fall within the limit of 8,000 bytes; however, their combined widths can exceed the 8,060-byte limit. This applies to varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns when they are created and modified, and also to when data is updated or inserted. 

http://technet.microsoft.com/en-us/library/ms186981(v=sql.105).aspx
------解决方案--------------------
引用:
A table can contain a maximum of 8,060 bytes per row. In SQL Server 2008, this restriction is relaxed for tables that contain varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns. The length of each one of these columns must still fall within the limit of 8,000 bytes; however, their combined widths can exceed the 8,060-byte limit. This applies to varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns when they are created and modified, and also to when data is updated or inserted. 

http://technet.microsoft.com/en-us/library/ms186981(v=sql.105).aspx


这个解释很权威字段长度解决办法