INSERT multiple records using ruby on rails active record

The create method takes also an array as parameter. VoteRecord.create( [ { :prospect_id => prospect.id, :state => “OH”, :election_type => “GE”, :election => “2011-11-08”, :party => row[82], :participate => participated(row[82]) }, { :prospect_id => prospect.id, :state => “OH”, :election_type => “PR”, :election => “2011-09-13”, :party => row[81], :participate => participated(row[81]) } … ] ) However, … Read more

PHP mySQL – Insert new record into table with auto-increment on primary key

Use the DEFAULT keyword: $query = “INSERT INTO myTable VALUES (DEFAULT,’Fname’, ‘Lname’, ‘Website’)”; Also, you can specify the columns, (which is better practice): $query = “INSERT INTO myTable (fname, lname, website) VALUES (‘fname’, ‘lname’, ‘website’)”; Reference: http://dev.mysql.com/doc/refman/5.6/en/data-type-defaults.html

MySQL INSERT IF (custom if statements)

INSERT INTO TABLE SELECT value_for_column1, value_for_column2, … FROM wherever WHERE your_special_condition If no rows are returned from the select (because your special condition is false) no insert happens. Using your schema from question (assuming your id column is auto_increment): insert into orders (product_id, qty) select 2, 20 where (SELECT qty_on_hand FROM products WHERE id = … Read more

How can I INSERT data into two tables simultaneously in SQL Server?

Try this: insert into [table] ([data]) output inserted.id, inserted.data into table2 select [data] from [external_table] UPDATE: Re: Denis – this seems very close to what I want to do, but perhaps you could fix the following SQL statement for me? Basically the [data] in [table1] and the [data] in [table2] represent two different/distinct columns from … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)