Update MySQL Table Storage Engine

AmitDiwan
Updated on 18-Dec-2019 05:12:31

278 Views

To update MySQL table engine, following the below syntax −Syntaxalter table yourTableName ENGINE=InnoDB;Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20),    -> StudentAge int,    -> StudentCountryName varchar(20)    -> )ENGINE=MyISAM, AUTO_INCREMENT=101; Query OK, 0 rows affected (0.18 sec)Let us check the description of table −mysql> show create table DemoTable;This will produce the following output −+---------------+-----------------------------------------------------------------------------------------+ | Table         | Create Table                                   ... Read More

Fetch Maximum Individual Marks for a Student in MySQL

AmitDiwan
Updated on 18-Dec-2019 05:05:52

292 Views

For this, use MAX() along with GROUP BY clause. Let us first create a table −mysql> create table DemoTable    -> (    -> StudentEmailId varchar(20),    -> Marks1 int,    -> Marks2 int -> ); Query OK, 0 rows affected (0.90 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John@gmail.com', 45, 32); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values('John@gmail.com', 32, 45); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values('Carol@gmail.com', 32, 45); Query OK, 1 row affected (1.64 sec) mysql> insert into DemoTable values('David@gmail.com', 45, 32); ... Read More

Select Maximum for Each Value in a MySQL Table

AmitDiwan
Updated on 18-Dec-2019 05:03:19

219 Views

For this, use GROUP BY clause along with MAX(). Let us first create a table −mysql> create table DemoTable    -> (    -> CountryName varchar(20),    -> Population int    -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('US', 560); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('UK', 10090); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('UK', 8794); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('US', 1090); Query OK, 1 row affected (0.21 sec)Display ... Read More

Grant on Databases Created After the Grant in MySQL

AmitDiwan
Updated on 18-Dec-2019 05:00:47

140 Views

Yes, since this is a global privilege. Let us first create a user −mysql> CREATE USER 'Jace'@'localhost' IDENTIFIED BY 'Jace123'; Query OK, 0 rows affected (0.67 sec)Here is the query to grant for global privileges with *.*:mysql> GRANT SELECT ON *.* TO 'Jace'@'localhost'; Query OK, 0 rows affected (0.58 sec)Now you can show all grants for a user −mysql> show grants for 'Jace'@'localhost';This will produce the following output −+-------------------------------------------+ | Grants for Jace@localhost                 | +-------------------------------------------+ | GRANT SELECT ON *.* TO `Jace`@`localhost` | +-------------------------------------------+ 1 row in set (0.14 sec)

Comparing String Objects Using Relational Operators in C++

Arnab Chakraborty
Updated on 17-Dec-2019 13:31:15

473 Views

Here we will see how to compare two strings in C++. The C++ has string class. It also has the compare() function in the standard library to compare strings. But here we will use the conditional operators like ==, !=, , =. These operators check the strings character by characters. Let us see the code to get better idea.Example Live Demo#include using namespace std; void compareStrings(string s1, string s2) {    if (s1 != s2)       cout

Code Valid in Both C and C++ but Produces Different Output

Arnab Chakraborty
Updated on 17-Dec-2019 13:26:14

135 Views

Here we will see some program that will return different results if they are compiled in C or C++ compilers. We can find many such programs, but here we are discussing about some of them.In C and C++, the character literals are treated as different manner. In C, they are treated as int but in C++, they are treated as characters. So if we check the size using sizeof() operator, it will return 4 in C, and 1 in C++.Example Live Demo#include int main() {    printf("The character: %c, size(%d)", 'a', sizeof('a')); }OutputThe character: a, size(4)Example#include int main() {    printf("The ... Read More

Chrono in C++

Arnab Chakraborty
Updated on 17-Dec-2019 13:23:17

408 Views

In this section we will see what is the Chrono library in C++. This Chrono library is used for date and time. Timers and clocks are different in different systems. So if we want to improve time over precision we can use this library.In this library, it provides precision-neutral concept, by separating the durations and point of time.The duration objects are used to express time span by means of a count like minute, two hours or ten minutes. For example, 30 seconds is represented by a duration consisting of 30 ticks of unit of 1 seconds.Example Live Demo#include #include ... Read More

Use getline in C++ with Blank Lines in Input

Arnab Chakraborty
Updated on 17-Dec-2019 13:20:55

976 Views

In C++, we use the getline() function to read lines from stream. It takes input until the enter button is pressed, or user given delimiter is given. Here we will see how to take the new line character as input using the getline() function. Let us see the following implementation to get the idea.Example Live Demo#include using namespace std; int main() {    string str;    int term = 4;    while (term--) {       getline(cin, str);       while (str.length()==0 )       getline(cin, str);       cout

Traverse C++ Set in Reverse Direction

Arnab Chakraborty
Updated on 17-Dec-2019 13:19:02

1K+ Views

Suppose we have a set, then we have to traverse the set in reverse direction. So if the set is like S = [10, 15, 26, 30, 35, 40, 48, 87, 98], then the output will be: 98 87 48 40 35 30 26 15 10.To traverse in reverse order, we can use the reverse_iterator. Here we will use the rbegin() and rend() function to get the begin and end of the reverse iterator.Example Live Demo#include #include using namespace std; int main() {    int arr[] = {10, 15, 26, 30, 35, 40, 48, 87, 98};    set my_set(arr, arr + sizeof(arr) / sizeof(arr[0]));    set::iterator it;    cout

Reverse an Array Using STL in C++

Arnab Chakraborty
Updated on 17-Dec-2019 13:15:32

984 Views

Here we will see how to reverse an array using STL functions in C++. So if the array is like A = [10, 20, 30, 40, 50, 60], then the output will be B = [60, 50, 40, 30, 20, 10]. To reverse we have one function called reverse() present in the header file . The code is like below −Example Live Demo#include #include using namespace std; int main() {    int arr[] = {10, 20, 30, 40, 50, 60};    int n = sizeof(arr) / sizeof(arr[0]);    cout

Advertisements