In Magento 2 while importing category data using repository it takes too much time to insert. Can I use raw SQL queries?
Related
Are queries or statements like (INSERT and SELECT)belong to any language LIKE(SQL OR PHP) or is it just a style of code(writing or entered into) the databases like MySQL.
Thank u :)
INSERT, SELECT, UPDATE, DELETE etc are part of sql. And almost every Database Package support sql as a query language to communicate with database.
Reference
I am updating mysql data through php script. I am looking to use mysqli_multi_query() instead of mysql_query. I have N number of update queries to execute. Please suggest if multi query will help in better execution time.
A. Updating data using mysql_query(), Firing single single queries N times.
B. Concatinating All Update queries with ";" and firing once using multi query.
Please Suggest if Technique "B" will help in performance.
Thanks.
C. Use prepared statements and if possible (InnoDB) within a transaction.
A multiquery will save you some client-server roundups, but the queries are still executed one by one.
If you use prepared statement together with transactions, the query is checked once by the parser after that just values are pasted to server. Transaction prevents indexes being rebuild after each update.
Multiple insert statements can be rewritten as a single bulk insert statement:
INSERT INTO t1 (c1,c2,c3) VALUES (1,2,3), (3,4,5) --etc
When I execute a prepared statement to select rows in a db table, does pdo "fetch" the records and caches it?
i.e. If I perform a fetch after executing a "select" statement, does pdo perform multiple db calls for each record I want fetched or does it simply fetch each record from its cache? (assuming it has cache)
tnx.
When you ask does pdo perform multiple db calls for each record if you mean a database connection or query by saying calls, then no. the way it works pdo opens the connection, query once then if you use fetchAll() it gets all the values at once while fetch() will get one value at the the time.
The caching you are referring when using prepare() a and execute() for statements that will be issued multiple times with different parameter values optimizes the performance of your application by allowing the driver to negotiate client and/or server side caching of the query plan and meta information.
Unless you are fetching huge amount of records (into the memory) you should not be concern with the cost of using fetch.
Sooo.. to answer your question PDO will not cache fetch , it will be stored into memory.
I have 5 text box contaning 5 contact no of a particular person. I want to insert those 5 contact no in tblContact(person_id|contact_no). Can I insert these 5 contact no in one sql statement OR I have to call a loop to insert 5 records?
INSERT INTO `tblContact` (`person_id`, `contact_no`) VALUES
('PERSON_ID_VALUE_1', 'CONTACT_NO_VALUE_1'),
('PERSON_ID_VALUE_2', 'CONTACT_NO_VALUE_2'),
('PERSON_ID_VALUE_3', 'CONTACT_NO_VALUE_3'),
('PERSON_ID_VALUE_4', 'CONTACT_NO_VALUE_4'),
('PERSON_ID_VALUE_5', 'CONTACT_NO_VALUE_5');
Many databases have a multi-row insert capability and MySQL is one of them. You can use (in 5.0+, not sure about earlier versions although a brief look at the 3.23/4.0/4.1 docs seems to indicate yes) something like:
insert into tblContact (person_id,contact_no) values
(1, '555-5555'),
(2, '555-1234');
More details here.
Aside: In genneral, if your database didn't support multi-row insert, you'd probably just use a transaction around the group of individual insert statements. We've found that multi-row inserts actually give us a pretty hefty speed increase (on our DBMS anyway - YMMV).
you can insert your 5 records in 1 insert statements.
like: insert into tblContact(person_id, contact_no) values(1,'145566'),(2,'233366'),(3,'564666')
I have these tables: My final mysql db, could someone check if the tables are correctly made?
How can I make an Insertion of an ad here?
Is join used on insert also?
Thanks
Clarification: I need to insert values into multiple tables here, and don't know how to do it else than using multiple INSERT INTO statements.
So I wonder if there is anyway to make just ONE statement (one line) and use JOIN to INSERT?
As far as I'm aware of, you can't INSERT data into multiple tables Within one plain SQL statement.
There are many database abstraction frameworks out there which can do something like that (DOCTRINE TO THE RESCUE!!) but thats a whole other story.
SQL for it self it not capable of such things.
No it's not possible with an INSERT statement to insert into multiple tables. But you could use a stored procedure that would nicely batch the various inserts, and the application would have only one SQL command to emit.
I don't understand your first question about the ads. As for the second, JOIN will not be used on a standard table unless you are using it in an INSERT...SELECT statement, which you very likely aren't.