Arjun Thakur

Arjun Thakur

749 Articles Published

Articles by Arjun Thakur

Page 46 of 75

Which one is better to insert NULL or empty string in MySQL?

Arjun Thakur
Arjun Thakur
Updated on 24-Jun-2020 2K+ Views

In innoDB, NULL occupies less space as compared to empty string. Also, the NULL length is null while length of the empty string is 0.To understand this, a table is created with the help of create command which is given as follows −mysql> CREATE table DemoEmptyAndNULL -> ( -> Message varchar(100) -> ); Query OK, 0 rows affected (0.49 sec)After creating the table successfully, an empty record is inserted into the table with the help of insert command which is as follows −mysql> INSERT into DemoEmptyAndNULL values(' '); Query OK, 1 row affected (0.17 sec)After inserting the record, we can ...

Read More

How to get the max of two values MySQL?

Arjun Thakur
Arjun Thakur
Updated on 24-Jun-2020 2K+ Views

To get the maximum of two values in MySQL, we can use the predefined function “greatest”. The syntax of greatest() function is as follows −SELECT greatest(value1, value2);Applying the above query, To get the maximum value from two values. The query is as follows −Case 1We are giving both the values int.mysql> SELECT greatest(100, -300); After executing the above query, we will get the following output+--------------------+ | greatest(100, -300) | +--------------------+ | 100 | +--------------------+ 1 row in set (0.00 sec)Case 2We are giving both the ...

Read More

C++ Program to Remove all Characters in a String Except Alphabets

Arjun Thakur
Arjun Thakur
Updated on 24-Jun-2020 826 Views

A string is a one-dimensional character array that is terminated by a null character. It may contain characters, digits, special symbols etc.A program to remove all characters in a string except alphabets is given as follows.Example#include using namespace std; int main() {    char str[100] = "String@123!!";    int i, j;    cout

Read More

How do I print a double value with full precision using cout in C++?

Arjun Thakur
Arjun Thakur
Updated on 24-Jun-2020 2K+ Views

The output stream cout allows using manipulators that you can use to set the precision directly on cout and use the fixed format specifier. To get the full precision of a double, you can use the limits library. For example,Example#include #include using namespace std; int main() { // Get numeric limits of double typedef std::numeric_limits< double > dbl; double PI = 3.14159265358979; cout.precision(dbl::max_digits10); cout

Read More

Is segmentation fault actual undefined behavior in C++?

Arjun Thakur
Arjun Thakur
Updated on 24-Jun-2020 544 Views

Undefined behavior is a way to give freedom to implementors (e.g. of compilers or of OSes) and to computers to do whatever they "want", in other words, to not care about consequences.The cases in which segmentation fault occurs are transient in nature. They won't always result in a segmentation fault but can also run correctly(or at least appear to). For example, consider the following code fragment −#include int main() { int arr[2]; arr[0] = 0; arr[1] = 1; arr[2] = 2; // Undefined behaviour ...

Read More

How can we create MySQL view by selecting data based on pattern matching from base table?

Arjun Thakur
Arjun Thakur
Updated on 22-Jun-2020 239 Views

MySQL LIKE operator is used to select data based on pattern matching. Similarly, we can use LIKE operator with views to select particular data based on pattern matching from the base table. To understand this concept we are using the base table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | ...

Read More

How can we get the structure of a MySQL view as we can get the structure of a MySQL table?

Arjun Thakur
Arjun Thakur
Updated on 22-Jun-2020 524 Views

As we know that views are a type of virtual tables and are a composition of tables too hence we can use the same query to get the structure of a view which we use to get the structure of a table. In other words, we can use DESCRIBE statement to get the structure of a MySQL view. Its syntax would be as follows −SyntaxDESCRIBE view_name;Here, view_name is the name of the view of which we want to get the structure.ExampleSuppose we want to get the structure of a view named ‘Info’ then it can be done with the help, of the following query ...

Read More

What are the prerequisites before starting writing and using MySQL views?

Arjun Thakur
Arjun Thakur
Updated on 22-Jun-2020 307 Views

MySQL VersionAs we know that MySQL 5 introduced views, hence, first of all, we need to check for the version of MySQL before starting writing and using stored procedures. It can be done with the following query −mysql> Select VERSION(); +-----------+ | VERSION() | +-----------+ | 5.7.20 | +-----------+ 1 row in set (0.10 sec)Privileges for current userActually CREATE VIEW statement requires the CREATE VIEW privilege. Privileges for the current user can be checked with the following query −mysql> SHOW PRIVILEGESSelecting a databaseBefore creating a view we must have to select a database from the available databases. ...

Read More

What is the use of ON COMPLETION PRESERVE clause while creating the event?

Arjun Thakur
Arjun Thakur
Updated on 22-Jun-2020 3K+ Views

As we know that an event is automatically dropped when it is expired and we would not be able to see it from SHOW EVENTS statement. To change such kind of behavior we can use ON COMPLETION PRESERVE while creating the event. It can be understood from the following example −Examplemysql> Create table event_messages(ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, MESSAGE VARCHAR(255) NOT NULL, Generated_at DATETIME NOT NULL); Query OK, 0 rows affected (0.61 sec)The below query will create an event without the use of ON COMPLETION PRESERVE hence it would not be seen in the output of SHOW EVENTS ...

Read More

How we can find all the triggers associated with a particular MySQL table?

Arjun Thakur
Arjun Thakur
Updated on 22-Jun-2020 179 Views

We can find all the triggers associated with a particular table with the help of the following query −mysql> Select * from INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_SCHEMA = 'query'AND EVENT_OBJECT_TABLE = 'Student_info'\G *************************** 1. row *************************** TRIGGER_CATALOG: def TRIGGER_SCHEMA: query TRIGGER_NAME: studentinfo_after_delete EVENT_MANIPULATION: DELETE EVENT_OBJECT_CATALOG: def ...

Read More
Showing 451–460 of 749 articles
« Prev 1 44 45 46 47 48 75 Next »
Advertisements