找到 4379 篇文章 关于 MySQL
755 次查看
是的,我们可以像下面语法一样传递 NULL:insert into yourTableName values(NULL, yourValue1, yourValue2, ...N);让我们首先创建一个表:mysql> create table DemoTable1503 -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int -> ); Query OK, 0 rows affected (0.45 sec)使用 insert 命令在表中插入一些记录。由于我们在上面设置了 NOT NULL,因此它不会影响自动增量:mysql> insert into DemoTable1503 values(NULL, 'Chris', 25); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1503 values(NULL, 'David', 28); Query OK, 1 row ... 阅读更多
111 次查看
为此,您可以使用 SUBSTRING_INDEX() 以及 ORDER BY。让我们首先创建一个表:mysql> create table DemoTable1502 -> ( -> StudentId varchar(40) -> ); Query OK, 0 rows affected (0.54 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1502 values('John_120'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1502 values('John_201'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1502 values('Mike_178'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1502 values('Bob_198'); Query OK, 1 row affected (0.36 sec)使用 select ... 阅读更多
3K+ 次查看
您需要使用索引才能有效地选择多行。让我们首先创建一个表:mysql> create table DemoTable1501 -> ( -> Id int NOT NULL PRIMARY KEY, -> URL text -> ); Query OK, 0 rows affected (0.62 sec)以下是创建索引的查询:mysql> create index id_index on DemoTable1501(Id); Query OK, 0 rows affected (0.23 sec) Records: 0 Duplicates: 0 Warnings: 0使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1501 values(101, 'www.facebook.com'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1501 values(110, 'www.google.com'); Query OK, 1 ... 阅读更多
180 次查看
为此,您可以使用 GROUP BY 以及 ORDER BY 子句。让我们首先创建一个表:mysql> create table DemoTable1499 -> ( -> StudentName varchar(20), -> StudentMarks int -> ); Query OK, 0 rows affected (0.46 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1499 values('Chris', 56); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1499 values('David', 78); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1499 values('Bob', 98); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1499 values('Chris', 45); Query OK, 1 row ... 阅读更多
671 次查看
要复制 MySQL 数据库,语法如下:create table yourdatabaseName1.yourTableName1 select * from yourdatabaseName2.yourTableName2;让我们首先创建一个表:mysql> use sample; Database changed mysql> create table DemoTable101 -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (1.45 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable101 values(101, 'Sam'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable101 values(102, 'Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable101 values(103, 'David'); Query OK, 1 row affected (0.11 sec)显示所有记录 ... 阅读更多
800 次查看
要搜索包含 % 的列值,语法如下:select * from yourTableName where yourColumnName LIKE '\%%';让我们首先创建一个表:mysql> create table DemoTable1497 -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.55 sec)使用 insert 插入一些记录到表中:mysql> insert into DemoTable1497 values('%JohnSmith'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1497 values('DavidMiller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1497 values('CarolTaylor%'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1497 values('%DavidMiller'); Query OK, 1 row affected (0.12 ... 阅读更多
505 次查看
让我们首先创建一个表:mysql> create table DemoTable1496 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> PassengerCode varchar(20), -> ArrivalDate datetime -> ); Query OK, 0 rows affected (0.85 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1496(PassengerCode, ArrivalDate) values('202', '2013-03-12 10:12:34'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1496(PassengerCode, ArrivalDate) values('202_John', '2013-03-12 11:00:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1496(PassengerCode, ArrivalDate) values('204', '2013-03-12 10:12:34'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1496(PassengerCode, ArrivalDate) values('208', '2013-03-14 ... 阅读更多
239 次查看
让我们首先创建一个表:mysql> create table DemoTable1495 -> ( -> ShippingDate bigint -> ); Query OK, 0 rows affected (0.63 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1495 values(1570127400); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1495 values(1570213800); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1495 values(1570645800); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1495 values(1570300200); Query OK, 1 row affected (0.15 sec)使用 select 语句显示表中的所有记录:mysql> select * from DemoTable1495;这将产生以下 ... 阅读更多
286 次查看
为此,使用 DECIMAL(21,20)。让我们首先创建一个表:mysql> create table DemoTable1493 -> ( -> LongValue DECIMAL(21,20) -> ); Query OK, 0 rows affected (0.48 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1493 values(1.0047464644664677373); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1493 values(5.999999484757773); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1493 values(0.009994995885885); Query OK, 1 row affected (0.21 sec)使用 select 语句显示表中的所有记录:mysql> select * from DemoTable1493;这将产生以下输出:+------------------------+ | LongValue | +------------------------+ | 1.00474646446646773730 | | 5.99999948475777300000 | | 0.00999499588588500000 | +------------------------+ 3 rows in set (0.00 sec)
3K+ 次查看
如果使用了不正确的语法,可能会发生此错误。假设以下为 create table 语句:mysql> create table DemoTable1492 -> ( -> timestamp TIMESTAMP, -> event int, -> ); 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 ')' at line 5您需要删除上面 event 列后面的额外逗号以进行修复。让我们首先创建一个:mysql> create table DemoTable1492 -> ( -> timestamp TIMESTAMP, ... 阅读更多