is this proper sql? -


i have coupon software e-commerce site. want generate bunch of coupons @ once. consists of 2 tables. 1 coupon, , 1 coupon description. primary key being coupon_id.

is proper way sql? coupon_id match up? since auto-incremented , not inputting number think should.

edit: rechecked , coupon_id field in coupons table auto incremented not 1 in coupon_description

but i'm not sure if using 2 inserts proper way.

   insert  coupons (     coupon_id,     coupon_type,     coupon_code,     coupon_amount,     coupon_minimum_order,     coupon_start_date,     coupon_expire_date,     uses_per_coupon,     uses_per_user,     restrict_to_products,     restrict_to_categories,     restrict_to_customers,     coupon_active,     date_created,     date_modified     )     values (     '' , '',  '" . substr(md5(uniqid(rand(), true)), 0, 8) ."', '100' , '1' , '06/05/2013' , '06/11/2013' , '1' ,  '1',  '',  '',  '',  '',  '',  '')      insert coupons_description (     coupon_id,     language_id,     coupon_name,     coupon_description     )      values (     '', '1', 'test coupon', 'test'        ) 

since 1 auto-incremented, insert table first, value , hard-code dependant table. is:

insert  coupons ( coupon_type, coupon_code, ...) values ('',  '" . substr(md5(uniqid(rand(), true)), 0, 8) ."', '100' ,...). 

notice coupon_id not in insert statement. database assign (assuming auto-increment doing should). databases let assign this, consider bad form. problem, then, finding record again. i'd use:

select * coupons order coupon_id desc; 

unless else adding coupons @ same time, should see coupon on top. if used unique coupon name or description. anyway, you'll have take assigned id , update table without auto-increment:

insert coupons_description ( coupon_id, language_id, coupon_name, coupon_description)  values ('123', '1', 'test coupon', 'test') 

where '123' whatever coupon_id found select statement.

but syntax correct, otherwise.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -