This is for sql Create a student club CLUB with a unique nam
This is for sql
Create a student club (CLUB) with a unique name (up to 30 characters), a description of the club, and the club president (ClubPresidentId) who is a student. Attach a referential triggered action such that when a student is deleted, then the president foreign key is automatically set to NULL for all clubs referencing the deleted student.
a. CREATE TABLE CLUB ( NAME VARCHAR(30) NOT NULL, DESCRIPTION VARCHAR(100), ClubPresidentId INT, PRIMARY KEY (NAME), ON DELETE SET NULL );
b. CREATE TABLE CLUB ( NAME VARCHAR(30) NOT NULL, DESCRIPTION VARCHAR(100), ClubPresidentId INT, PRIMARY KEY (NAME), FOREIGN KEY(ClubPresidentId) REFERENCES STUDENT(StudentId) ON DELETE SET NULL );
c. c. CREATE TABLE CLUB ( NAME VARCHAR(30) NOT NULL, DESCRIPTION VARCHAR(100), ClubPresidentId INT, PRIMARY KEY (NAME), FOREIGN KEY(ClubPresidentId) REFERENCES STUDENT(StudentId) );
Solution
A Foreign key with \"set null on delete \" is used for our requirement mentioned
It means that if a record in the parent table is deleted,then the corresponding records in the child table will ha the Foreign key fields set to NULl. It can be created using either a CREATE TABLE statement or an ALTER TABLE statement
Answer for it requirement is
CREATE TABLE Student(StuName varchar(30),Description varchar(100)StudentId int,ClubPresidentId int, PRIMARY KEY(StudentId));
CREATE TABLE CLUB(NAME VARCHAR(30) NOT NULL, DESCRIPTION VARCHAR(100), ClubPresidentId INT, PRIMARY KEY (NAME), FOREIGN KEY(ClubPresidentId) REFERENCES STUDENT(StudentId) );
