たとえば、VARCHAR(50) フィールドを作成した場合、100 文字の値を割り当てようとするとどうなりますか?
SQL Server でこれを実行できますか? なんとなく効率が悪いのでしょうか。
たとえば、VARCHAR(50) フィールドを作成した場合、100 文字の値を割り当てようとするとどうなりますか?
SQL Server でこれを実行できますか? なんとなく効率が悪いのでしょうか。
大きな文字列をより小さなサイズの変数に強制しようとすると、入力文字列は適切なサイズで切り捨てられます。
declare @Variable varchar (50)
set @Variable = replace (SPACE (100), ' ' , '.')
print @Variable
出力の長さは 50 文字です
..................................................
大きな文字列をテーブル内の小さなサイズのフィールドに強制しようとすると、エラーが発生します
declare @MyTable Table
(
TestVariable varchar (50)
)
insert into @MyTable (TestVariable) select replace (SPACE (100), ' ' , '.')
select * from @MyTable
出力は
Msg 8152, Level 16, State 14, Line 6
String or binary data would be truncated.
The statement has been terminated.
TestVariable
------------------------------------------------
It will throw an error saying that the value would be truncated. It won't write more than the 50 characters you've specified, otherwise you wouldn't be able to prevent the row size from growing out of control
SQL Server でこれを実行できますか? なんとなく効率が悪いのでしょうか。
文字列またはバイナリデータが切り捨てられることを示すエラーが発生します。