Question

In: Computer Science

Create a database with two tables as follows:- Students - StudentID, Name, Program FeePayment - StudentID,...

Create a database with two tables as follows:- Students - StudentID, Name, Program FeePayment - StudentID, Date, Description, Amount 1. Create a stored procedure that receives all the details of a student including fees and proceeds to insert insert the student details into the student details and the fee payment into the FeePayment table. All the operations should be done within a single transaction in a stored procedure. Note that the stored procedure works like a function that receives parameters. Copy and submit your code for creating the tables as well as your stored procedure code in a word document.

Solutions

Expert Solution

The below statement will create the Student Table.

CREATE TABLE [dbo].[Students](
        [StudentID] [int] NOT NULL,
        [Name] [varchar](50) NOT NULL,
        [Program] [varchar](50) NOT NULL
)

The below statement will create the FeePayment Table

CREATE TABLE [dbo].[FeePayment](
        [StudentID] [int] NOT NULL,
        [Date] [datetime] NOT NULL,
        [Description] [varchar](100) NOT NULL,
        [Amount] [float] NOT NULL
)

The below statement will create the Stored Procedure to insert the details into the respective tables. The comments are provided to understand the logic of the stored procedure.

create procedure [dbo].[AddStudentDetails]
        @StudentID int, 
        @Name varchar(50), 
        @Program varchar(50),
        @Date datetime,
        @Description varchar(100),
        @FeesAmount float
as
begin
        begin transaction
                -- Check if the StudentID and the Program combination exists in the table.
                -- If it exists do not insert it again. Otherwise proceed in inserting.
                if exists(select 1 from Students where StudentID = @StudentID and Program = @Program)
                begin
                        print 'The Student ID and the Program combination already exists in the Students table.  Hence not inserting '
                end
                else
                begin
                        -- Insert the details into the Student table
                        insert into Students (StudentID, Name, Program) values (@StudentID, @Name, @Program)
                end

                -- Insert the Fees details into the FeePayment table
                insert into FeePayment (StudentID, [Date], [Description], Amount) values (@StudentID, @Date, @Description, @FeesAmount)

        -- Finally commit the transaction
        commit
end
GO


The stored procedure can be executed as follows. The sample data and other screenshots are attached.

exec AddStudentDetails 1, 'Rob Martin', 'Computer Science', '2020-10-01', 'Sem 1 Fees', 120
exec AddStudentDetails 2, 'McCarthy', 'Software Engineering', '2020-10-02', 'Sem 1 Fees', 150


Related Solutions

Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient,...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient, fullName, biologicalMother, birthdate, address) doctor(idDr, fullName, specialization, consulRates) inpatient(idPatient, entryTime, outTime, idDr, idRoom). Please make entryTime as column that is going to be filled automatically when care record is being add room(idRoom, roomName, cost) fill the data above to each table Create sql query and relational algebra expressions for the query Please give me detailed answer so I could learn from it. Thank you...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based on your entities defining The attributes within each table The primary and foreign keys within each table *****Show your database tables, tables attributes, primary and foreign keys***** Do not forget to check the lesson slides and videos that show you how to convert an ER/EER into a database schema, and how to create a database and tables using MS SQL Server.
Write create table statements to create tables for the Exoproduct employees computers database depicted by the...
Write create table statements to create tables for the Exoproduct employees computers database depicted by the relational schema created in a mini case MC5 in chapter 3. Use insert into statements to insert no fewer than 2 and no more than 10 records per table.
Create a Database from blank (scratch) for a manager and name it. Create and design a...
Create a Database from blank (scratch) for a manager and name it. Create and design a table and name it. For each fields click and choose proper a data type such as short text and name the field. Make at least three fields. Enter your records. Make sure to add your name as a record. Similarly create two more tables. By design tool, make a relationship between each of two tables at a time and drag a primary key one...
Create tables according to the mapping. Add 2 records to each. Create 5 queries for database...
Create tables according to the mapping. Add 2 records to each. Create 5 queries for database of 3 table joins to use most of the tables or group of tables in database. You should not have tables that are of no use. Student(ssn, name, major) Class(classID, name, f_ssn) Faculty(ssn, name, office_num, dept_id) Department(Dept_id, office_num, f_ssn) Enroll(s_ssn, classID, grade) Professor(f_ssn, alma-mater, tenured) Instructor(f_ssn, term_degree, type) Lecture(classID, method) Lab(classID, location) Person(ssn, dob, gender)
1.Create a Database in Access with the information The database must include: Database name: Monaco Enterprise  Mark...
1.Create a Database in Access with the information The database must include: Database name: Monaco Enterprise  Mark Johnson #87451 Table name: Contacts Delete the Primary key. Fields name and data type are (remember to choose the data type): Field Name Data Types Employee Name Short text Name Short text Last Name Short Text Work Yes/No 2.Go to the “Datasheet View” and enter the data. * Remember to save the table. 3.Move the last name field after the employee name. 4.The (data)...
There are four tables in the database. 1. students (sno, sname, sgender, sbirthday, class) - sno:...
There are four tables in the database. 1. students (sno, sname, sgender, sbirthday, class) - sno: student number - sname: student name - sgender: male or female - sbirthday: date of birth - class: class number - primary key: sno 2. courses (cno, cname, tno) - cno: course number - cname: course name - tno: teacher number - primary key, cno, tno 3. scores (sno, cno, grade) - sno: student number - cno: course number - grade: grade - primary...
Please create the following tables for a tool rental database with appropriate primary keys & foreign...
Please create the following tables for a tool rental database with appropriate primary keys & foreign keys. Assumptions: 1. Each tool belongs to a category. 2. Each category may have a parent category but the parent category should not have a parent category (so at most two levels). E.g., a Tool A belongs to the electric mower, and electric mowers belong to mowers. Mower has no parent category. 3. Each tool can be rented at different time units. The typical...
Flag Create a database for PAINTER and PAINTING entities/tables; Decide on your own what will be...
Flag Create a database for PAINTER and PAINTING entities/tables; Decide on your own what will be the attributes of PAINTER and PAINTING tables; Insert at least 5 records on each table Deliverables: Screenshot of PAINTER and PAINTING table structures using the describe command Screenshot of PAINTER and PAINTING table records/entries using select command.
Database Design Design a database and show the relationship between each tables. I need multiple tables....
Database Design Design a database and show the relationship between each tables. I need multiple tables. *Must meet the requirements for Third Normal Form. These are the information for employee DB. Employee Number, First Name, Last Name, Date of birth, Address, city, state, zip, department, job title, supervisor, health insurance number, health insurance provider, dental insurance number, dental insurance provider, spouse/partner, children, children's ages.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT