- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 6702 Articles for Database
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
The DECLARE syntax must between BEGIN and END. The syntax is as follows −BEGIN DECLARE yourVariableName1 dataType, DECLARE yourVariableName2 dataType, . . . . ENDHere is the query to avoid DECLARE syntax error in MySQL −mysql> DELIMITER // mysql> create procedure declare_Demo() -> BEGIN -> DECLARE Name varchar(100); -> SET Name: ='John'; -> SELECT Name; -> END -> // Query OK, 0 rows affected (0.17 sec) mysql> DELIMITER ;Call the stored procedure with the help of CALL command. The syntax is as follows −CALL yourStoredProcedureName();The query is as follows −mysql> call declare_Demo();The following is ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
237 Views
Yes, it is possible to cast in a MongoDB query −db.yourCollectionName.find("this.yourFieldName >yourValue);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.castingDemo.insertOne({"Amount":"200"}); { "acknowledged" : true, "insertedId" : ObjectId("5c947e874cf1f7a64fa4df42") } > db.castingDemo.insertOne({"Amount":"100"}); { "acknowledged" : true, "insertedId" : ObjectId("5c947e8e4cf1f7a64fa4df43") } > db.castingDemo.insertOne({"Amount":"110"}); { "acknowledged" : true, "insertedId" : ObjectId("5c947e944cf1f7a64fa4df44") } > db.castingDemo.insertOne({"Amount":"95"}); { "acknowledged" : true, "insertedId" : ObjectId("5c947e9d4cf1f7a64fa4df45") } > db.castingDemo.insertOne({"Amount":"85"}); { "acknowledged" : true, "insertedId" : ObjectId("5c947ea44cf1f7a64fa4df46") } > db.castingDemo.insertOne({"Amount":"75"}); { "acknowledged" ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
183 Views
You can use $cmp operator 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.matchBetweenFieldsDemo.insertOne({"FirstValue":40, "SecondValue":70}); { "acknowledged" : true, "insertedId" : ObjectId("5c92c9625259fcd19549980d") } > db.matchBetweenFieldsDemo.insertOne({"FirstValue":20, "SecondValue":5}); { "acknowledged" : true, "insertedId" : ObjectId("5c92c96b5259fcd19549980e") }Display all documents from a collection with the help of find() method. The query is as follows −> db.matchBetweenFieldsDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c92c9625259fcd19549980d"), "FirstValue" : 40, "SecondValue" : 70 } { "_id" : ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
346 Views
To check replication type, you can use SHOW GLOBAL VARIABLES command. The syntax is as follows −SHOW GLOBAL VARIABLES LIKE 'binlog_format';The above syntax returns either ROW, MIXED or STATEMENT. The default resultant is ROW.Now you can implement the above syntax to check replication type. The query is as follows −mysql> SHOW GLOBAL VARIABLES LIKE 'binlog_format';Here is the output −+---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | +---------------+-------+ 1 row in set (0.10 sec)Here is the query to switch from ROW to STATEMENT −mysql> SET GLOBAL binlog_format = 'STATEMENT'; Query OK, 0 rows affected (0.04 ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
182 Views
The equivalent syntax is as follows.db.yourCollectionName.find({}, {_id: 1, "column1": 1, "column2": 1}).pretty();To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.equivalentForSelectColumn1Column2Demo.insertOne({"CustomerName":"John", "CustomerAge":26, "CustomerCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92c6205259fcd19549980a") } > db.equivalentForSelectColumn1Column2Demo.insertOne({"CustomerName":"David", "CustomerAge":22, "CustomerCountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92c6305259fcd19549980b") } > db.equivalentForSelectColumn1Column2Demo.insertOne({"CustomerName":"Chris", "CustomerAge":24, "CustomerCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92c6415259fcd19549980c") }Display all documents from a collection with the help of find() method. The query is as follows −> db.equivalentForSelectColumn1Column2Demo.find().pretty();The following is the output ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
197 Views
To select accumulated column, let us first create a demo table. The query to create a table is as follows −mysql> create table accumulatedDemo -> ( -> Value int -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into accumulatedDemo values(10); Query OK, 1 row affected (0.21 sec) mysql> insert into accumulatedDemo values(15); Query OK, 1 row affected (0.09 sec) mysql> insert into accumulatedDemo values(20); Query OK, 1 row affected (0.13 sec) mysql> insert into accumulatedDemo values(25); Query OK, 1 row affected ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
1K+ Views
You can use dot(.) notation to query by subfield. Let us create a collection with a document. The query to create a collection with a document is as follows −> db.queryBySubFieldDemo.insertOne( ... { ... "StudentPersonalDetails" : {"StudentName" : "John", "StudentHobby" :"Photography"}, ... "StudentScores" : {"MathScore" : 56} ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5c92c2995259fcd195499808") } > db.queryBySubFieldDemo.insertOne( ... { ... "StudentPersonalDetails" : {"StudentName" : "Chris", "StudentHobby" :"Reading"}, ... "StudentScores" : {"MathScore" : 97} ... } ... ); { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
278 Views
The SELECT INTO equivalent is CREATE TABLE AS SELECT statement. The syntax is as follows −CREATE TABLE yourNewTableName AS SELECT *FROM yourTableName;To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table selectIntoEquivalentDemo -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into selectIntoEquivalentDemo(ClientName, ClientAge) values('Larry', 34); Query OK, 1 row affected (0.13 ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
6K+ Views
To check whether a field exists or not in MongoDB, you can use the $exists operator.To understand the above concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.checkFieldExistsOrNotDemo.insertOne({"StudentName":"Larry"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92ba4136de59bd9de063a1") } > db.checkFieldExistsOrNotDemo.insertOne({"StudentName":"John", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c92ba4e36de59bd9de063a2") } > db.checkFieldExistsOrNotDemo.insertOne({"StudentName":"Chris", "StudentAge":24, "StudentCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92ba6536de59bd9de063a3") } > db.checkFieldExistsOrNotDemo.insertOne({"StudentName":"Robert", "StudentAge":21, "StudentCountryName":"UK", "StudentHobby":["Teaching", "Photography"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c92ba9d36de59bd9de063a4") }Display all documents from a collection ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
1K+ Views
Let us see an example to understand the $toString in MongoDB. To understand the above concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.objectidToStringDemo.insertOne({"UserName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92b80036de59bd9de0639d") } > db.objectidToStringDemo.insertOne({"UserName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92b80436de59bd9de0639e") } > db.objectidToStringDemo.insertOne({"UserName":"Larry"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92b80936de59bd9de0639f") } > db.objectidToStringDemo.insertOne({"UserName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92b81836de59bd9de063a0") }Display all documents from a collection with the help of find() method. The query is as follows ... Read More