Question

In: Computer Science

Create a stored procedure that can be used to add a student to the school and...

Create a stored procedure that can be used to add a student to the school and a section of a course. 1. If the student already exists, then just add him to the section (do not update information like address). 2. The procedure will require the following arguments (see table definition for types): A. Salutation B. First Name C. Last Name D. Street Address (including City) E. ZIP Code F. Phone Number G. Employer Name (if any) H. Course Number I. Section Number 3. The program should error if any constraints are violated (no last name, bad zip, bad course, bad section) 4. It should rollback changes if these or any other errors occur. 5. The dates in the STUDENT and ENROLLMENT tables should be set to the day the procedure is run. 6. Don't forget that each table has 4 extra required fields ( CREATED_BY, CREATED_DATE, MODIFIED_BY, and MODIFIED_DATE). The current user should be in both 'BY's and the day the procedure is run in both 'DATE's. 7. To test the procedure insert yourself into course 120, section 5. 8. If the insert fails (usually due to the ZIP code not being in the ZIPCODE table, then find a legal ZIP code in that table and use it instead of your own or insert you own ZIP into the table and rerun the procedure. 9. The following SQL can be used to verify that you have successfully placed yourself in the course: SELECT S.LAST_NAME [Last Name], s.FIRST_NAME [First Name], e.ENROLL_DATE [Enrolled On] FROM ENROLLMENT e INNER JOIN SECTION c ON c.SECTION_ID = e.SECTION_ID INNER JOIN STUDENT s ON s.STUDENT_ID = e.STUDENT_ID WHERE c.COURSE_NO =120 AND c.SECTION_NO = 5 structure of

[STUDENT]

STUDENT_ID(PK)                INT                        NOT NULL

SALUTATION                       VARCHAR(5)         NULL

FIRST_NAME                      VARCHAR(25)       NULL

LAST_NAME                        VARCHAR(25)       NOT NULL

STREET_ADDRESS              VARCHAR(50)       NULL

ZIP(FK)                                VARCHAR(5)         NOT NULL

PHONE                                VARCHAR(15)       NULL

EMPLOYER                          VARCHAR(60)       NULL

REGISTRATION_DATE            DATE       NOT NULL

[SECTION]

SECTION_ID(PK)                        INT                        NOT NULL

COURSE_NO(FK)                      INT                        NOT NULL

SECTION_NO                            TINYINT                 NOT NULL

START_DATE_TIME                  DATE                     NOT NULL

LOCATION                                 VARCHAR(30)       NULL

INSTRUCTOR_ID(FK)                INT                        NOT NULL

CAPACITY                                  TINYINT                 NULL

[ENROLLMENT]

STUDENT_ID(PK)(FK)                INT                        NOT NULL

SECTION_ID(PK)(FK)                 INT                        NOT NULL

ENROLL_DATE                          DATE                     NOT NULL

FINAL_GRADE                           TINYINT                 NULL

[ZIPCODE]

ZIP(PK)                                      CHAR(5)                NOT NULL

CITY                                           VARCHAR(25)       NULL

STATE                                        VARCHAR(2)         NULL

[COURSE]

COURSE_NO(PK)    INT                    NOT NULL

DESCRIPTION          VARCHAR(50)   NOT NULL

COST                       MONEY             NULL

PRERQUISITE(FK)   INT                    NULL

Solutions

Expert Solution

// the below statements are used for creating a simple insert stored procedure. You can run it through an explicit call from a host language program. .... similarly create other tables....

DROP PROCEDURE IF EXISTS `students`
GO

CREATE PROCEDURE students
     (
        IN p_student_id                    INT(11)       ,
        IN p_salutation                    VARCHAR(5)   ,
        IN p_lastname                      VARCHAR(25)   ,
        IN p_firstname                     VARCHAR(25)   ,
        IN p_streetaddress                 VARCHAR(50)    ,
        IN p_zip                           VARCHAR(5)    ,
        IN p_phone                         VARCHAR(15)   ,
   IN p_employer                      VARCHAR(60)   ,
   IN p_registrationdate            DATE    ,
   IN_createdby                VARCHAR(25) ,
   IN_createddate                DATE ,
   IN_modifyby                VARCHAR(25) ,
   IN_modifydate                DATE
     )
BEGIN

    INSERT INTO students
         (
           student_id ,
           salutation ,
           lastname    ,
           firstname   ,
           streetaddress ,
           zip         ,
           phone ,    
       employer ,
       registrationdate ,
       createdby ,
       createddate ,
       modifyby ,
       modifydate                
         )
    VALUES
         (
           p_student_id ,
           p_salutation ,
           p_lastname    ,
           p_firstname   ,
           p_streetaddress ,
           p_zip         ,
           p_phone ,    
       p_employer ,
       p_registrationdate                
       p_createdby ,
       p_createddate ,
       p_modifyby ,
       p_modifydate                
     ) ;
END

GO

// the below statements are used to create the table ..using mysql command.. similarly create other tables....

CREATE TABLE IF NOT EXISTS student
     (
         STUDENT_ID                INT               NOT NULL
   SALUTATION                 VARCHAR(5)        NULL
   FIRST_NAME                 VARCHAR(25)       NULL
   LAST_NAME                  VARCHAR(25)       NOT NULL
   STREET_ADDRESS             VARCHAR(50)       NULL
   ZIP(FK)                    VARCHAR(5)        NOT NULL
   PHONE                      VARCHAR(15)       NULL
   EMPLOYER                   VARCHAR(60)       NULL
   REGISTRATION_DATE           DATE             NOT NULL
       PRIMARY KEY (STUDENT_ID)
     ) ENGINE = MYISAM

