Found 6705 Articles for Database

How can we check the default character sets of all the MySQL databases we have on the server?

Nikitha N
Updated on 30-Jan-2020 06:21:34

118 Views

The query below will return the name of the database along with the default character set −mysql> SELECT SCHEMA_NAME 'Database', default_character_set_name 'charset' FROM information_schema.SCHEMATA; +--------------------+---------+ | Database           | Charset | +--------------------+---------+ | information_schema | utf8    | | gaurav             | latin1  | | menagerie          | latin1  | | mysql              | latin1  | | performance_schema | utf8    | | sample             | latin1  | | test               | latin1  | | tutorial           | latin1  | +--------------------+---------+ 8 rows in set (0.00 sec)

How can we delete a single row from a MySQL table?

Akshaya Akki
Updated on 20-Jun-2020 07:31:48

393 Views

We can use DELETE statement along with a WHERE clause, which identifies that particular row, to delete a row from MySQL table.Examplemysql> Select * from names; +------+-----------+ | id   | name      | +------+-----------+ | 1    | Rahul     | | 2    | Gaurav    | | 3    | Raman     | | 4    | Aarav     | | 5    | Ram       | +------+-----------+ 5 rows in set (0.00 sec) mysql> DELETE from names where id = 4; Query OK, 1 row affected (0.07 sec)The query above will delete a single row having id = 4 from table ‘names’.mysql> Select * from names; +------+-----------+ | id   | name      | +------+-----------+ | 1    | Rahul     | | 2    | Gaurav    | | 3    | Raman     | | 5    | Ram       | +------+-----------+ 4 rows in set (0.00 sec)

How can we get all the unique rows in MySQL result set?

Vikyath Ram
Updated on 20-Jun-2020 07:09:52

260 Views

With the help of DISTINCT keyword in SELECT statement, we can get the unique rows in MySQL result set.Examplemysql> Select * from names; +------+-----------+ | id   | name      | +------+-----------+ | 1    | Rahul     | | 2    | Gaurav    | | 3    | Raman     | | 4    | Aarav     | | 5    | Ram       | | 5    | Ram       | | 5    | Ram       | +------+-----------+ 7 rows in set (0.00 sec)As we can see that table ‘names’ is having three duplicate rows, with the help of following query we can get the result set having only unique rows.mysql> Select DISTINCT * from names; +------+-----------+ | id   | name      | +------+-----------+ | 1    | Rahul     | | 2    | Gaurav    | | 3    | Raman     | | 4    | Aarav     | | 5    | Ram       | +------+-----------+ 5 rows in set (0.00 sec)

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

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

140 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

281 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

4K+ 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

591 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

158 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

145 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

3K+ 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

Advertisements