- 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
1K+ Views
To get the last access time, try the following syntax −SELECT update_time FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'yourDatabaseName' AND table_name = 'yourTableName'The above syntax gives the last access information about MyISAM engine type.Here, our database is ‘business’ and we will be using the table with the name ‘twoprimarykeytabledemo'.To get last access time of MySQL database, use the following query.Case 1 − The query is as follows −mysql> SELECT update_time -> FROM INFORMATION_SCHEMA.TABLES -> WHERE table_schema = 'business' -> AND table_name = 'twoprimarykeytabledemo';The output is as follows −+---------------------+ | UPDATE_TIME ... Read More
114 Views
The smallest datatype for one bit can be bit(1). The syntax is as follows −yourColumnName bit(1)To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table bitDemo -> ( -> isValid bit(1) -> ); Query OK, 0 rows affected (0.49 sec)Now you can check all the details of table with the help of SHOW CREATE command. The query is as follows −mysql> show create table bitDemo;Here is the output −+---------+-----------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table ... Read More
51 Views
MongoDB order the docs in one collection with the help of a $natural operator. It stores the document as it is when we get from find(). The default order is $natural. Let us now see the syntax −db.yourCollectionName.find().sort({ "$natural": 1 });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.orderDocsDemo.insertOne({"UserScore":87}); { "acknowledged" : true, "insertedId" : ObjectId("5c9531a316f542d757e2b44b") } > db.orderDocsDemo.insertOne({"UserScore":98}); { "acknowledged" : true, "insertedId" : ObjectId("5c9531a816f542d757e2b44c") } > db.orderDocsDemo.insertOne({"UserScore":99}); { "acknowledged" : true, "insertedId" : ObjectId("5c9531b216f542d757e2b44d") ... Read More
204 Views
The localhost means you can access from same machine while from % the remote host access is possible. The syntax is as follows to change the user password.SET PASSWORD FOR 'yourUserName'@'localhost' ='yourPassword';First check the user and host from MySQL.user table. The query is as follows −mysql> select user, host from MySQL.user;Here is the output −+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Manish | % ... Read More
652 Views
First of all, you need to get your collection with the help of getCollectionNames().The database name is “test”. Let us loop through all MongoDB collections and execute the query. The query is as follows −> db.getCollectionNames().forEach(function(collectioNameDemo) ... { ... var nextDemo = db[(collectioNameDemo) ].find().sort({_id:-1}).limit(1); ... if (nextDemo.hasNext()) ... { ... printjson(nextDemo.next()._id.getTimestamp()); ... } ... });The following is the output −ISODate("2019-02-21T18:52:43Z") ISODate("2019-03-19T17:49:00Z") ISODate("2019-03-06T15:40:12Z") ISODate("2019-03-15T16:31:50Z") ISODate("2019-02-21T15:40:52Z") ISODate("2019-03-06T06:14:37Z") ISODate("2019-02-21T19:29:15Z") ISODate("2019-03-15T13:35:33Z") ISODate("2019-03-14T21:13:58Z") ISODate("2019-03-18T22:02:54Z") ISODate("2019-03-22T18:01:45Z") ISODate("2019-03-06T16:21:14Z") ISODate("2019-02-20T15:04:32Z") ISODate("2019-03-06T07:45:42Z") ISODate("2019-03-19T12:33:17Z") ISODate("2019-03-20T21:39:21Z") ISODate("2019-03-15T16:44:26Z") ISODate("2019-03-22T06:20:45Z") ISODate("2019-02-21T16:40:55Z") ISODate("2019-02-21T12:45:20Z") ISODate("2019-03-06T16:05:48Z") ISODate("2019-03-06T16:00:08Z") ISODate("2019-02-28T12:43:56Z") ISODate("2019-03-20T22:11:41Z") ISODate("2019-03-06T05:56:45Z") ISODate("2019-03-06T07:34:12Z") ISODate("2019-03-14T21:00:16Z") ISODate("2019-02-28T10:33:39Z") ISODate("2019-03-06T05:11:10Z") ISODate("2019-02-28T09:44:28Z") ISODate("2019-03-06T10:13:22Z") ISODate("2019-03-17T21:35:26Z")Read More
212 Views
To select timestamp as date string in MySQL, the syntax is as follows −select FROM_UNIXTIME(yourColumnName, '%Y-%m-%d %H:%i:%s') from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table select_timestampDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ArrivalDateTime int -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into select_timestampDemo(ArrivalDateTime) values(1546499730); Query OK, 1 row affected (0.18 sec) mysql> insert into select_timestampDemo(ArrivalDateTime) values(1546210820); Query OK, 1 ... Read More
722 Views
To understand the query on list field, and/or, you can create a collection with documents.The query to create a collection with a document is as follows −> db.andOrDemo.insertOne({"StudentName":"Larry", "StudentScore":[33, 40, 50, 60, 70]}); { "acknowledged" : true, "insertedId" : ObjectId("5c9522d316f542d757e2b444") } > db.andOrDemo.insertOne({"StudentName":"Larry", "StudentScore":[87, 67, 79, 98, 90]}); { "acknowledged" : true, "insertedId" : ObjectId("5c95230916f542d757e2b445") }Display all documents from a collection with the help of find() method. The query is as follows −> db.andOrDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c9522d316f542d757e2b444"), "StudentName" : "Larry", "StudentScore" : [ 33, ... Read More
66 Views
To implement AND condition, the syntax is as follows −select *from yourTableName where yourColumnName1 = yourValue1 AND yourColumnName2 = yourValue2;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table MySQLANDConditionDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into MySQLANDConditionDemo(Name, Age) values('Larry', 23); Query OK, 1 row affected (0.11 sec) mysql> ... Read More
339 Views
You can easily insert a row into a table that has only a single auto increment column. The syntax is as follows −insert into yourTableName set yourColumnName =NULL;You can use the below syntax −insert into yourTableName values(NULL);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table singleAutoIncrementColumnDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into singleAutoIncrementColumnDemo set UserId ... Read More
128 Views
You can use GLOBAL variable as shown below −SET global innodb_stats_on_metadata =0;After including the above syntax, the INFORMATION_SCHEMA.key_column_usage will take less time and that would improve the performance.The query is as follows −mysql> set global innodb_stats_on_metadata =0; Query OK, 0 rows affected (0.00 sec) mysql> SELECT REFERENCED_TABLE_NAME,TABLE_NAME,COLUMN_NAME,CONSTRAINT_SCHEMA -> FROM INFORMATION_SCHEMA.key_column_usage;The following is the output −It returns 674 rows in 0.28 seconds.