- 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 4378 Articles for MySQL
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
85 Views
An error will arise and nothing will get inserted in the table Let us see an example and create a table −mysql> create table DemoTable1585 -> ( -> StudentId int, -> StudentMarks int, -> UNIQUE(StudentId) -> ); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1585 values(1,87),(2,98),(3,91),(3,48); ERROR 1062 (23000): Duplicate entry '3' for key 'StudentId'Display all records from the table using select statement −mysql> select * from DemoTable1585;This will produce the following output. Nothing gets inserted:Empty set (0.00 sec)
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
866 Views
Let us first create a table −mysql> create table DemoTable1584 -> ( -> DueDate datetime -> ); Query OK, 0 rows affected (1.79 sec)Here is the query to insert DATE in a MySQL −mysql> create trigger insertDate before insert on DemoTable1584 -> for each row set new.DueDate=curdate(); Query OK, 0 rows affected (0.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1584 values(); Query OK, 1 row affected (0.66 sec) mysql> insert into DemoTable1584 values(); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1584 values(); Query OK, 1 row affected ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
193 Views
To delete partial data, use UPDATE command along with REPLACE(). Let us first create a table −mysql> create table DemoTable1583 -> ( -> GameDetails text -> ); Query OK, 0 rows affected (1.38 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1583 values('=Candy, 2000'); Query OK, 1 row affected (0.53 sec) mysql> insert into DemoTable1583 values('=Lucky29, 10000'); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement −mysql> select * from DemoTable1583;This will produce the following output −+------------------------------------------------------------+ | GameDetails ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
110 Views
Let’s say the current date is −'2019-10-20We will first see an example and create a table −mysql> create table DemoTable1582 -> ( -> PostedDate datetime -> ); Query OK, 0 rows affected (13.36 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1582 values('2019-01-21 12:34:40'); Query OK, 1 row affected (1.06 sec) mysql> insert into DemoTable1582 values('2019-10-15 11:00:00'); Query OK, 1 row affected (0.87 sec) mysql> insert into DemoTable1582 values('2019-10-25 1:10:00'); Query OK, 1 row affected (1.14 sec)Display all records from the table using select statement −mysql> select * from DemoTable1582;This will produce the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
348 Views
To ensure that MySQL rows are unique, you need to use UNIQUE constraint. Let us first create a table −mysql> create table DemoTable1580 -> ( -> id int, -> Name varchar(20), -> Age int -> ); Query OK, 0 rows affected (0.73 sec)Here is the query to create unique constraints to ensure MySQL rows are unique −mysql> alter table DemoTable1580 add unique index(id, Name, Age); Query OK, 0 rows affected (0.45 sec) Records: 0 Duplicates: 0 Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable1580 values(101, 'Chris', 21); Query OK, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
560 Views
To select the last three rows in ascending order, use ORDER BY DESC LIMIT as in the below syntax −select * from (select * from yourTableName order by yourColumnName desc limit 3) anyAliasName order by yourColumnName ;Let us first create a table −mysql> create table DemoTable1579 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1579(Name) values('Robert'); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable1579(Name) values('Bob'); Query OK, 1 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
294 Views
Here is the query to create first table.mysql> create table DemoTable1 -> ( -> StudentName varchar(20), -> StudentMarks int -> ); Query OK, 0 rows affected (0.67 sec)To understand the above concept, let us create second table.mysql> create table DemoTable2 -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2 values('Chris'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable2;This will produce the following output −+-------+ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
139 Views
The easiest way to get number of rows, use aggregate function COUNT(*). Let us first create a table −mysql> create table DemoTable1575 -> ( -> FirstName varchar(20) -> ); Query OK, 0 rows affected (1.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1575 values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1575 values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1575 values('Robert'); Query OK, 1 row affected (0.15 sec)Display all records from the table ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
788 Views
Let us first create a table −mysql> create table DemoTable1574 -> ( -> StudentCode varchar(20) -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1574 values('111_Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1574 values('______'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1574 values('David_12345'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1574 values('______'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable1574;This will produce the following ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
260 Views
To retrieve table names from a database in MySQL, the syntax is as follows −show tables from yourDatabaseName;Let us implement the above query in order to retrieve table names from a database in MySQL −mysql> show tables from hb_student_tracker;This will produce the following output −+------------------------------+ | Tables_in_hb_student_tracker | +------------------------------+ | demotable192 | | demotable193 | | demotable194 | | demotable195 | | demotable196 ... Read More