如何设计dt和dd,以便它们在同一行?(How to style dt and dd so they are on the same line?)
使用CSS,如何设置以下内容:
<dl> <dt>Mercury</dt> <dd>Mercury (0.4 AU from the Sun) is the closest planet to the Sun and the smallest planet.</dd> <dt>Venus</dt> <dd>Venus (0.7 AU) is close in size to Earth, (0.815 Earth masses) and like Earth, has a thick silicate mantle around an iron core.</dd> <dt>Earth</dt> <dd>Earth (1 AU) is the largest and densest of the inner planets, the only one known to have current geological activity.</dd> </dl>
所以
dt
的内容显示在一列,dd
的内容在另一列中,每个dt
和相应的dd
在同一行? 也就是生产一些看起来像:Using CSS, how can I style the following:
<dl> <dt>Mercury</dt> <dd>Mercury (0.4 AU from the Sun) is the closest planet to the Sun and the smallest planet.</dd> <dt>Venus</dt> <dd>Venus (0.7 AU) is close in size to Earth, (0.815 Earth masses) and like Earth, has a thick silicate mantle around an iron core.</dd> <dt>Earth</dt> <dd>Earth (1 AU) is the largest and densest of the inner planets, the only one known to have current geological activity.</dd> </dl>
so the content of the
dt
show in one column and the content of thedd
in another column, with eachdt
and the correspondingdd
on the same line? I.e. producing something that looks like:
原文:https://stackoverflow.com/questions/1713048
最满意答案
这是我们的模板(删除错误记录)
这是设计来处理
- Paul Randal的文章“没有像SQL Server中的嵌套事务那样的事情”
- 错误266
- 触发器回滚
说明:
所有TXN开始和提交/回滚必须配对,以便
@@TRANCOUNT
在进入和退出时是相同的
@@TRANCOUNT
错配导致错误266因为
BEGIN TRAN
增量@@TRANCOUNT
COMMIT
递减@@TRANCOUNT
ROLLBACK
返回@@TRANCOUNT
为零您不能在当前范围内递减
@@TRANCOUNT
这就是你认为的“内部交易”
SET XACT_ABORT ON
抑制由不匹配的@@TRANCOUNT
引起的错误266
并且还处理dba.se上这样的“SQL Server事务超时”问题这允许客户端TXN(如LINQ)单个存储过程可能是分布式或XA事务的一部分,或者仅仅是在客户端代码中启动(例如.net TransactionScope)
用法:
- 每个存储的proc必须符合相同的模板
概要
- 所以不要创建比你需要的更多的TXN
代码
CREATE PROCEDURE [Name] AS SET XACT_ABORT, NOCOUNT ON DECLARE @starttrancount int BEGIN TRY SELECT @starttrancount = @@TRANCOUNT IF @starttrancount = 0 BEGIN TRANSACTION [...Perform work, call nested procedures...] IF @starttrancount = 0 COMMIT TRANSACTION END TRY BEGIN CATCH IF XACT_STATE() <> 0 AND @starttrancount = 0 ROLLBACK TRANSACTION; THROW; --before SQL Server 2012 use --RAISERROR [rethrow caught error using @ErrorNumber, @ErrorMessage, etc] END CATCH GO
笔记:
由于
SET XACT_ABORT ON
,回滚检查实际上是多余的。 然而,它让我感觉更好,看起来很奇怪,而且允许你不想要的情况Remus Rusanu有一个类似的shell ,它使用保存点。 我更喜欢原子数据库调用,不要像他们的文章一样使用部分更新
This is our template (error logging removed)
This is designed to handle
- Paul Randal's article "No such thing as a nested transaction in SQL Server"
- Error 266
- Trigger Rollbacks
Explanations:
all TXN begin and commit/rollbacks must be paired so that
@@TRANCOUNT
is the same on entry and exitmismatches of
@@TRANCOUNT
cause error 266 because
BEGIN TRAN
increments@@TRANCOUNT
COMMIT
decrements@@TRANCOUNT
ROLLBACK
returns@@TRANCOUNT
to zeroYou can not decrement
@@TRANCOUNT
for the current scope
This is what you'd think is the "inner transaction"
SET XACT_ABORT ON
suppresses error 266 caused by mismatched@@TRANCOUNT
And also deals with issues like this "SQL Server Transaction Timeout" on dba.seThis allows for client side TXNs (like LINQ) A single stored procedure may be part of distributed or XA transaction, or simply one initiated in client code (say .net TransactionScope)
Usage:
- Each stored proc must conform to the same template
Summary
- So don't create more TXNs than you need
The code
CREATE PROCEDURE [Name] AS SET XACT_ABORT, NOCOUNT ON DECLARE @starttrancount int BEGIN TRY SELECT @starttrancount = @@TRANCOUNT IF @starttrancount = 0 BEGIN TRANSACTION [...Perform work, call nested procedures...] IF @starttrancount = 0 COMMIT TRANSACTION END TRY BEGIN CATCH IF XACT_STATE() <> 0 AND @starttrancount = 0 ROLLBACK TRANSACTION; THROW; --before SQL Server 2012 use --RAISERROR [rethrow caught error using @ErrorNumber, @ErrorMessage, etc] END CATCH GO
Notes:
The rollback check is actually redundant because of
SET XACT_ABORT ON
. However, it makes me feel better, looks odd without, and allows for situations where you don't want it onRemus Rusanu has a similar shell that uses save points. I prefer an atomic DB call and don't use partial updates like their article
相关问答
更多-
嵌套存储过程包含TRY CATCH ROLLBACK模式?(Nested stored procedures containing TRY CATCH ROLLBACK pattern?)[2023-06-02]
这是我们的模板(删除错误记录) 这是设计来处理 Paul Randal的文章“没有像SQL Server中的嵌套事务那样的事情” 错误266 触发器回滚 说明: 所有TXN开始和提交/回滚必须配对,以便@@TRANCOUNT在进入和退出时是相同的 @@TRANCOUNT错配导致错误266因为 BEGIN TRAN增量@@TRANCOUNT COMMIT递减@@TRANCOUNT ROLLBACK返回@@TRANCOUNT为零 您不能在当前范围内递减@@TRANCOUNT 这就是你认为的“内部交易” SET ... -
尽可能不要在控制流或异常情况下使用异常。 但是要直接回答你的问题(假设所有异常类型都是一样的): Func
[] calcs = { calc1, calc2, calc3 }; foreach(var calc in calcs) { try { return calc(); } catch (CalcException){ } } throw new NoCalcsWorkedException(); As far as possible, don't use exc ... -
存储过程中的错误处理(Error handling in stored procedures)[2022-04-19]
关闭这一点,因为我发现每个SP都必须有自己的错误处理,而外部SP调用多个SP不需要进行错误处理。 Closing this since I figured out that each SP had to have its own Error handling and the outside SP calling multiple SPs would not need to have error handling. -
TransactionScope和事务包含在嵌套存储过程中(TransactionScope and transactions included in nested stored procedures)[2022-04-22]
通过使用SqlTransaction而不是TransactionScope管理以使其工作,并将相同的连接和事务传递给用于执行两个存储过程的命令对象。 它的接缝TransactionScope不能在这种情况下使用。 感谢您的意见。 Managed to get it work by using SqlTransaction instead of TransactionScope and passing the same connection and transaction to the command obj ... -
根据我的说法,如果Stored Proc 1失败,所有内容都应该回滚,你不会在表2和表3中插入任何数据。 According to me if Stored Proc 1 fails everything should be rolled back and you wont have any data inserted in Table 2 & Table 3.
-
从前端的sql server存储过程返回的Catch错误消息(Catch error message returned from sql server stored procedure at front end)[2022-07-11]
您的存储过程包含一个基本缺陷: 如果在检查@@ERROR (或@@ROWCOUNT )的值后执行任何语句,它将重置为零。 在继续之前,应始终缓存在局部变量中: DECLARE @errornum int SET @errornum = @@ERROR 如果您还需要rowcount,那么您必须在单个语句中执行,如此 SELECT @errornum = @@ERROR, @rowcount = @@ROWCOUNT 此外,您不需要混合使用TRY/CATCH和检查@@ERROR 如果要处理存储过程中的错误, ... -
SQL中的try...catch工作方式略有不同,我过去所做的是在存储过程中使用OUTPUT变量: ALTER PROCEDURE dbo.yourStoredProcedure (-- your parameters @errNumber INT OUTPUT, @errLine INT OUTPUT, @errMessage VARCHAR(MAX) OUTPUT) AS BEGIN SET @errNumber = 0 SET @err ...
-
引用MS文档 TRY ... CATCH构造捕获严重性高于10但未关闭数据库连接的所有执行错误。 所以,try catch没有捕获所有可能的错误。 除了try catch之外,你还可以使用xact_abort。 try / catch为您提供了更大的灵活性,即,当您不满意时,您不仅限于回滚。 Quoting from MS docs A TRY…CATCH construct catches all execution errors that have a severity higher than 10 t ...
-
RAISERROR无法使用ROLLBACK TRANSACTION在CATCH内工作(RAISERROR Dosn't Work Inside CATCH With ROLLBACK TRANSACTION)[2022-11-27]
将IF(XACT_STATE())= -1更改为IF(XACT_STATE()) <> 0 ,您的问题将完成。 Change IF(XACT_STATE())= -1 to IF(XACT_STATE()) <> 0 and your problem will be done. -
只有当EXECUTE关键字是批处理中的第一个语句时,它才是可选的。 它与参数无关,在所有其他上下文中都是必需的。 Microsoft从Sybase代码库以及其他许多松散的T-SQL解析规则继承了这种奇怪的行为。 我建议你遵循严格的T-SQL编码风格来避免陷阱。 下面的代码运行没有错误,因为它根本没有执行proc。 由于没有分号语句终止符,因此存储过程名称将成为BEGIN TRAN语句的一部分,并被解释为事务名称。 begin tran failsInTransactions commit 如果添加语句 ...