George John

George John

789 Articles Published

Articles by George John

Page 66 of 79

How to change a primary key in MySQL to auto_increment?

George John
George John
Updated on 30-Jul-2019 4K+ Views

To change a primary key to auto_increment, you can use MODIFY command. Let us first create a table.mysql> create table changePrimaryKeyInAutoIncrement    -> (    -> StudentId int not null primary key,    -> StudentName varchar(100),    -> StudentAge int,    -> StudentAddress varchar(100)    -> ); Query OK, 0 rows affected (0.63 sec)Let us now check the description of table using desc command:mysql> desc changePrimaryKeyInAutoIncrement;This will produce the following output+----------------+--------------+------+-----+---------+-------+ | Field          | Type         | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+-------+ | StudentId      | int(11)   ...

Read More

Count value for multiple columns in MySQL?

George John
George John
Updated on 30-Jul-2019 646 Views

To count value for multiple columns, use the CASE statement. Let us first create a table::mysql> create table countValueMultipleColumnsDemo    -> (    -> Value1 int,    -> Value2 int,    -> Value3 int    -> ); Query OK, 0 rows affected (0.62 sec)Following is the query to insert some records in the table using insert command:mysql> insert into countValueMultipleColumnsDemo values(10, 15, 10); Query OK, 1 row affected (0.15 sec) mysql> insert into countValueMultipleColumnsDemo values(20, 30, 10); Query OK, 1 row affected (0.14 sec) mysql> insert into countValueMultipleColumnsDemo values(40, 10, 60); Query OK, 1 row affected (0.18 sec)Following ...

Read More

C++ Program to Check if an UnDirected Graph is a Tree or Not Using DFS

George John
George John
Updated on 30-Jul-2019 290 Views

A graph is a tree if it does not contain any cycle. This is a C++ program to check whether an undirected graph is tree or not.AlgorithmBegin function cyclicUtil() :    A) Mark the current node as visited.    B) Recur for all the vertices adjacent to this vertex.    C) If an adjacent is not visited, then recur for that adjacent.    D) If an adjacent is visited and not parent of current vertex, then there is a cycle. End Begin function cyclic():    A) Mark all the vertices as not visited and not part of recursion stack.   ...

Read More

In a MySQL schema, what is the meaning of "AUTO_INCREMENT=3

George John
George John
Updated on 30-Jul-2019 355 Views

In MySQL, AUTO_INCREMENT=3 tells that the inserted record will start from 3 not the default 1. Let us first create a sample table and set auto increment to 3:mysql> create table Auto_incrementDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> )AUTO_INCREMENT=3; Query OK, 0 rows affected (0.52 sec)Following is the query to insert some records in the table using insert command:mysql> INSERT INTO Auto_incrementDemo(Name) values('John'); Query OK, 1 row affected (0.12 sec) mysql> INSERT INTO Auto_incrementDemo(Name) values('Larry'); Query OK, 1 row affected (0.15 sec) mysql> INSERT INTO Auto_incrementDemo(Name) ...

Read More

Can MySQL concatenate strings with ||?

George John
George John
Updated on 30-Jul-2019 216 Views

Yes, you can concatenate strings with || in MySQL with the help of sql_mode. Set the sql_mode to PIPES_AS_CONCAT.The syntax is as followsset sql_mode=PIPES_AS_CONCAT;The following is the syntax to concat with the help of ||.SELECT ‘yourValue' || yourColumName AS anyAliasName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table PipeConcatDemo    - > (    - > Name varchar(20)    - > ); Query OK, 0 rows affected (0.93 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into PipeConcatDemo values('Larry'); Query ...

Read More

MySQL query to select one specific row and another random row?

George John
George John
Updated on 30-Jul-2019 245 Views

To select one specific row and another random row, you can use ORDER BY and RAND(). Let us first create a sample table:mysql> create table oneSpecificRowAndOtherRandom    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.72 sec)Following is the query to insert some records in the table using insert command:mysql> insert into oneSpecificRowAndOtherRandom(Name) values('Larry'); Query OK, 1 row affected (0.56 sec) mysql> insert into oneSpecificRowAndOtherRandom(Name) values('Sam'); Query OK, 1 row affected (0.13 sec) mysql> insert into oneSpecificRowAndOtherRandom(Name) values('Mike'); Query OK, 1 row affected ...

Read More

Does MySQL converts bool to tinyint(1) internally?

George John
George John
Updated on 30-Jul-2019 2K+ Views

Yes, MySQL internally convert bool to tinyint(1) because tinyint is the smallest integer data type.You can also say the bool is synonym for tinyint(1). Let us first create a sample table:mysql> create table boolToTinyIntDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> isAgeGreaterThan18 bool -> ); Query OK, 0 rows affected (1.02 sec)Let us now check the description of table:mysql> desc boolToTinyIntDemo;This will produce the following output+--------------------+-------------+------+-----+---------+----------------+ | Field ...

Read More

How to use "OR" condition in MySQL CASE expression?

George John
George John
Updated on 30-Jul-2019 244 Views

Set the same condition like “OR” in a MySQL CASE expression. Let us first create a sample table.Following is the querymysql> create table caseOrConditionDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(100),    -> Score int    -> ); Query OK, 0 rows affected (0.49 sec)Following is the query to insert some records in the table using insert command:mysql> insert into caseOrConditionDemo(Name, Score) values('Larry', 85); Query OK, 1 row affected (0.18 sec) mysql> insert into caseOrConditionDemo(Name, Score) values('Sam', 74); Query OK, 1 row affected (0.20 sec) mysql> insert into caseOrConditionDemo(Name, ...

Read More

C++ Program to Remove the Edges in a Given Cyclic Graph such that its Linear Extension can be Found

George John
George John
Updated on 30-Jul-2019 276 Views

In this Program we will basically find a feedback arc set which contains edges which when removed from the graph, graph becomes directed acyclic graph.AlgorithmBegin    function checkCG(int n) :    n: number of vertices.    arr: struct graph variable.    Initialize cnt = 0 and size = (n-1).    For i = 0 to n-1       if (cnt == size)          return 0       if (arr[i].ptr == NULL)          Increase cnt.          for j = 0 to n-1             while (arr[j].ptr ...

Read More

How to fix the incorrect datetime value while inserting in a MySQL table?

George John
George John
Updated on 30-Jul-2019 24K+ Views

To avoid the incorrect datetime value error, you can use the STR_TO_DATE() method.As we know the datetime format is YYYY-MM-DD and if you won’t insert in the same format, the error would get generated.Let us see what actually lead to this error. For this, let us create a new table. The query to create a table is as followsmysql> create table CorrectDatetimeDemo    - > (    - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > ArrivalTime datetime   - > ); Query OK, 0 rows affected (0.63 sec)The occurs when we try to include a ...

Read More
Showing 651–660 of 789 articles
« Prev 1 64 65 66 67 68 79 Next »
Advertisements