- 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
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
Yes, primary key is automatically indexed in MySQL because primary key, index, etc gets stored into B-trees. All engines including InnoDB as well as MyISAM automatically supports the primary key to be indexed. The primary key is implicitly indexed in InnoDB, MyISAM, and other engines. Let us create a table with primary key − mysql> create table DemoIndex -> ( -> Id int not null, -> primary key(Id) -> ); Query OK, 0 rows affected (1.21 sec) In the above table, Id is implicitly indexed.
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
23K+ Views
To get the count of all the records in MySQL tables, we can use TABLE_ROWS with aggregate function SUM. The syntax is as follows. SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'yourDatabaseName'; Apply the above syntax in order to get the count of records for all tables. The query is as follows − mysql> SELECT SUM(TABLE_ROWS) ->FROM INFORMATION_SCHEMA.TABLES ->WHERE TABLE_SCHEMA = 'business'; The following table returns the count of records. +-----------------+ | SUM(TABLE_ROWS) | +-----------------+ | ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
4K+ Views
To count the number of occurrences of a string in a VARCHAR, we can use the logic of subtraction with length. First, we will create a table with the help of create command. mysql> create table StringOccurrenceDemo -> ( -> Cases varchar(100), -> StringValue varchar(500) -> ); Query OK, 0 rows affected (0.56 sec) After executing the above table, we will insert records into the table. The query is as follows − mysql> insert into StringOccurrenceDemo values('First', 'This is MySQL Demo and MySQL is ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
7K+ Views
The active or total connection can be known with the help of threads_connected variable. The variable tells about the number of currently open connections. The query is as follows − mysql> show status where `variable_name` = 'Threads_connected'; Here is the output. +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_connected | 1 | +-------------------+-------+ 1 row in set (0.06 sec) We can check the same with the help of show command. The query is as follows − mysql> show processlist; Here is the output. +----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+ ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
First, we will create a table and insert some values into the table. Let us create a table. mysql> create table RowValueDemo -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (0.69 sec) Insert records using the insert command. We have added duplicate values as well for our example. mysql> insert into RowValueDemo values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into RowValueDemo values('Bob'); Query OK, 1 row affected (0.14 sec) mysql> insert into RowValueDemo values('Carol'); Query OK, 1 row affected ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
773 Views
The char_length() can be used to display the length of a string. Let us see an example to get the length of the string included as a parameter.mysql> select char_length('John');The following is the output.+---------------------+ | char_length('John') | +---------------------+ | 4 | +---------------------+ 1 row in set (0.00 sec)The length() function can be used to display the length of string measured in bytes. In many cases characters and bytes gives the same length.Here is an example of length()mysql> select length('Tim'); The following is ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
474 Views
We can get new record key with the help of LAST_INSERT_ID() function from MySQL. First, we will create a table and for inserting record, we will use LAST_INSERT_ID(). Let us create a table with the help of create command. The query is as follows − mysql> create table LastInsertRecordIdDemo -> ( -> id int auto_increment, -> value varchar(100), -> primary key(id) -> ); Query OK, 0 rows affected (0.52 sec) After creating a table, we will insert records and set it using LAST_INSERT_ID() ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
Firstly, let us get the current datetime with the help of the now() function. mysql> select now(); The following is the output. +---------------------+ | now() | +---------------------+ | 2018-11-01 19:55:56 | +---------------------+ 1 row in set (0.00 sec) Syntax to subtract 10 days with the help of DATE_SUB() select DATE_SUB(now(),interval integer_value day ); Applying the above syntax to subtract 10 days from the current datetime. mysql> select DATE_SUB(now(),interval 10 day); Here is the output. +---------------------------------+ | DATE_SUB(now(),interval 10 day) | +---------------------------------+ | 2018-10-22 19:56:07 | +---------------------------------+ 1 row in set (0.00 sec)
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
8K+ Views
We can know that with the help of the column name ‘UPDATED_TIME’ using information_schema.tables with WHERE clause. Let us first create a table for our example. mysql> create table MyISAMTableDemo -> ( -> id int -> ); Query OK, 0 rows affected (0.56 sec) Inserting some records into table. mysql> insert into MyISAMTableDemo values(1); Query OK, 1 row affected (0.72 sec) mysql> insert into MyISAMTableDemo values(2); Query OK, 1 row affected (0.16 sec) Syntax to know the last updated time. SELECT UPDATE_TIME FROM information_schema.tables WHERE TABLE_SCHEMA = 'yourDatabaseName' AND TABLE_NAME = ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
91K+ Views
To show the schema, we can use the DESC command. This gives the description about the table structure. The following is the syntax. DESCRIBE yourDatabasename.yourTableName; Let us implement the above syntax. mysql> DESCRIBE business.student; The following is the output. +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | id | int(11) | YES | MUL | NULL | | | Name | varchar(100) | YES | MUL | NULL | | +-------+--------------+------+-----+---------+-------+ 2 rows in set (0.05 ... Read More