Home Database Mysql Tutorial 订单事务-存储过程

订单事务-存储过程

Jun 07, 2016 pm 04:00 PM
create proc affairs storage Order process

create proc Createorder @orderId nvarchar(50),--订单号 @userId int,--用户编号 @address nvarchar(255),--收货人地址 @totalMoney money output --总金额 as begin declare @error int set @error=0 begin transaction --计算总价 select @totalMoney=SUM

create proc Createorder
@orderId nvarchar(50),--订单号
@userId int,--用户编号
@address nvarchar(255),--收货人地址
@totalMoney money output --总金额
as
begin
declare @error int
set @error=0
begin transaction
--计算总价
select @totalMoney=SUM([count]*Unitprice)from Cart
inner join Books on Cart.BookId=Books.Id
where UserId=@userId
set @error=@@ERROR+@error
--向订单主表中插入数据
insert into Orders(OrderId,OrderDate,UserId,TotalPrice,PostAddress,[state])
values(@orderId,GETDATE(),@userId,@totalMoney,@address,0)
set @error=@@ERROR+@error
--向订单明细表中插入数据
insert into OrderBook(OrderID,BookID,Quantity,UnitPrice)
select @orderId,BookId,[Count],UnitPrice from Cart inner join Books on Cart.BookId=Books.Id
where Cart.UserId=@userId
set @error=@@ERROR+@error
--删除购物车表中的数据
delete from Cart where UserId=@userId
set @error=@@ERROR+@error
--判断错误,执行事务
if @error>0
begin
rollback transaction
end
else
begin
commit transaction
end
end
--rollback transaction
--commit transaction
--primary key(Id) identity(1,1)
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Mar 07, 2024 pm 10:43 PM

This website reported on March 7 that Dr. Zhou Yuefeng, President of Huawei's Data Storage Product Line, recently attended the MWC2024 conference and specifically demonstrated the new generation OceanStorArctic magnetoelectric storage solution designed for warm data (WarmData) and cold data (ColdData). Zhou Yuefeng, President of Huawei's data storage product line, released a series of innovative solutions. Image source: Huawei's official press release attached to this site is as follows: The cost of this solution is 20% lower than that of magnetic tape, and its power consumption is 90% lower than that of hard disks. According to foreign technology media blocksandfiles, a Huawei spokesperson also revealed information about the magnetoelectric storage solution: Huawei's magnetoelectronic disk (MED) is a major innovation in magnetic storage media. First generation ME

Vue3+TS+Vite development skills: how to encrypt and store data Vue3+TS+Vite development skills: how to encrypt and store data Sep 10, 2023 pm 04:51 PM

Vue3+TS+Vite development tips: How to encrypt and store data. With the rapid development of Internet technology, data security and privacy protection are becoming more and more important. In the Vue3+TS+Vite development environment, how to encrypt and store data is a problem that every developer needs to face. This article will introduce some common data encryption and storage techniques to help developers improve application security and user experience. 1. Data Encryption Front-end Data Encryption Front-end encryption is an important part of protecting data security. Commonly used

How to apply for a refund for a Meituan takeout order. Detailed guide to applying for a refund on an order. How to apply for a refund for a Meituan takeout order. Detailed guide to applying for a refund on an order. Mar 12, 2024 am 10:50 AM

I believe that many users like some of the above functions very much, right? It not only saves you more time and effort, but also can always meet your various needs for food. Sometimes we order When taking out food, we find that some orders were delivered incorrectly or that our food cannot be eaten. At these times, we will definitely need to find some refund methods, so we also hope to be able to help everyone here. We can help you better. If there is a problem with some of the takeaways we order in the future, we can definitely protect our rights and interests directly. If the merchant does not agree, we will directly transfer manual customer intervention, so let’s take a look at the details now. Way to go, you can’t miss the excitement, hurry up

How to refund Meituan's pending orders_Meituan's tutorial on refunding pending orders How to refund Meituan's pending orders_Meituan's tutorial on refunding pending orders Mar 27, 2024 pm 08:40 PM

1. First open the Meituan app and click on the order to be used to enter. 2. Then on the page to be used, click on the order that needs to be refunded. 3. Then you can see the merchant information and order information. At this time, you can see the option to apply for a refund. Click to apply for a refund. 4. Finally, select the reason for the refund. Generally, the payment will be processed quickly if you choose a reason that has no impact on the merchant.

Lock wait timeout exceeded; try restarting transaction - How to solve MySQL error: transaction wait timeout Lock wait timeout exceeded; try restarting transaction - How to solve MySQL error: transaction wait timeout Oct 05, 2023 am 08:46 AM

Lockwaittimeoutexceeded;tryrestartingtransaction - How to solve the MySQL error: transaction wait timeout. When using the MySQL database, you may sometimes encounter a common error: Lockwaittimeoutexceeded;tryrestartingtransaction. This error indicates that the transaction wait timeout. This error usually occurs when

Git installation process on Ubuntu Git installation process on Ubuntu Mar 20, 2024 pm 04:51 PM

Git is a fast, reliable, and adaptable distributed version control system. It is designed to support distributed, non-linear workflows, making it ideal for software development teams of all sizes. Each Git working directory is an independent repository with a complete history of all changes and the ability to track versions even without network access or a central server. GitHub is a Git repository hosted on the cloud that provides all the features of distributed revision control. GitHub is a Git repository hosted on the cloud. Unlike Git which is a CLI tool, GitHub has a web-based graphical user interface. It is used for version control, which involves collaborating with other developers and tracking changes to scripts and

MySQL transaction processing: the difference between automatic submission and manual submission MySQL transaction processing: the difference between automatic submission and manual submission Mar 16, 2024 am 11:33 AM

MySQL transaction processing: the difference between automatic submission and manual submission. In the MySQL database, a transaction is a set of SQL statements. Either all executions are successful or all executions fail, ensuring the consistency and integrity of the data. In MySQL, transactions can be divided into automatic submission and manual submission. The difference lies in the timing of transaction submission and the scope of control over the transaction. The following will introduce the difference between automatic submission and manual submission in detail, and give specific code examples to illustrate. 1. Automatically submit in MySQL, if it is not displayed

How to correctly use sessionStorage to protect sensitive data How to correctly use sessionStorage to protect sensitive data Jan 13, 2024 am 11:54 AM

How to correctly use sessionStorage to store sensitive information requires specific code examples. Whether in web development or mobile application development, we often need to store and process sensitive information, such as user login credentials, ID numbers, etc. In front-end development, using sessionStorage is a common storage solution. However, since sessionStorage is browser-based storage, some security issues need to be paid attention to to ensure that the stored sensitive information is not maliciously accessed and used.

See all articles