找到关于 MySQL 的4379 篇文章
78 次浏览
下面的查询将返回数据库名称及其默认字符集: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)
323 次浏览
我们可以使用 DELETE 语句以及 WHERE 子句来删除 MySQL 表中的一行,WHERE 子句标识该特定行。示例 mysql> 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) 上面的查询将删除表 'names' 中 id = 4 的单行。mysql> Select * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | | 3 | Raman | | 5 | Ram | +------+-----------+ 4 rows in set (0.00 sec)
220 次浏览
借助 SELECT 语句中的 DISTINCT 关键字,我们可以获取 MySQL 结果集中的唯一行。示例 mysql> 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) 如我们所见,表 'names' 有三行重复的行,借助下面的查询,我们可以获得结果集,其中只有唯一行。mysql> Select DISTINCT * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | | 3 | Raman | | 4 | Aarav | | 5 | Ram | +------+-----------+ 5 rows in set (0.00 sec)
93 次浏览
借助以下查询,我们可以查看 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 ... 阅读更多
235 次浏览
在这种情况下,MySQL 将返回错误消息,因为我们知道,如果使用子查询在 UPDATE 语句的 SET 子句中赋值,则它必须为与 WHERE 子句匹配的更新表中的每一行返回正好一行。示例 mysql> 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 ... 阅读更多
3K+ 次浏览
在 MySQL 中,SERIAL 和 AUTO_INCREMENT 都用于将序列定义为字段的默认值。但它们在技术上彼此不同。AUTO_INCREMENT 属性受除 BIT 和 DECIMAL 之外的所有数字数据类型支持。每个表只能有一个 AUTO_INCREMENT 字段,并且一个表中的 AUTO_INCREMENT 字段生成的序列不能用于任何其他表。此属性要求在字段上存在唯一索引以确保序列没有重复。序列默认从 1 开始,每次插入都会递增 1。示例 mysql> ... 阅读更多
492 次浏览
众所周知,CHAR 用于存储定长字符串,VARCHAR 用于存储变长字符串。因此,我们可以通过将一个列声明为 CHAR,另一个列声明为 VARCHAR 来在同一表中存储定长和变长字符串。示例 mysql> 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 | ... 阅读更多
117 次浏览
在这种情况下,MySQL 将向 SET 子句提供 NULL 值。下面的示例将演示它:示例 mysql> 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) ... 阅读更多
103 次浏览
这可以通过以下示例来理解,在该示例中,我们使用名为 '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) 现在,我们可以通过以下两种方式使用日期搜索记录:mysql> Select * from detail_bday Where Birth_Date = '1993-06-11'; +----+-------+------------+ | Sr | ... 阅读更多
2K+ 次浏览
顾名思义,启用 ALLOW_INVALID_DATES SQL 模式将允许我们将无效日期存储在表中。以下示例说明了这一点:示例 mysql> 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 ... 阅读更多