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...
Use MYSQL to create the set of database tables of the relational database model and complete...
Use MYSQL to create the set of database tables of the relational database model and complete the associated queries given. Procedure: 1) Write all the SQL statements, necessary to create all tables and relationships, with Primary & Foreign keys. 2) Execute each statement in the correct order to create the relational database in MYSQL. 3)Insert some data into each table. 4) Use all your SQL create and Insert statements (from MS Word) to execute in the MYSQL WorkBench 5) Write...
PartA: Create the database. Name the database doctorWho. Then create a page that allows Doctor Who’s...
PartA: Create the database. Name the database doctorWho. Then create a page that allows Doctor Who’s assistant to add a new patient record. You will need to give the assistant rights to this database. The assistant’s username is 'helper' and the password is 'feelBetter'. For this to work, you will need to create several pages so be sure to include all of them when submitting your work. Name the main page addPatient.php. PartB: Add at least five records to the...
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.
mySQL database question.. I have a database that has the following tables: User (Id, Name, Gender)...
mySQL database question.. I have a database that has the following tables: User (Id, Name, Gender) Primary key = Id Friends (Id1, Id2, Startdate) Primary key = (Id1, Id2) Foreign keys are also Id1, Id2 pointing to User(Id) Comments (CommentId, Poster, Recipient, Text, PostDate) Primary key = (CommentId) Foreign Keys are Poster, Recipient pointing to User(Id) I need to answer the following queries: 5. List Users who have posted comments to all female users 6. List User(s) who have received...
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)...
JAVA StudentId: Consist of the first two characters of the student's first name, student's birth year,...
JAVA StudentId: Consist of the first two characters of the student's first name, student's birth year, and the last two characters of the last name. For instance, if the student full name is John Doe and birthyear is 1995, then the id will be Jo1995oe. Birthday is using GregorianCalendar. String firstname String lastname GregorianCalendar birthday
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT