Found 6702 Articles for Database

What is the query to know about all character sets supported by MySQL?

vanithasree
Updated on 30-Jan-2020 06:23:43

81 Views

With the help of the following query we can see all the character sets supported by MySQL −mysql> Show Character Set; +-----------+-----------------------------+---------------------+--------+ | Charset   | Description                 | Default collation   | Maxlen | +---------- +-----------------------------+---------------------+--------+ | big5      | Big5 Traditional Chinese    | big5_chinese_ci     |      2 | | dec8      | DEC West European           | dec8_swedish_ci     |      1 | | cp850     | DOS West European           | cp850_general_ci   ... Read More

What MySQL returns if sub-query, used to assign new values in the SET clause of UPDATE statement, returns multiple rows?

karthikeya Boyini
Updated on 20-Jun-2020 07:07:57

218 Views

In this case, MySQL will return an error message because we know that if sub-query is used to assign new values in the SET clause of UPDATE statement then it must return exactly one row for each row in the update table that matches the WHERE clause.Examplemysql> insert into info(id, remarks) values(5, 'average'); Query OK, 1 row affected (0.06 sec) mysql> select * from info; +------+-----------+ | id   | remarks   | +------+-----------+ | 1    | Good      | | 2    | Good      | | 3    | Excellent | | 4   ... Read More

In MySQL, what is the difference between SERIAL and AUTO_INCREMENT?

Srinivas Gorla
Updated on 20-Jun-2020 07:09:26

3K+ Views

In MySQL, both SERIAL and AUTO_INCREMENT are used to define a sequence as a default value for a field. But they are technically different from each other.The AUTO_INCREMENT attribute is supported by all numeric data types except for BIT and DECIMAL. There can only be one AUTO_INCREMENT field per table and the sequence generated by an AUTO_INCREMENT field in one table cannot be used in any other table. This attribute requires that a UNIQUE index exists on the field to ensure the sequence has no duplicates. The sequence would start by default from 1 and increment by 1 for every insert.Examplemysql> ... Read More

How can I store the fixed length string as well as variable length string in the same MySQL table?

Jennifer Nicholas
Updated on 20-Jun-2020 07:08:50

438 Views

As we know that CHAR is used to store fixed length string and VARCHAR is used to store variable length strings. Hence we can store a fixed length as well as variable length string in the same table by declaring a column as CHAR and other as VARCHAR.Examplemysql> Create Table Employees(FirstName CHAR(10), LastName VARCHAR(10)); Query OK, 0 rows affected (0.64 sec) mysql> Desc Employees; +-----------+-------------+------+-----+---------+-------+ | Field     | Type        | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | FirstName | char(10)    | YES  |     | NULL    |   ... Read More

What MySQL returns if sub-query, used to assign new values in the SET clause of UPDATE statement, returns no rows?

Kumar Varma
Updated on 20-Jun-2020 07:07:27

92 Views

In this case, MySQL will provide a NULL value to the SET clause. Following example will demonstrate it −Examplemysql> Select * from student; +----+---------+-----------+ | Id | Name    | grade     | +----+---------+-----------+ | 1  | Rahul   | Good      | | 2  | Gaurav  | Good      | | 3  | Raman   | Excellent | | 4  | Harshit | Average   | | 5  | Aarav   | Best      | | 6  | Ram     | average   | +----+---------+-----------+ 6 rows in set (0.00 sec) ... Read More

How can we search a record from MySQL table having a date as a value in it?

Nitya Raut
Updated on 30-Jan-2020 06:29:55

85 Views

It can be understood with the help of following example in which we are using the following data from the table named ‘detail_bday’ −mysql> Select * from detail_bday; +----+---------+------------+ | Sr | Name    | Birth_Date | +----+---------+------------+ | 1  | Saurabh | 1990-05-12 | | 2  | Raman   | 1993-06-11 | | 3  | Gaurav  | 1984-01-17 | | 4  | Rahul   | 1993-06-11 | +----+---------+------------+ 4 rows in set (0.00 sec)Now, in the following two ways we can search records using the date −mysql> Select * from detail_bday Where Birth_Date = '1993-06-11'; +----+-------+------------+ | Sr | ... Read More

What is the use of ALLOW_INVALID_DATES SQL mode?

Abhinanda Shri
Updated on 20-Jun-2020 07:06:28

2K+ Views

As the name suggests, enabling ALLOW_INVALID_DATES SQL mode will allow us to store invalid dates in the table. The example is given below to understand it −Examplemysql> SET sql_mode = ALLOW_INVALID_DATES; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> Insert Into detail_bday(Name, Birth_Date) values('Sonia', '1993-11-31'); Query OK, 1 row affected (0.09 sec) mysql> Insert Into detail_bday(Name, Birth_Date) values('Ram', '0000-00-00'); Query OK, 1 row affected (0.10 sec) mysql> Select * from detail_bday; +----+---------+------------+ | Sr | Name    | Birth_Date | +----+---------+------------+ | 1  | Saurabh | 1990-05-12 | | 2  | Raman   | 1993-06-11 ... Read More

How can we update the values in one MySQL table by using the values of another MySQL table?

Manikanth Mani
Updated on 20-Jun-2020 07:06:58

343 Views

For updating the values in one MySQL table by using the values from another MySQL table, we need to use sub-query as an expression in the SET clause of the UPDATE statement.ExampleIn this example, we have two table ‘student’ and ‘info’. We will update the value of column ‘grade’ of table ‘student’ by using the values from column ‘remarks’ of ‘info’ table.mysql> select * from student; +----+---------+-------+ | Id | Name    | grade | +----+---------+-------+ | 1  | Rahul   | NULL  | | 2  | Gaurav  | NULL  | | 3  | Raman   | NULL  | | ... Read More

How MySQL evaluates if I store date along with time value in a column having DATE data type?

Ankitha Reddy
Updated on 20-Jun-2020 07:04:43

66 Views

As we know that 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. But still, if we store date along with time value in a column having DATE data type then MySQL will show a warning and store only the date value in that column. Following example will exhibit it −Examplemysql> Create table date_time_test(date DATE); Query OK, 0 rows affected (0.44 sec) mysql> Insert into date_time_test(date) values(‘2017-09-09 09:34:21’); Query OK, 1 row affected, 1 warning (0.03 sec) mysql> Select * from date_time_test; +------------+ | ... Read More

How can we use existing values of the rows to provide new values in the SET clause of UPDATE statement?

Swarali Sree
Updated on 20-Jun-2020 07:05:10

109 Views

Existing values of the row can be used to provide new values in the SET clause if that row matches the WHERE clause in an UPDATE statement. Following is the example to demonstrate it.ExampleSuppose we have a table named ‘tender’ as follows −mysql> Select * from tender; +-----------+---------+------+ | tender_id | company | rate | +-----------+---------+------+ | 200       | ABC     | 1000 | | 300       | ABD     | 6000 | | 301       | ABE     | 7000 | | 302       | ABF   ... Read More

Advertisements