GO

//query to check if student data exists if so add to section

CREATE DEFINER=`root`@`127.0.0.1`
PROCEDURE `GetUserName`(student STUDENT_ID INT,SECTION SECTION_ID INT)
BEGIN
DECLARE SECTION_ID INT;
SELECT STUDENT_ID SECTION SECTION_ID
FROM STUDENT,SECTION
WHERE STUDENT_ID = STUDENT_ID;
IF STUDENT_ID EXISTS
THEN
INSERT INTO SECTION (SECTION_ID, COURSE_NO, SECTION_NO, START_DATE_TIME, LOCATION, INSTRUCTOR_ID, CAPACITY);
END IF;
END

//query to select the required data

mysql> CREATE PROCEDURE my_proc_OUT (OUT highest_salary INT)
-> BEGIN
-> SELECT S.LAST_NAME [Last Name], s.FIRST_NAME [First Name], e.ENROLL_DATE [Enrolled On] FROM ENROLLMENT e INNER JOIN SECTION c ON c.SECTION_ID = e.SECTION_ID INNER JOIN STUDENT s ON s.STUDENT_ID = e.STUDENT_ID WHERE c.COURSE_NO =120 AND c.SECTION_NO = 5
-> END$$


Related Solutions

Step 2: Create Stored Procedures to Add/Update/Delete an entity table Create a script to create a...
Step 2: Create Stored Procedures to Add/Update/Delete an entity table Create a script to create a table named ProjectBilling which will have the following columns: • projectBillID char(6) : A 6 character unique identifier (numbers and letters) • TransAmount decimal(16,9) : The amount of the transaction • TransDesc varchar(255): A description of the transaction • TransDate datetime: The date of the transaction • projectID char(4):The Id of the project • accountMgr char(8):The employee who manages the bill ledger Include this...
Create a simple procedure (120–150 words) that can be used to reconcile credit card transactions.
Create a simple procedure (120–150 words) that can be used to reconcile credit card transactions.
Sharpe Middle School is applying for a grant that will be used to add fitness equipment...
Sharpe Middle School is applying for a grant that will be used to add fitness equipment to the gym. The principal surveyed 16 anonymous students to determine how many minutes a day the students spend exercising. The results from the 16 anonymous students are shown. 0 minutes; 40 minutes; 60 minutes; 30 minutes; 60 minutes; 10 minutes; 45 minutes; 30 minutes; 300 minutes; 90 minutes; 30 minutes; 120 minutes; 60 minutes; 60 minutes; 0 minutes; 20 minutes ** Lp =...
---In the code, create add and delete a student by ID number when prompted /////////////////////////////////////////////////////////////// import...
---In the code, create add and delete a student by ID number when prompted /////////////////////////////////////////////////////////////// import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String [] students = new String[1];     private int numberOfStudents;     public COurseCom66(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public...
Write a script that creates and calls a stored procedure named test. This procedure should identify...
Write a script that creates and calls a stored procedure named test. This procedure should identify all of the prime numbers less than 100. (A prime number is an integer that can't be divided by another integer other than 1 and itself.) Then, it should display a string variable that includes the prime numbers like this: 2 1 3 1 5 1 7 1 1 1 1 1 3 1 1 7 1 1 9 1 2 3 1 2...
SQL Code: Write a script that creates and calls a stored procedure named test. This procedure...
SQL Code: Write a script that creates and calls a stored procedure named test. This procedure should identify all of the prime numbers less than 100. (A prime number is an integer that can't be divided by another integer other than 1 and itself.) Then, it should display a string variable that includes the prime numbers like this: 2 1 3 1 5 1 7 1 1 1 1 1 3 1 1 7 1 1 9 1 2 3...
Create Procedure in (PL/SQL) called Make_Account (v_first, v_last, v_email, v_errormsg) Add a new user to the...
Create Procedure in (PL/SQL) called Make_Account (v_first, v_last, v_email, v_errormsg) Add a new user to the Account table. If the new user cannot be added, return a error message. Table Account (this is the table I need to add data using PROCEDURE) Account_no (PK) Email (VARCHAR2) first (VARCHAR2) last (VARCHAR2)
Describe a procedure that can be used to restrict or digest the TOL plasmid
Describe a procedure that can be used to restrict or digest the TOL plasmid
What is the diagnostic procedure for glucose tolerance? ACTIVE LEARNING TEMPLATE:Diagnostic Procedure STUDENT NAME _____________________________________ PROCEDURE...
What is the diagnostic procedure for glucose tolerance? ACTIVE LEARNING TEMPLATE:Diagnostic Procedure STUDENT NAME _____________________________________ PROCEDURE NAME ____________________________________________________________________ REVIEW MODULE CHAPTER ___________ Description of Procedure Indications Interpretation of Findings. CONSIDERATIONS Nursing Interventions (pre, intra, post) Potential Complications. Client Education Nursing Interventions. ACTIVE LEARNING TEMPLATES                                                                                                                                                                 TherapeuTic procedure A3
1. How do indexes improve SQL query performance? 2. How can stored procedure design improve query...
1. How do indexes improve SQL query performance? 2. How can stored procedure design improve query times in a data mart? 3. Why/How does de-normalization of a data mart design improve performance of queries? 4. What is a different between Client-Servervs. Distributed Architecture? 5. What are some primary features of a 3-tier architecture design?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT