"An Apex transaction represents a set of operations that are executed as a single unit. All DML operations in a transaction either complete successfully, or if an error occurs in one operation, the entire transaction is rolled back and no data is committed to the database. The boundary of a transaction can be a trigger, a class method, an anonymous block of code, a Visualforce page, or a custom Web service method."
Please read this link, it will help. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_transaction.htm
In order to bulkify your code and process mutiple records in one transaction you should use apex collections E.g Maps, Set, List
"An Apex transaction represents a set of operations that are executed as a single unit. All DML operations in a transaction either complete successfully, or if an error occurs in one operation, the entire transaction is rolled back and no data is committed to the database. The boundary of a transaction can be a trigger, a class method, an anonymous block of code, a Visualforce page, or a custom Web service method."
Please read this link, it will help.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_transaction.htm
In order to bulkify your code and process mutiple records in one transaction you should use apex collections E.g Maps, Set, List
https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code
Thanks,
Fahad Akhtar