如图
想通过hallID(int)列+seatID(varcher)列 的形式来添加hallSeatID列
| 表头 | 表头 | 表头 |
| ------ | ------ | ------ |
| 1+A | 1 | A |
| 2+B | 2 | B |
| | int |varcher|
所以我就想是否能通过CHECK约束实现
然而并不能……
或者我表达的不对
如图
想通过hallID(int)列+seatID(varcher)列 的形式来添加hallSeatID列
| 表头 | 表头 | 表头 |
| ------ | ------ | ------ |
| 1+A | 1 | A |
| 2+B | 2 | B |
| | int |varcher|
所以我就想是否能通过CHECK约束实现
然而并不能……
或者我表达的不对
用触发器来做,有帮助麻烦点个采纳【本回答右上角】,谢谢~~
create trigger [dbo].[ThallSeatID] on [dbo].[seat]-----注意修改表名
for insert,update
as
begin
declare @hallID int,@seatID nvarchar(50)
select @hallID=hallId,@seatID=seatID from inserted
-----注意修改表名
update seat set hallSeatID=replace(str(@hallID),' ','')+'-'+@seatID where seatID=@seatID and hallID=@hallID
end