如何模拟SQL插入语句?

时间:2014-04-30 20:26:59

标签: sql sql-server nhibernate

我正在使用一个使用NHibernate的Web应用程序。有时当NHibernate生成的SQL出现错误时,我得到的错误非常无益:

NHibernate.Exceptions.GenericADOException: could not execute batch command.[SQL: SQL not available] ---> System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.

抛出错误的代码生成了数十个SQL语句,这些语句存储在日志中,例如:

INSERT 
INTO
    ShipOrder (ShipContactName, ShipAddress1, ShipAddress2, ShipAddress3, ShipCity, ShipStateCode, ShipPostalCode, ShipCountryCode, ShipProvider) 
VALUES
    ('Tobias Funke', '12345 Anywhere Pl', NULL, NULL, 'Anytown', 'AA', '12345', 'US', 'UPS GROUND')

我想尝试运行此查询以查看它是否是错误的原因。有没有办法在SQL Server Management Studio中模拟插入,所以我不创建虚拟数据?

1 个答案:

答案 0 :(得分:9)

transactionrollback代替commit包裹它:

BEGIN TRANSACTION
INSERT 
INTO
    ShipOrder (ShipContactName, ShipAddress1, ShipAddress2, ShipAddress3, ShipCity, ShipStateCode, ShipPostalCode, ShipCountryCode, ShipProvider) 
VALUES
    ('Tobias Funke', '12345 Anywhere Pl', NULL, NULL, 'Anytown', 'AA', '12345', 'US', 'UPS GROUND')
ROLLBACK TRANSACTION