- 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)
252 Views
To find/replace string in fields, the syntax is as follows −update yourTableName set yourColumnName =REPLACE(yourColumnName, yourOldValue, yourNewValue);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table FindReplaceDemo -> ( -> FileId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> FileDirectory text -> ); Query OK, 0 rows affected (0.92 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into FindReplaceDemo(FileDirectory) values('C://User//MySQL'); Query OK, 1 row affected (0.19 sec) mysql> insert into FindReplaceDemo(FileDirectory) values('D://WebsiteImage//image1.jpg'); Query OK, ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
483 Views
Adding an index on column of int type is a good choice to run your query faster whenever your table has lots of records.If your table has less records then it is not a good choice to use index on column of int type.To understand the concept, let us create a table. The query to create a table is as follows −mysql> create table indexOnIntColumnDemo -> ( -> UserId int, -> UserName varchar(20), -> UserAge int, -> INDEX(UserId) -> ); Query OK, 0 rows affected (0.85 sec)Now check the description of table −mysql> desc ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
3K+ Views
To convert ObjectId to string, use 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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
124 Views
You can use DROP INDEX for this. The syntax is as follows −alter table yourTablename drop index yourUniqueName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removeUniquenessConstraint -> ( -> Id int, -> Name varchar(100), -> Age int, -> isGreaterThan18 bool, -> UNIQUE(Id, isGreaterThan18) -> ); Query OK, 0 rows affected (0.69 sec)Now check the details of table with the help of SHOW CREATE command. The query is as follows −mysql> show create table removeUniquenessConstraint;Here is the output −+----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
252 Views
Let us first create a demo table −mysql> create table BulkChangeDemo -> ( -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CustomerName varchar(20), -> isEducated boolean -> ); Query OK, 0 rows affected (1.47 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into BulkChangeDemo(CustomerName, isEducated) values('Larry', true); Query OK, 1 row affected (0.09 sec) mysql> insert into BulkChangeDemo(CustomerName, isEducated) values('John', false); Query OK, 1 row affected (0.16 sec) mysql> insert into BulkChangeDemo(CustomerName, isEducated) values('Carol', false); Query OK, 1 row affected (0.25 sec) mysql> insert into BulkChangeDemo(CustomerName, ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
443 Views
To hide _id from aggregation, use the below syntax −db.yourCollectionName.aggregate( {$project : { _id : 0 , yourIncludeFieldName:1, yourIncludeFieldName: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.hideidDemo.insertOne({"UserName":"Larry", "UserAge":23, "UserCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92b02336de59bd9de06392") } > db.hideidDemo.insertOne({"UserName":"Chris", "UserAge":21, "UserCountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92b03036de59bd9de06393") } > db.hideidDemo.insertOne({"UserName":"Robert", "UserAge":26, "UserCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5c92b04036de59bd9de06394") }Display all documents ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
You can use ORDER BY RIGHT() to ORDER BY last 2 character string.The syntax is as followsselect yourColumnName from yourTableName ORDER BY RIGHT(yourColumnName , 2);To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table OrderByLast2CharactersDemo -> ( -> CustomerId varchar(20), -> CustomerName varchar(20) -> ); 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 OrderByLast2CharactersDemo(CustomerId, CustomerName) values('John-98', 'John'); Query OK, 1 row affected (0.20 sec) mysql> insert into OrderByLast2CharactersDemo(CustomerId, CustomerName) values('Carol-91', ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
660 Views
You can verify SET FOREIGN KEY CHECKS is set to = 1 or not with the help of variable@@foreign_key_checks;The syntax is as follows −select @@foreign_key_checks;You can use SHOW VARIABLES command. The syntax is as follows −show variables like 'foreign%';Now you can implement both the syntaxes.Case 1 − Using variable @@foreign_key_checks.The query is as follows −mysql> SELECT @@foreign_key_checks; Here is the output −+----------------------+ | @@foreign_key_checks | +----------------------+ | 1 | +----------------------+ 1 row in set (0.00 sec)Case 2 − Using SHOW commandThe ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
54 Views
Yes, to query for a field in an object in the array with MongoDB, use the following syntax −db.yourCollectionName.find({"yourOuterFieldName": { $elemMatch: { "yourInnerFieldName": "yourValue" } } } ).pretty();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.objectInAnArrayDemo.insertOne({ "StudentDetails": [{ "StudentName": "John", "StudentMessage": "Hi"}, {"StudentName": "Larry", "StudentMessage": "Hello"}]}) { "acknowledged" : true, "insertedId" : ObjectId("5c92635d36de59bd9de06381") } > db.objectInAnArrayDemo.insertOne({ "StudentDetails": [{ "StudentName": "Carol", "StudentMessage": "Hello"}, {"StudentName": "David", "StudentMessage": "Good Morning"}]}) { "acknowledged" : true, "insertedId" : ObjectId("5c92637936de59bd9de06382") }Display all documents ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
95 Views
Ampersands work in Oracle. To work it in MySQL, use @ as shown in the following syntax −SET @yourVariableName1 = yourValue, @yourVariableName2 = yourValue, @yourVariableName3 =yourValue, .........N; insert into yourTableName values(@yourVariableName1, @yourVariableName2, @yourVariableName3, ........N);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Student_Information -> ( -> StudentId int, -> StudentName varchar(100), -> StudentAge int, -> StudentMarks int, -> StudentCountryName varchar(10) -> ); Query OK, 0 rows affected (0.75 sec)Here is the query with values prepended by @. Insert some records ... Read More