In: Computer Science
1. Write the statements to create a table named REQUIREMENTS. The table has the following columns: credits number (primary key) and degree name.
2. Write the statements to create a table named CANDIDATE with the following columns names. Pick the best column type: student_id, first name, last name, credits and graduation date. The credits column is a foreign key to the credits column in the REQUIREMENTS table.
3. Write the statement(s) to Insert 2 rows in your REQUIREMENTS table. Make up your own data.
4. Write the statement(s) to insert 2 rows in your CANDIDATE table.
5. Add a new row to the CANDIDATE table.
ANSWERS
1) CREATE TABLE REQUIREMENTS (
credits number int PRIMARY KEY,
degree name varchar(100)
);
In the above statement we are create a table with the create table command and then write the name of the table and in the brackets I write the column names and then by giving space I wrote the data type of that column and then give the corressponding constraints of it and then giving another column name seperated by a coma(,). This is the syntax of creating a table. And write constraint if there is any constraint applied on that column otherwise no need of applying the constraints in any column. And if you are facing any error related to the column name then you could remove the space from the column name within itself.
2) CREATE TABLE CANDIDATE(
student_id varchar(50),
first name varchar(100).
last name varchar(100),
credits int,
graduation date date,
FOREIGN KEY (credits) REFERENCES REQUIREMENTS(credits number)
);
In the above statement I creates a table by giving colmn name then its datatype with its size in the brackets and in the last the credits column is the foreign key from the REQUIREMENTS table so that I take credits column as a foreign key references to the REQUIREMENTS table with its 'credits number' column in the bracket after the name of the table. This is the syntax of taking a foreign key from any other table. First you have to write foreign key then write the column name of that table which you want to make a foreign key write its name in the brackets then write references then write the table name of that table from which you wants to take reference and then write its column name in the brackets.
3) INSERT INTO REQUIREMENTS VALUES ( 08, 'Bachelor of Technology');
INSERT INTO REQUIREMENTS VALUES ( 07, 'Bachelor of Science');
In the above statements there are two statements of inserting two rows in the requirements table. The syntax is "INSERT INTO table_name VALUES (value1, value2, value3, ...); " in which values should be according to the sequence of the columns. And if you want to insert the value in the perticular column then you can also do it by specifying that column after writing the table name in the brackets.
4) INSERT INTO CANDIDATE VALUES ('BCS1903' , 'Robert' , 'Pattinson' , 08, '2022-11-20');
INSERT INTO CANDIDATE VALUES ('BIT1723' , 'Emma' , 'Watson' , 07, '2020-12-15');
In the baove statements there are two statements of inserting two rows in the candidate table. while inserting the date the format of date is 'YYYY-MM-DD' and if the values is of number type then we will write it without inverted comas and if any character is in the value then we have to write it in the inverted coma.
5) INSERT INTO CANDIDATE VALUES ('MBA1945' , 'Hannah' , 'Bakker' , 06 , '2023-06-30');
In the above statement we are adding a new row in the candidate table with the values corressponding to the columns of the candidate table according to its sequence.
If you have any problem with the answers then please comment on it. And Please give me an upvote.