找到 4379 篇文章 关于 MySQL
736 次浏览
您不能使用 index 作为列名,因为它是一个保留字。为此,您需要在列名周围使用反引号。如果您将保留字用作列名,则会看到以下错误-mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> index int -> )ENGINE=MyISAM; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int )ENGINE=MyISAM' at line 4让我们首先 ... 阅读更多
390 次浏览
要随机排序查询结果,请使用 ORDER BY RAND()。语法如下-select * from DemoTable1559 where yourColumnName IN(yourValue1, yourValue2, ....N) order by rand() limit yourLimitValue;让我们首先创建一个表-mysql> create table DemoTable1559 -> ( -> EmployeeId int, -> EmployeeName varchar(20), -> EmployeeAge int -> ); Query OK, 0 rows affected (1.22 sec)使用 insert 命令在表中插入一些记录-mysql> insert into DemoTable1559 values(101, 'Bob', 28); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1559 values(102, 'Robert', 26); Query OK, 1 row affected (0.16 sec) ... 阅读更多
304 次浏览
要重新格式化 MySQL 中的日期时间,您可以使用 DATE_FORMAT()。MySQL 以 yyyy-mm-dd 的格式给出。让我们首先创建一个表-mysql> create table DemoTable1558 -> ( -> EmployeeJoiningDate datetime -> ); Query OK, 0 rows affected (1.10 sec)使用 insert 命令在表中插入一些记录-mysql> insert into DemoTable1558 values(CURDATE()); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1558 values(NOW()); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1558 values('2018-01-10'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1558 values('2017-12-31'); Query OK, 1 row affected (0.18 sec)显示所有记录 ... 阅读更多
791 次浏览
要打乱元素,您需要使用 ORDER BY RAND()。让我们首先创建一个表-mysql> create table DemoTable1557 -> ( -> SubjectId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> SubjectName varchar(20) -> ); Query OK, 0 rows affected (0.91 sec)使用 insert 命令在表中插入一些记录-mysql> insert into DemoTable1557(SubjectName) values('MySQL'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1557(SubjectName) values('MongoDB'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1557(SubjectName) values('Java'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1557(SubjectName) values('C'); Query OK, 1 row affected ... 阅读更多
142 次浏览
让我们首先创建一个表-mysql> create table DemoTable1 -> ( -> Id int, -> FirstName varchar(20) -> ); Query OK, 0 rows affected (0.52 sec)以下是创建第二个表的查询-mysql> create table DemoTable2 -> ( -> EmployeeId int, -> EmployeeName varchar(20) -> ); Query OK, 0 rows affected (0.51 sec)现在让我们创建一个触发器来在 insert 命令中更新 MySQL 表-mysql> DELIMITER // mysql> CREATE TRIGGER updateDemoOnInsert -> AFTER INSERT ON DemoTable2 -> FOR EACH ... 阅读更多
414 次浏览
使用 FULLTEXT 搜索来快速搜索字符串。让我们首先创建一个表-mysql> create table DemoTable1554 -> ( -> Title text -> ); Query OK, 0 rows affected (0.63 sec)以下是创建全文搜索的查询-mysql> create fulltext index faster_title on DemoTable1554(Title); Query OK, 0 rows affected, 1 warning (7.09 sec) Records: 0 Duplicates: 0 Warnings: 1使用 insert 命令在表中插入一些记录-mysql> insert into DemoTable1554 values('John is working on MySQL database'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable1554 values('Adam Smith is working on ... 阅读更多
338 次浏览
为此,您可以使用 UNIQUE KEY。让我们首先创建一个表-mysql> create table DemoTable1553 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeSalary int -> ); Query OK, 0 rows affected (0.47 sec)以下是添加唯一键的查询-mysql> alter table DemoTable1553 add unique(EmployeeSalary); Query OK, 0 rows affected (0.53 sec) Records: 0 Duplicates: 0 Warnings: 0使用 insert 命令在表中插入一些记录-mysql> insert into DemoTable1553(EmployeeName, EmployeeSalary) values('Chris', 45000); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1553(EmployeeName, EmployeeSalary) ... 阅读更多
76 次浏览
对字符串输入值使用单引号。如果存在表名或列名之类的标识符,则不要使用单引号(使用反引号)。让我们首先创建一个表-mysql> create table DemoTable1552 -> ( -> `key` int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.82 sec)使用 insert 命令在表中插入一些记录-mysql> insert into DemoTable1552 values(101, 'Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1552 values(102, 'David'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1552 values(103, 'Mike'); Query OK, 1 row ... 阅读更多
379 次浏览
在 MySQL 中使用 FORMAT() 以正确的格式显示 USD 货币记录。让我们首先创建一个表-mysql> create table DemoTable -> ( -> Amount DECIMAL(15, 4) -> ); Query OK, 0 rows affected (0.75 sec)使用 insert 命令在表中插入一些记录-mysql> insert into DemoTable values(90948484); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1000000000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(1535353536); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(773646463); Query OK, 1 row affected (0.20 sec)显示所有记录 ... 阅读更多
375 次浏览
为此,您可以将 ORDER BY 子句与 LIMIT 结合使用。让我们首先创建一个表-mysql> create table DemoTable1551 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20) -> ); Query OK, 0 rows affected (0.52 sec)使用 insert 命令在表中插入一些记录-mysql> insert into DemoTable1551(EmployeeName) values('Chris'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1551(EmployeeName) values('Robert'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1551(EmployeeName) values('Mike'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1551(EmployeeName) values('Sam'); Query OK, 1 row ... 阅读更多