如何用一条sql语句删除表中所相同的记录 20
1个回答
展开全部
建议你写个存储过程,我写的一个,让你参考一下!CardNo是自定义的数据类型!用触发器容易出错
CREATE PROCEDURE DelFixUser
@CardNo CardNo
AS
Declare @CarNo CarNo
select @CarNo=车辆号码 from FixCardIndexTable
where 卡号=@CardNo
Delete from AllCardIndexTable
where 卡号=@CardNo
Delete from FixCardIndexTable
where 卡号=@CardNo
Delete from FixCardEndDateTable
where 卡号=@CardNo
Delete from CardPassWordTable
where 卡号=@CardNo
Delete from UserCarInfoTable
where 车辆牌号=@CarNo
说明:删除一个固定用户记录,同时从AllCardIndexTable、FixCardIndexTable、FixCardEndDateTable、CardPassWordTable和UserCarInfoTable表中删除相应的记录。
CREATE PROCEDURE DelFixUser
@CardNo CardNo
AS
Declare @CarNo CarNo
select @CarNo=车辆号码 from FixCardIndexTable
where 卡号=@CardNo
Delete from AllCardIndexTable
where 卡号=@CardNo
Delete from FixCardIndexTable
where 卡号=@CardNo
Delete from FixCardEndDateTable
where 卡号=@CardNo
Delete from CardPassWordTable
where 卡号=@CardNo
Delete from UserCarInfoTable
where 车辆牌号=@CarNo
说明:删除一个固定用户记录,同时从AllCardIndexTable、FixCardIndexTable、FixCardEndDateTable、CardPassWordTable和UserCarInfoTable表中删除相应的记录。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询