MySQL Articles - Page 382 of 402

How MySQL reacts when we specify a CHARACTER SET binary attribute for a character string data type?

Sravani S
Updated on 20-Jun-2020 07:36:30

238 Views

On specifying a CHARACTER SET binary attribute for a character string data type, MySQL creates that column as its subsequent binary string type. The conversions for CHAR, VARCHAR and BLOB data types take place as follows −CHAR would become BINARYVARCHAR would become VARBINARYTEXT would become BLOBThe above kind of conversion does not occur for ENUM and SET data type and they both are created as declared while creating the table.ExampleIn the example below we have created a table named ‘EMP’ with four columns all specified as CHARACTER SET binary as follows −mysql> Create table Emp(Name varchar(10) CHARACTER SET binary, Address ... Read More

How can I check the character set of all the tables along with column names in a particular MySQL database?

Rishi Rathor
Updated on 20-Jun-2020 07:33:43

220 Views

With the help of the following MySQL query we can check the character sets of all the tables in a particular database −mysql> Select Column_name, TABLE_NAME, CHARACTER_SET_NAME FROM        INFORMATION_SCHEMA.Columns Where TABLE_SCHEMA = 'db_name';ExampleFor example, the query below returns the character sets of all the tables along with the column names in a database named ‘Alpha’.mysql> Select Column_name 'Column', TABLE_NAME, CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.Columns Where TABLE_SCHEMA = 'Alpha'; +---------+------------+--------------------+ | Column  | TABLE_NAME | CHARACTER_SET_NAME | +---------+------------+--------------------+ | Name    | employee   | latin1             | | email   | employee   ... Read More

How can we check the character set of all the tables in a particular MySQL database?

V Jyothi
Updated on 20-Jun-2020 07:33:19

2K+ Views

With the help of the following MySQL query we can check the character sets of all the tables in a particular database −mysql> Select TABLE_NAME, CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.Columns Where TABLE_SCHEMA = 'db_name';ExampleFor example, the query below returns the character sets of all the tables in a database named ‘Alpha’.mysql> Select TABLE_NAME, CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.Columns Where TABLE_SCHEMA = 'Alpha'; +------------+--------------------+ | TABLE_NAME | CHARACTER_SET_NAME | +------------+--------------------+ | employee   | latin1             | | employee   | latin1             | | student    | latin1             ... Read More

How can we delete multiple rows from a MySQL table?

Lakshmi Srinivas
Updated on 20-Jun-2020 07:31:13

7K+ Views

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

Mobile

What is the query to check Character set of the columns of MySQL table?

Daniol Thomas
Updated on 20-Jun-2020 07:32:48

530 Views

Following is the query to check character set of the columns of MySQL table −mysql> Select Column_name 'Column', Character_set_name 'Charset' FROM        information_schema.columns where table_schema = 'db_name' and        table_name ='table_name';ExampleFor example, the query below returns the name of the columns of ‘test_char_set’ table in a database named ‘sample’ along with the character sets of those columns.mysql> Select Column_name 'Column', Character_set_name 'Charset' FROM        information_schema.columns where table_schema = 'Sample' and        table_name ='test_char_set'; +--------+---------+ | Column | Charset | +--------+---------+ | Name   | latin1  | | Field  | latin1  | ... Read More

How can we check the default character sets of a particular MySQL database?

Priya Pallavi
Updated on 20-Jun-2020 07:32:16

213 Views

Following is the query to check default character set of the particular MySQL database −mysql> SELECT SCHEMA_NAME 'DatabaseName', default_character_set_name 'Charset' FROM information_schema.SCHEMATA where schema_name = 'db_name';ExampleFor example, the query below will return the default character set of a database named ‘Sample’ −mysql> SELECT SCHEMA_NAME 'DatabaseName', default_character_set_name 'Charset' FROM information_schema.SCHEMATA where schema_name = 'Sample'; +----------------+---------+ | DatabaseName   | Charset | +----------------+---------+ | Sample         | latin1  | +----------------+---------+ 1 row in set (0.00 sec)

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

143 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

431 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

288 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 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

316 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

Advertisements