Found 6702 Articles for Database

How to Drop MySQL Table using Java?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

212 Views

Let us first create a table in a database. The query to create a table is as followsmysql> create table customerDetails    -> (    -> CustomerId int,    -> CustomerName varchar(30)    -> ); Query OK, 0 rows affected (0.56 sec)Now display all tables from the database in order to check the customerDetails table is present or not.The query is as followsmysql> show tables;The following is the output+------------------------------+ | Tables_in_test3              | +------------------------------+ | bestdateformatdemo           | | customerdetails              | | deletedemo     ... Read More

Resolve error 1045 (28000) access denied for user 'root'@'localhost' (using password: YES)?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

4K+ Views

To fix this error, you need to specify the -p option for password.The syntax is as followsmysql -uyourUserName -pLet us implement it.First, we need to open CMD using Windows+R shortcut keys. The snapshot is as followsType CMD and press OK button. You will get a command prompt.The snapshot is as followsNow reach the MySQL bin directory.The snapshot is as followsNow use the syntax discussed in the beginning.The command is as follows

MySQL temporary variable assignment?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

3K+ Views

You can use SET command for temporary variable assignment.The syntax is as followsSET @anyVariableName=(SELECT yourColumnName FROM yourTableName WHERE yourCondition);To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table tempVariableAssignment    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (0.59 sec)Now insert some records in the table using insert commandmysql> insert into tempVariableAssignment(Name, Age) values('John', 25); Query OK, 1 row affected (0.14 sec) mysql> insert into tempVariableAssignment(Name, Age) values('Carol', 26); Query ... Read More

How to update the current delimiter in MySQL?

George John
Updated on 30-Jul-2019 22:30:25

230 Views

At first, let us determine the current delimiter in MySQL using the following syntax\sThe above syntax will let you know about the current delimiter. Let us implement the above syntax.The query is as followsmysql> \sThe following is the outputC:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe Ver 8.0.12 for Win64 on x86_64 (MySQL Community Server - GPL) Connection id: 19 Current database: sample Current user: root@localhost SSL: Cipher in use is DHE-RSA-AES128-GCM-SHA256 Using delimiter: ; Server version: 8.0.12 MySQL Community Server - GPL Protocol version: 10 Connection: localhost via TCP/IP Insert id: 11 Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: ... Read More

Priority of AND and OR operator in MySQL select query?

Chandu yadav
Updated on 06-Aug-2021 21:41:51

987 Views

The AND has the highest priority than the OR operator in MySQL select query.Let us check how MySQL gives the highest priority to AND operator.The query is as followsmysql> select 0 AND 0 OR 1 as Result;The following is the output+--------+ | Result | +--------+ | 1     | +--------+ 1 row in set (0.00 sec)If you are considering the OR operator has the highest priority then MySQL will wrap up the above query like this.The query is as followsselect 0 AND (0 OR 1) as ResultFirst, solve the 0 OR 1, this will give result 1. After that ... Read More

How to count number of distinct values per field/ key in MongoDB?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

403 Views

You can use the distinct command for this. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.distinctCountValuesDemo.insertOne({"StudentFirstName":"John", "StudentFavouriteSubject":["C", "C++", "Java", "MySQL", "C", "C++"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a39f193b406bd3df60e07") } > db.distinctCountValuesDemo.insertOne({"StudentFirstName":"Larry", "StudentFavouriteSubject":["MongoDB", "SQL Server"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a3a1193b406bd3df60e08") }Display all documents from a collection with the help of find() method. The query is as follows −> db.distinctCountValuesDemo.find().pretty();The following is the output −{    "_id" : ObjectId("5c8a39f193b406bd3df60e07"),    "StudentFirstName" : "John",    "StudentFavouriteSubject" : [ ... Read More

Find duplicate records in MongoDB?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

2K+ Views

You can use the aggregate framework to find duplicate records in MongoDB. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.findDuplicateRecordsDemo.insertOne({"StudentFirstName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a330293b406bd3df60e01") } > db.findDuplicateRecordsDemo.insertOne({"StudentFirstName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a330493b406bd3df60e02") } > db.findDuplicateRecordsDemo.insertOne({"StudentFirstName":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a330c93b406bd3df60e03") } > db.findDuplicateRecordsDemo.insertOne({"StudentFirstName":"Sam"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a331093b406bd3df60e04") } > db.findDuplicateRecordsDemo.insertOne({"StudentFirstName":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a331593b406bd3df60e05") } > db.findDuplicateRecordsDemo.insertOne({"StudentFirstName":"Mike"}); {   ... Read More

How can I use 'Not Like' operator in MongoDB?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

860 Views

For this, use the $not operator in MongoDB. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.notLikeOperatorDemo.insertOne({"StudentName":"John Doe"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a29c393b406bd3df60dfc") } > db.notLikeOperatorDemo.insertOne({"StudentName":"John Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a29cc93b406bd3df60dfd") } > db.notLikeOperatorDemo.insertOne({"StudentName":"John Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a29df93b406bd3df60dfe") } > db.notLikeOperatorDemo.insertOne({"StudentName":"Carol Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a2a1693b406bd3df60dff") } > db.notLikeOperatorDemo.insertOne({"StudentName":"David Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a2a2693b406bd3df60e00") }Display all documents from ... Read More

Which characters are NOT allowed in MongoDB field names?

Smita Kapse
Updated on 29-Jun-2020 16:00:38

637 Views

Do not use $ symbol or period (.) because these characters are not allowed for MongoDB field names. The field shouldn’t start with $.Here is an example of the allowed characters −> db.charactersAllowedDemo.insertOne({"Employee Name" : "John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7fefbc8d10a061296a3c6d") }Display all documents from a collection with the help of find() method. The query is as follows −> db.charactersAllowedDemo.find().pretty();The following is the output −{    "_id" : ObjectId("5c7fefbc8d10a061296a3c6d"),    "Employee Name" : "John" }

Difference between count() and find().count() in MongoDB?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

301 Views

There is no difference between count() and find().count(). Let us see how both of them works. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.countDemo.insertOne({"UserId":1, "UserName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7f9d278d10a061296a3c5d") } > db.countDemo.insertOne({"UserId":2, "UserName":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7f9d308d10a061296a3c5e") } > db.countDemo.insertOne({"UserId":3, "UserName":"Bob"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7f9d3a8d10a061296a3c5f") } > db.countDemo.insertOne({"UserId":4, "UserName":"Mike"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7f9d428d10a061296a3c60") }Display all documents from a collection with the help ... Read More

Advertisements