Example of a stored procedure with SQL Server attached

Source: Internet
Author: User

The code looks like this, and it's clear:

--To add a project large class stored procedure UsechaiqianD2Goif object_id('P_insertbigtype','P') is  not NULLDrop procedureP_insertbigtypeGoCreate procedureP_insertbigtype@Name nvarchar( -)--[Big class name] as begin    Insert  into     [major categories of projects]([Large class name])    Values(@name)End     

2, a bit difficult to drip, most of them do not use it

--add household and household information UsechaiqianD2IF object_id('P_insertfamilymember','P') is  not NULLDROP PROCEDUREP_insertfamilymemberGOCREATE PROCEDUREP_insertfamilymember@name NVARCHAR( -),--name    @sex CHAR(2),--Sex    @idNumber NVARCHAR( -),--ID Number    @workUnit NVARCHAR( -),--Work Unit    @workUnitAddress NVARCHAR( -),--Address of work unit    @accountAddress NVARCHAR( -),--Account Location    @accountNature CHAR(Ten),--hukou Nature    @residentialAddress NVARCHAR( -),--Residential Address    @mobileNumber CHAR( A),--Mobile phone number    @remarks NVARCHAR( $),--Notes    @titles NVARCHAR(Ten),--appellation    @nation NVARCHAR( the),--ethnic    @politicStatus NVARCHAR( -),--political landscape        @familyId INT = NULL,--Family Number    @accounts INT,--total number of accounts    @houseNature NVARCHAR(Ten),--Housing Properties    @phoneNumber NVARCHAR( A),--Phone number    @familyAddress NVARCHAR( -),--Home Address        @projectId INT,--Demolition Project Number    @priorityBusinessArea FLOAT,--The size of the business Room can be purchased    @priorityHousingArea FLOAT,--Affordable Housing Area        @typistId INT,--Entry Clerk position serial number    @flag INT = 0                     --flag Information, 0: Add family members, 1: Add household information and family information asBEGIN    SETXact_abort on;--This sentence must be added    BEGIN TRANSACTIONMytran--Add Home Information    IF @flag = 1    BEGIN        INSERT  intofamily (number of family members, total number of accounts, housing nature, telephone number, home address, job serial number _ Input)VALUES(0,@accounts,@houseNature,@phoneNumber,@familyAddress,@typistId)                --get a family number        SELECT @familyId = MAX(family number) fromFamilyWHEREJob Serial Number _ input Clerk= @typistId    END        IF @flag = 1    BEGIN         INSERT  intoHome Settlement (demolition item number, family number, can purchase the business room area, can purchase the housing area)VALUES(@projectId,@familyId,@priorityBusinessArea,@priorityHousingArea)    END        --Add a family member    INSERT  intofamily member (family number, name, gender, ID number, work unit, work address, account location, account nature, residence address, mobile number, remark, appellation, nationality, political appearance)VALUES(@familyId,@name,@sex,@idNumber,@workUnit,@workUnitAddress,@accountAddress,@accountNature,@residentialAddress,@mobileNumber,@remarks,@titles,@nation,@politicStatus)        --number of family population plus one    UPDATEFamilySETNumber of family population=Number of family population+ 1    WHEREFamily number= @familyId    COMMIT TRANSACTIONMytranEND 
View Code

Example of a stored procedure with SQL Server attached

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.