Skip to main content
 首页 » 编程设计

c#之插入记录并抛出异常

2024年02月24日18小虾米

<分区>

如果 cardescription 在具有特定 @idCar 的行中的表中,我想抛出异常

cardescription非PK,不允许任何设计改动

insert into carsdescription 
  (description)  
value  
  (@description,@idCar) 

例子:

IDCar  | Description 
--------------------- 
1      | nice        - this record was in table before. 
1      | nice        - should throw exception 
2      | nice        - it is allowed 

汽车描述表:

  • ID(主键、整数、自增)
  • idcar(FK, int)
  • 描述(可变字符)

汽车表:

  • Id(int, PK, autoincrement)
  • 姓名(nvarchar(255)