Note Please Change the Data Type or Value of data like I have
given 5 you should change it to your own choice.
Q1. You are required to create the following tables using SQL CREATE command,
table names along with column description is given below. One of the important
things is to use appropriate data types for each column definition and choosing
primary and foreign keys for the tables.
Step 1:
1. Table Name: MEMBER
CREATE TABLE MEMBER ( MemberId char(5) PRIMARY KEY, FirstName char(30),
LastName char(30),
DateOfBirth char(10),City char(30), ZipCode_Email char(50), DateOfJoining char(10) )
2. Table Name: ATTENDANCE
CREATE TABLE ATTENDENCE( MeetingDate char(10), Location char(50),
MemberAttended char(1),
MemberId char(5) FOREIGN KEY REFERENCES MEMBER(MemberId))
3. Table Name: DOCUMENTARY
CREATE TABLE DOCUMENTRY( DoumentryId char(5) PRIMARY KEY,
DocumentyName char(30), YearReleased char(10),
AvailableOnDVD char(3), Rating char(10),CategoryId char(5) FOREIGN KEY
REFERENCES CATEGORY(CategoryId))
4. Table Name: CATEGORY
CREATE TABLE CATEGORY ( CategoryId char(5) PRIMARY KEY, Category
char(25))
5. Table Name: FAVOURITE_CATEGORY
CREATE TABLE FAVORITE_CATEGORY( CategoryId char(5) FOREIGN KEY
REFERENCES CATEGORY(CategoryId),
MemberId char(5) FOREIGN KEY REFERENCES MEMBER(MemberId))
Step 2:
What to do next???
After creating these tables successfully you are required to enter Five (5) records in each
of the tables using SQL’s INSERT command.
Answer:-
I didn’t attach my snap you have to use Insert statement like that,
INSERT INTO TABLE NAME VALUES (‘1st column value’,’2nd column value’, &
so on)
Q2. Differentiate ALTER and UPDATE table commands in SQL. You are required
to write example SQL queries for illustration.
Answer:-
The ALTER Statement:-
The ALTER TABLE statement is used to add, delete,
or modify columns in an existing table.
SQL ALTER TABLE Syntax
1). To add a column in a table, use the following syntax:
ALTER TABLE table_name
ADD column_name datatype
2). To delete a column in a table, use the following syntax
ALTER TABLE table_name
DROP COLUMN column_name
3). To change the data type of a column in a table, use the following syntax:
ALTER TABLE table_name
ALTER COLUMN column_name datatype
Query:-
ALTER TABLE ATTENDENCE
DROP COLUMN MemberAttended
The UPDATE Statement:-
The UPDATE statement is used to update existing records in a
table.
SQL UPDATE Syntax:-
UPDATE table_name
SET column1=value, column2=value2...
WHERE some_column=some_value
Query:-
UPDATE ATTENDENCE
SET Location ='Karachi'
WHERE Location='Islamabad'