![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 4219 Articles for MySQLi
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
69 Views
We can compute the date as follows −mysql> SET @year=2017, @week=15, @day=4; Query OK, 0 rows affected (0.00 sec)The above query will pass the value’2017’ ,’15’, ‘4’ in ‘year’, ’week’ and ‘day’ variables respectively. Then after applying the formula in the query below, we can get the date.mysql> SELECT Str_To_Date( Concat(@year,'-',@week,'-',If(@day=7,0,@day) ), '%Y-%U-%w' ) AS Date; +--------------+ | Date | +--------------+ | 2017-04-13 | +--------------+ 1 row in set (0.00 sec)
![Vikyath Ram](https://www.tutorialspoint.com/assets/profiles/13780/profile/60_74413-1512648006.jpg)
59 Views
As we know that MySQL supports foreign key for referential integrity but it does not support CHECK constraint. But we can emulate them by using triggers. It can be illustrated with the help of an example given below −ExampleSuppose we have a table named ‘car1’ which can have the fix syntax registration number like two letters, a dash, three digits, a dash, two letters as follows −mysql> Create table car1 (number char(9)); Query OK, 0 rows affected (0.32 sec) mysql> Insert into car1 values('AB-235-YZ'); Query OK, 1 row affected (0.10 sec)The above value is a valid one but what ... Read More
![usharani](https://www.tutorialspoint.com/assets/profiles/13564/profile/60_32161-1512638316.jpg)
238 Views
We can calculate age in years from birthdate as follows −mysql> SET @dob = '1984-01-17'; Query OK, 0 rows affected (0.00 sec)This above query will pass the value’1984-01-17’ in the ‘dob’ variable. Then after applying the formula in the query below, we can get the age in years.mysql> Select Date_format( From_Days( To_Days(Curdate()) - To_Days(@dob) ), '%Y' ) + 0 AS ‘Age in years; +---------------+ | ‘Age in years’| +---------------+ | 33 | +---------------+ 1 row in set (0.00 sec)
![Rishi Rathor](https://www.tutorialspoint.com/assets/profiles/13563/profile/60_89283-1512714754.jpg)
237 Views
After enabling the SQL MODE to ALLOW_INVALID_DATES, MySQL will also be able to store invalid dates in the table. The example is given below to understand it −mysql> Insert into order1234(ProductName, Quantity, Orderdate) values('B',500,'2015-11-31'); Query OK, 1 row affected (0.06 sec) mysql> Select * from order1234; +-------------+----------+--------------+ | ProductName | Quantity | OrderDate | +-------------+----------+--------------+ | A | 500 | 0000-00-00 | | B | 500 | 2015-11-31 | +-------------+----------+--------------+ 2 rows in set (0.00 sec)We can see MySQL also inserts the invalid date in a table.
![varun](https://www.tutorialspoint.com/assets/profiles/13559/profile/60_29674-1512637943.jpg)
318 Views
The response of MySQL on encountering out-of-range or invalid date will depend upon SQL MODE. If we have enabled ALLOW_INVALID_DATES mode then MySQL will convert the out of range values into all zeros (i.e. ‘0000:00:00 00:00:00’) and also stores the same in the table without producing any error or warning.For example, we can change SQL MODE as follows and then insert the out-of-range −mysql> set sql_mode = 'ALLOW_INVALID_DATES'; Query OK, 0 rows affected (0.00 sec) mysql> Insert into order1234(productname, quantity, orderdate) values('A', 500, '999-05-100'); Query OK, 1 row affected, 1 warning (0.13 sec) mysql> Select * from order1234; ... Read More
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
145 Views
As we know that MySQL supports foreign key for referential integrity but it does not support CHECK constraint. But we can emulate them by using triggers. It can be illustrated with the help of an example given below −ExampleSuppose we have a table named ‘car’ which can have the fix syntax registration number like two letters, a dash, three digits, a dash, two letters as follows −mysql> Create table car (number char(9)); Query OK, 0 rows affected (0.32 sec) mysql> Insert into car values('AB-235-YZ'); Query OK, 1 row affected (0.10 sec)The above value is a valid one but what ... Read More
![Monica Mona](https://www.tutorialspoint.com/assets/profiles/13520/profile/60_87298-1512650151.jpg)
4K+ Views
MySQL allows us to add a FOREIGN KEY constraint on multiple columns in a table. The condition is that each Foreign Key in the child table must refer to the different parent table.ExampleSuppose we have a table ‘customer2’ which have a Primary Key constraint on the field ‘cust_unq_id’ as follows −mysql> describe customer2; +-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | cust_id | int(11) | YES | | NULL | | | First_name | varchar(20) | ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
10K+ Views
Both the data types store data in “YYYY-MM-DD HH:MM:SS” format and include date as well as time. In spite of these similarities they are having the following differences −Range − Datetime data type supports a date along with time in the range between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. But timestamp data type supports a date along with time in the range between ‘1970-01-01 00:00:01’ to ‘2038-01-19 08:44:07’.Size − Datetime requires 5 bytes along with 3 additional bytes for fractional seconds’ data storing. On the other hand, timestamp datatype requires 4 bytes along with 3 additional bytes for fractional seconds’ data ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
114 Views
AUTO_INCREMENT means that the column will get the value automatically. To illustrate it we have created a table ‘employees’ as follows − mysql> Show Create Table employees\G *************************** 1. row *************************** Table: employees Create Table: CREATE TABLE `employees` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(35) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) From the above result set, we can see that column id is given the auto-increment option. Now, when we will insert the value in Name ... Read More
![Prabhas](https://www.tutorialspoint.com/assets/profiles/13554/profile/60_90506-1512543588.jpg)
810 Views
Suppose we have a table ‘Order123’ having ProductName, Quantity and OrderDate columns as follows −mysql> Select * from Order123; +-------------+----------+------------+ | ProductName | Quantity | OrderDate | +-------------+----------+------------+ | A | 100 | 2017-05-25 | | B | 105 | 2017-05-25 | | C | 55 | 2017-05-25 | | D | 250 | 2017-05-26 | | E | 500 | 2017-05-26 | | ... Read More