We can work with nested transactions in MySQL with the help of SAVEPOINT.Firstly, create a table. After that, begin the transaction.Now, insert records in the table created above. Use SAVEPOINT statement to set a named transaction savepoint with a name of identifier.Here are all the steps shown in the form of query −Create tablemysql> create table NestedTransactionDemo -> ( -> Name varchar(200) -> ); Query OK, 0 rows affected (0.63 sec)Start the transaction −mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec)Now, insert a record in the tablemysql> insert into ... Read More
The difference between MySQL BigInt and int is that INT is a 32-bit long while BIGINT is 64-bit long.The following are some of the points −The BigInt takes 8 bytes of storage while int takes 4 bytes of storage.The int takes 4294967295 maximum values for int(10), whereas 18, 446, 744, 073, 709, 551, 615 for the bigint(20).The BigInt(20) and int(10), in this 20 and 10 can be used for width display with zerofill.Here is the demo of Bigint and int with zerofill. The following is the query to create a table.mysql> create table BigintandintDemo −> ( ... Read More
The 'socket' module in Python's standard library defines how server and client machines can communicate using socket endpoints on top of the operating system. The 'socket' API contains functions for both connection-oriented and connectionless network protocols.Socket is an end-point of a two-way communication link. It is characterized by IP address and the port number. Proper configuration of sockets on either ends is necessary so as to initiate a connection. This makes it possible to listen to incoming messages and then send the responses in a client-server environment.The socket() function in 'socket' module sets up a socket object.import socket obj = ... Read More
Earlier people used to go for ‘Nani ka Ghar’ in the vacations but nowadays people love adventure trips. Trekking and going to wildlife sanctuaries via Road trips have now become a fashion. However, there is a guideline you need to follow before embarking on such trips so that any unexpected instance does not spoil your taste.Plan the Trip in An Appropriate Season: It is not advisable to plan trekking in rainy season or monsoons, as one may slip and get injured.Jungle Safari: Jim Corbett or any other Jungle Safari can add a thrilling experience to your journey.Do Not Wear Perfume: ... Read More
The name can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the name and the given input name and returns true if they match and false otherwise.A program that demonstrates this is given as follows:Example Live Demopublic class Demo { public static void main(String args[]) { String name = "John Harry Smith"; String regexName = "\p{Upper}(\p{Lower}+\s?)"; String patternName = "(" + regexName + "){2, 3}"; System.out.println("The name is: " + name); System.out.println("Is the above name valid? " + name.matches(patternName)); ... Read More
You can use GROUP BY clause and COUNT() function for this. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, ..N, COUNT(*) as anyAliasName FROM yourTableName GROUP BY yourColumnName1, yourColumnName2;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table GroupAndCountByDate -> ( -> Id int NOT NULL AUTO_INCREMENT, -> TripDate date, -> ShopId int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.79 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> ... Read More
To merge two MySQL tables, use the following syntax −INSERT IGNORE INTO yourTableName1 select *from yourTableName2;We will create two tables with some records. After that the merge process will begin using the above syntax.Creating first table −mysql> create table MergeDemo1 -> ( -> id int, -> primary key(id), -> Name varchar(200) -> ); Query OK, 0 rows affected (1.00 sec)Inserting records into the table −mysql> insert into MergeDemo1 values(1, 'John'); Query OK, 1 row affected (0.21 sec)Displaying records from the tablemysql> select *from MergeDemo1;The following ... Read More
The “hh” format in Java Date is like 01 – 12 hour in AM/ PM. Use SimpleDateFormat("hh") to get the same format;// displaying hour in hh format SimpleDateFormat simpleformat = new SimpleDateFormat("hh"); String strHour2 = simpleformat.format(new Date()); System.out.println("Hour in hh format = "+strHour2);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More
SQLite is an open source database and is serverless that needs no configuration. Entire database is a single disk file that can be placed anywhere in operating system's file system. SQLite commands are similar to standard SQL. SQLite is extensively used by applications such as browsers for internal data storage. It is also convenient data storage for embedded devices.Standard Python library has in built support for SQLite database connectivity. It contains sqlite3 module which is a DB-API V2 compliant module written by Gerhad Haring. It adheres to DB-API 2.0.The DB-API has been defined in accordance with PEP-249 to ensure similarity ... Read More
To grant a user permission to only view a MySQL view, use the below syntaxGRANT SELECT ON yourDatabaseName.yourViewName TO ' yourUserName@'yourLocalHost';First you need to display all the view names from a table. The syntax is as follows −SHOW FULL TABLES IN yourDatabaseName WHERE TABLE_TYPE LIKE 'VIEW';Now implement the above syntax to display all views from a database. Here I am using the database name ‘test’. The query is as follows −mysql> SHOW FULL TABLES IN test WHERE TABLE_TYPE LIKE 'VIEW';The following is the output −+-------------------------------+------------+ | Tables_in_test | Table_type | +-------------------------------+------------+ | empidandempname_view ... Read More