Reputation: 75
I have students table as below
I want to create a new table certificates using SQL query where it will have certid as primary key auto incremented and rollno and marks should come from students table as foreign key (correct me if I am wrong) like below:
Upvotes: 0
Views: 38
Reputation: 18357
You have to create table certificates like this,
create table certificates (
certId int auto_increment primary key,
rollNo int,
marks int,
FOREIGN KEY (rollNo) REFERENCES students(rollNo)
);
Then using this command you can copy all data from students table to certificates table,
insert into certificates (rollNo,marks) select rollNo,marks from students;
Let me know if you needed this and have any issues doing it.
Upvotes: 1