Tutorialspoint

What does the KEY keyword mean in MySQL?

George John
Answered 6h 28m ago

The ‘Key’ keyword in MySQL is a constraint while index is a type of data structure which can be used to implement the constraint. Key is synonymous to an index. If you want to create an index for a column, then use ‘Key’. The key can be used with the ... Read More

How to convert MySQL datetime to Unix timestamp?

Ankith Reddy
Answered 6h 30m ago

We can convert MySQL date and time to Unix Timestamp with the help of function UNIX_TIMESTAMP(). The following is the query. mysql> SELECT UNIX_TIMESTAMP(STR_TO_DATE('Oct 19 2018 10:00PM', '%M %d %Y %h:%i%p')); After running the above query we will not get the output in date format as shown in ... Read More

How to remove leading and trailing whitespace from a MySQL field value?

George John
Answered 6h 33m ago

We can remove the leading and trailing whitespaces from MySQL with the help of trim() function. The following is the syntax. mysql> SELECT TRIM(' AnyStringWithWhitespaces '); Let us now implement the above syntax in the below query. mysql> SELECT TRIM(' Leading And ... Read More

Using DISTINCT and COUNT together in a MySQL Query?

Chandu yadav
Answered 6h 37m ago

We can use DISTINCT and COUNT together in a single MySQL query. Firstly, let us create a table. The CREATE command is used to create a table. mysql> create table DistCountDemo - > ( - > id int, - > ... Read More

Making an existing field Unique in MySQL?

George John
Answered 7h 4m ago

Unique in MySQL means we cannot add duplicate records. Let us now see how to create a unique constraint in the column at the time of creating a table. mysql> create table UniqueConstDemo - > ( - > name varchar(100) unique ... Read More

How to add not null constraint to existing column in MySQL?

Ankith Reddy
Answered 7h 9m ago

To add not null constraint to an existing column in MySQL, we will use the ALTER command. This is a type of validation to restrict the user from entering null values. Let us see an example. Firstly, we will create a table. The CREATE command is used to create a ... Read More

How to list down all the running queries in MySQL?

Maheshwari Thakur
Answered 7h 12m ago

To list running queries, we need to use the ‘show processlist’ command. The following is the query. mysql> SHOW processlist; The following is the output of the above query. +----+-----------------+-----------------+----------+---------+-------+------------------------+------------------+ | Id | User | Host ... Read More

How to insert current date/time in MySQL?

Chandu yadav
Answered 7h 14m ago

To insert current date/ time in MySQL, use the now() function. Let us now see an example. At first, we will create a table. The CREATE command is used to create a table. mysql > create table CurrentDateTime -> ( -> CurrentTime datetime ... Read More

How to get the count of each distinct value in a column in MySQL?

Chandu yadav
Answered 7h 40m ago

Let us see an example to get the count of each distinct value in a column. Firstly, we will create a table. The CREATE command is used to create a table. mysql> create table DistinctDemo1 - > ( - > id int, ... Read More

How do I get SUM function in MySQL to return '0' if no values are found?

George John
Answered 7h 44m ago

To return Sum as ‘0’ if no values are found, use IFNULL or COALESCE commands. The following is the syntax for IFNULL. SELECT IFNULL(SUM(NULL), 0) AS aliasName; Let us now implement the above syntax in the following query. mysql> SELECT IFNULL(SUM(NULL), 0) AS SUMOFTWO; The following ... Read More

Different methods to check if a MySQL table exist?

Ankith Reddy
Answered 7h 51m ago

Let us see some of the ways to check if a table exist in MySQL or not. Using SHOW The SHOW command displays all the tables. SHOW tables; Here is the output. +--------------------------+ | Tables_in_business | +--------------------------+ ... Read More

When should I use a composite index in MySQL?

Maheshwari Thakur
Answered 7h 54m ago

The composite index can be used when we are using sub queries. The advantages of using composite index are in case of. Joining Filtering Selecting The following is the syntax of index. index(column_name1, column_name2, column_name3, column_name4, ............................N) Let us create a table first and within that ... Read More

How to do a batch insert in MySQL?

Chandu yadav
Answered 7h 57m ago

To do a batch insert, we need to use all column names with parenthesis, separated by ‘, ’. Let us see an example. First, we will create a table. The following is the CREATE command to create a table. mysql> CREATE table MultipleRecordWithValues - > ( ... Read More

What does 'show processlist' command do in MySQL?

George John
Answered 8h 47m ago

The ‘SHOW processlist’ command can be used to display the running thread related to only your MySQL account. We can see almost all running threads if we have process privileges. It shows which threads are running. The following is the query. mysql> SHOW processlist; Here is the output. ... Read More

How to reset or change the MySQL root password?

Ankith Reddy
Answered 8h 51m ago

To reset or change the root password, first we need to open MySQL in the Administrator mode. There, we can see all the users as well as the host. The following is the query − mysql> USE mysql; Database changed mysql> SELECT user, host from user; Here is ... Read More

1 2 3 4 5 6 7 ... 875 Next
Advertisements
Loading...
Unanswered Questions View All