
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6705 Articles for Database

3K+ Views
Actually, both MySQL IFNULL() and NULLIF() functions are having an almost same syntax as given below −The syntax of IFNULL()IFNULL(expression1, expression2)The syntax of NULLIF()NULLIF(expression1, expression2)They can be distinguished in the way they return the first argument as result. IFNULL() function will return the first argument as a result if it is not NULL and NULLIF() function will return the first argument as a result if both the arguments are not same.mysql> Select IFNULL('Ram', 'Shyam'); +-----------------------+ | IFNULL('Ram', 'Shyam') | +-----------------------+ | Ram | +-----------------------+ 1 row in set (0.00 sec) mysql> Select ... Read More

162 Views
Once we get connected to the MySQL server, it is required to select a database to work with. This is because there might be more than one database available with the MySQL Server.It is very simple to select a database from the mysql> prompt. We can use SQL command ‘use’ to select a database. To illustrate it we are selecting the database named ‘Tutorials’ in the following example −Example[root@host]# mysql -u root -p Enter password:****** mysql> use TUTORIALS; Database changed mysql>Now, we have selected the TUTORIALS database and all the subsequent operations will be performed on the TUTORIALS database.Read More

1K+ Views
As we know that if no comparison or condition is true then CASE statement returns the result specified after ELSE statement. But what if there is no ELSE statement, then in this situation, CASE statement would return NULL. Following is an example to demonstrate it.Examplemysql> Select CASE 100 -> WHEN 150 THEN 'It is matched' -> WHEN 200 THEN 'It is not matched' -> END As 'It Returns NULL'; +-----------------+ | It Returns NULL | +-----------------+ | NULL | +-----------------+ 1 row in set (0.00 sec)The query below, using the data from ... Read More

165 Views
To understand it consider the data, as follows, from the table ‘Students’ −mysql> Select * from Students; +----+-----------+-----------+----------+----------------+ | id | Name | Country | Language | Course | +----+-----------+-----------+----------+----------------+ | 1 | Francis | UK | English | Literature | | 2 | Rick | USA | English | History | | 3 | Correy | USA | English | Computers | | 4 | Shane | France | ... Read More

165 Views
We would need special privileges to create or to delete a MySQL database. Following is the syntax of dropping a database using mysqladmin binary −Syntax[root@host]# mysqladmin -u root -p drop db_name Enter password:******Here, db_name is the name of the database we want to delete.ExampleFollowing is an example to delete a database named TUTORIALS −[root@host]# mysqladmin -u root -p drop TUTORIALS Enter password:******The above statement will give you a warning and it will confirm if you really want to delete this database or not.Dropping the database is potentially a very bad thing to do. Any data stored in the database will be ... Read More

390 Views
MySQL CASE statement is a flow control function that allows us to build conditions inside a query such as SELECT or WHERE clause. We have two syntaxes of CASE statementSyntax-1CASE val WHEN compare_val1 THEN result1 WHEN compare_val2 THEN result2 . . . Else result ENDHere in this 1st syntax, if the val is equal to compare_val1 then the CASE statement returns result1. If the val is equal to compare_val2 then the CASE statement returns result2 and so on.In case if the val does not match any compare_val then the CASE statement returns the result specified in ELSE clause.Examplemysql> Select CASE 100 ... Read More

202 Views
We would need special privileges to create or to delete a MySQL database. Following is the syntax for creating a new database using mysqladmin binary −Syntax[root@host]# mysqladmin -u root -p create db_name Enter password:******Here, db_name is the name of the database we want to create.ExampleFollowing is a simple example to create a database called TUTORIALS −[root@host]# mysqladmin -u root -p create TUTORIALS Enter password:******The above query will create a MySQL database called TUTORIALS.

128 Views
You can establish the MySQL database using the mysql binary at the command prompt. It can be understood with the help of the following example −ExampleWe can use following statements to connect to the MySQL server from the command prompt −[root@host]# mysql -u root -p Enter password:******This will give us the mysql> command prompt where we will be able to execute any SQL command. Following is the result of above command −The following code block shows the result of above code −Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.20 MySQL ... Read More

163 Views
We can also add user account by using GRANT SQL command. It can be illustrated by using the following example −ExampleIn this example, we will add user Zara with password zara123 for a particular database,which is named as TUTORIALS.root@host# mysql -u root -p password; Enter password:******* mysql> use mysql; Database changed mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP -> ON TUTORIALS.* -> TO 'zara'@'localhost' -> IDENTIFIED BY 'zara123';The above statements will also create an entry in the MySQL database table called as a user.

2K+ Views
For adding a new user to MySQL, we just need to add a new entry to the user table in the database mysql. To illustrate it we are using the following example −ExampleThe following program is an example of adding a new user guest with SELECT, INSERT and UPDATE privileges with the password guest123; the SQL query is −root@host# mysql -u root -p Enter password:******* mysql> use mysql; Database changed mysql> INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'guest', PASSWORD('guest123'), 'Y', 'Y’, 'Y'); Query OK, 1 row affected (0.20 sec) mysql> FLUSH PRIVILEGES; Query OK, ... Read More