I have a table called rent on MySQL
id, int (5), autoincrement PRIMARY KEY
dNo, int (5)
pRent, varchar (5)
status, varchar (10)
I need to insert 300 rows into this table
id and dNo need to match
so in the end we will have id/dNo up until 300. How can this be done?
pRent will have a default value of 0
status will have a default value of vacant
What SQL query should I use to insert all 300 rows in at once with id/dNo autoincrement up to 300?
Assuming the id is set to
auto incrementyou can just insert the lot then do anupdate table set dNo=idI’m not sure if you can set
dNo=idduring insert as the id would beNULLYou might be able to set the
dNodefault value toidEdit:
Works fine, but not if I set
id=NULL.Looks like you’ll have to user triggers