0

Can anyone help me in Sqlite query

I created column 'ID' and gave constraint as 'Primary key', While inserting the values for other columns it is throwing an error to pass the value for 'ID'.

21st Sep 2022, 7:10 AM
S S
12 Antworten
+ 3
Tibor Santa and Calviղ Thanks for your help
22nd Sep 2022, 1:02 PM
S S
+ 2
Sultan Shaikh you can also manually specify the value of the ID if you want, when you do the insert. By using AUTOINCREMENT, the database will assign a number to each new row, based on an algorithm. Now that Calvin has already told you what is the problem, you are only a Google search away from finding out more: https://www.sqlite.org/autoinc.html
21st Sep 2022, 11:33 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Set AUTOINCREMENT to the ID
21st Sep 2022, 7:21 AM
Calviղ
Calviղ - avatar
+ 1
@Calvin, Data type is int then why should we add autoincrement?
21st Sep 2022, 8:39 AM
S S
+ 1
Tibor Santa I tried with manual entry, but it is allowing me for duplicate ID. I am not getting any error while entering the same ID which I already have.
21st Sep 2022, 11:47 AM
S S
+ 1
Sultan Shaikh The primary key does enforce uniqueness. See sample code here, it's not possible to insert the same ID twice. https://code.sololearn.com/cZUM385ZGOa3/?ref=app
21st Sep 2022, 7:05 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Tibor Santa Why did you use executemany instead of using execute for INSERT query?
22nd Sep 2022, 5:22 AM
S S
+ 1
It should not make any difference. Executemany has nice syntax to work on a data structure that contains all the relevant fields, and no need to write a loop. I copied and adjusted the example from python standard documentation. Maybe you have a problem with commit missing? You did not link your own code, so I can only guess. Maybe I shouldn't. :)
22nd Sep 2022, 12:02 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Sultan Shaikh Check out here how does the Animal table create data with ID auto increment set in Sqlite https://code.sololearn.com/wT34BpTg8sgH/?ref=app
22nd Sep 2022, 2:38 PM
Calviղ
Calviղ - avatar
0
Int data type is not auto increment by default
21st Sep 2022, 8:47 AM
Calviղ
Calviղ - avatar
0
Yes
24th Sep 2022, 11:58 AM
Mia
Mia - avatar
0
Mia I got the solution
24th Sep 2022, 1:44 PM
S S