Reputation: 1
I have a problem while inserting data in sqlite database.i created a table with 3 columns studentid,studentname and studentmarks.when i insert same marks for two different students it doesn't insert duplicate entery.How to solve this problem that it will accept duplicate entries on student name and student marks.thanks
Upvotes: 0
Views: 909
Reputation: 606
Check whether there's an Unique constraint on marks column/or if u have set marks as primary key if either of the above case is true you should drop unique constraint/primary key to make your code work as you expect (drop index index_name on table_name) .
Upvotes: 0
Reputation: 35464
Since you have a student id there is no need to have a student name. The table should have a course ID/Name column to associate a specific mark with a student and course.
Basically you want three tables:
Student (ID, Name)
Course (ID, Name)
Mark (studentID, courseID, studentMark)
This is called third normal form
. http://en.wikipedia.org/wiki/Third_normal_form
However, if you want just one table for your database, then you still must add course id and/or name to the table and make sure that the primary key include student id and course id.
Upvotes: 3
Reputation: 12737
You might have created the table with a primary key as StudentID. In that case, you can not insert multiple rows for a single Students marks. You will need to re-create the table removing restrictions like primary key/unique values for StudentID
You should also create a separate table for Students
, with a primary key (Student ID
) in which you only insert student data (each row represents a single student).
Then create a table for Student_marks in which the relation of Student to Marks is One-To-Many, meaning that multiple rows in Students_Marks
belong to a single row in Students
table
Upvotes: 0