Found 4220 Articles for MySQLi

How to search a record by date in MySQL table?

Prabhas
Updated on 28-Jan-2020 09:22:39

758 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

Why we cannot use MySQL DATE data type along with time value?

seetha
Updated on 28-Jan-2020 09:23:21

68 Views

The default format for MySQL DATE data type is “YYYY-MM-DD” and in this format, there is no possibility to store the time value. Hence, we can say that we cannot use DATE data type along with time value.As we can see in the following example MySQL returns only date value even on using time along with the date.mysql> select DATE("2017-09-25 09:34:21"); +-----------------------------------+ | DATE("2017-09-25 09:34:21")       | +-----------------------------------+ | 2017-09-25                        | +-----------------------------------+ 1 row in set (0.04 sec)However, in DATETIME and TIMESTAMP date data types we can use the time to date.

What is the use of DEFAULT constraint? How can it be applied to a column while creating a table?

Ankith Reddy
Updated on 19-Jun-2020 13:38:37

57 Views

DEFAULT constraint is used set a default value for a column in MySQL table. If it is applied on a column then it will take the default value of not giving any value for that column. Its syntax would be as follows −SyntaxDEFAULT default_valueHere, default_value is the default value set for the column.ExampleThe query below will create a table named workers where we assign the column id a DEFAULT value 1000.mysql> Create table workers(Name Varchar(25), Id INT NOT NULL DEFAULT 1000); Query OK, 0 rows affected (0.47 sec) mysql> Insert into workers(Name, Id) values('Ram', 101); Query OK, 1 row ... Read More

How many DATE data types are supported by MySQL?

Daniol Thomas
Updated on 19-Jun-2020 13:32:12

86 Views

MySQL supports following 5 types of DATE data type −DATE - A date is in the range between 1000-01-01 and 9999-12-31. “YYYY-MM-DD” is the default DATE format. For example, January 17th, 1984 would be stored as 1984-01-17.DATETIME − This 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. “YYYY-MM-DD HH:MM:SS” is the default DATETIME format. For example, 2:20 in the afternoon on January 17th, 1984 would be stored as 1984-01-17 14:20:00.TIMESTAMP − A 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’. It ... Read More

How can I see the constraints which are applied to a table stored in another database then I am currently using?

Sai Nath
Updated on 19-Jun-2020 13:32:38

44 Views

MySQL SHOW CREATE TABLE statement will provide us the constraints applied to a particular table along with some other details about that table stored in another database then I am currently using. Its syntax would be as follows −SyntaxSHOW CREATE TABLE db_name.table_name;Here table_name is the name of the table on which we want to see the constraints.Db_name is the name of the database name in which table is stored.ExampleIn this example we are getting the detail of the table named ‘arena’ stored in MySQL database −mysql> Show Create table mysql.arena\G *************************** 1. row *************************** Table: arena Create Table: CREATE TABLE ... Read More

How can I see the constraints which are applied to a table stored in the database I am currently using?

Samual Sam
Updated on 19-Jun-2020 13:30:26

50 Views

MySQL SHOW CREATE TABLE statement will provide us the constraints applied to a particular table along with some other details about that table. Its syntax would be as follows −SyntaxSHOW CREATE TABLE table_name;Here table_name is the name of the table on which we want to see the constraints.ExampleIn this example we are getting the detail of the table named ‘employees’ −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 ... Read More

In MySQL, when VARCHAR data type will use 1-byte and when 2-bytes prefix length along with data?length along with data?

vanithasree
Updated on 28-Jan-2020 09:29:04

76 Views

As we know that in MySQL, VARCHAR values are stored as a 1-byte or 2-byte length prefix plus data. This length prefix points out the number of bytes in the value of data. The data value itself will decide that when VARCHAR data type will use 1-byte and when 2-byte prefix length.A column uses 1-byte length if values require no more than 255 bytes.A column uses 2-byte length if values may require more than 255 bytes.

What is the difference between MySQL PRIMARY KEY and UNIQUE constraint?

Arushi
Updated on 19-Jun-2020 13:31:07

519 Views

The following table will provide us the differences between PRIMARY KEY and UNIQUE constraint −PRIMARY KEYUNIQUE Constraint1. Only one Primary key can be created on a table.1. More than one UNIQUE Constraints can be added to a table.2. Primary key creates clustered index by default.2. UNIQUE Constraint creates a non-clustered index by default.3. We cannot insert null values in the column which is defined as PRIMARY KEY.3. We can insert null values in the column having a UNIQUE constraint.

What should one use CHAR data type or VARCHAR data type in MySQL?

Krantik Chavan
Updated on 19-Jun-2020 13:29:53

249 Views

Actually, both of these data types in MySQL store strings and can be set with a maximum length. The use of these data types purely depends on the need. Followings are some points which will make us clear that when one should CHAR and when VARCHAR −Suppose if we have fixed size of data, such as flags of “Y” and “N” then it is better to use CHAR rather than VARCHAR. It is because 1 byte of length prefix also used with VARCHAR. In other words, for the above kind of data, CHAR will store the only 1byte which is ... Read More

What is the difference between CHAR and VARCHAR in MySQL?

radhakrishna
Updated on 19-Jun-2020 13:27:55

4K+ Views

CHAR and VARCHAR are both ASCII character data types and almost same but they are different at the stage of storing and retrieving the data from the database. Following are some important differences between CHAR and VARCHAR in MySQL −CHAR Data TypeVARCHAR Data TypeIts full name is CHARACTERIts full name is VARIABLE CHARACTERIt stores values in fixed lengths and are padded with space characters to match the specified lengthVARCHAR stores values in variable length along with 1-byte or 2-byte length prefix and are not padded with any charactersIt can hold a maximum of 255 characters.It can hold a maximum of 65, ... Read More

Advertisements