找到 4219 篇文章 适用于 MySQLi
230 次查看
要为现有列设置 NOT NULL 属性,请使用 ALTER TABLE 命令。让我们首先创建一个表 -mysql> create table DemoTable1949 ( UserId int, UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)以下是为现有列设置 NOT NULL 属性的查询 -mysql> alter table DemoTable1949 modify UserName varchar(20) not null; Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0让我们检查表的描述 -mysql> desc DemoTable1949;这将产生以下输出 -+----------+-------------+------+-----+---------+-------+ | Field | Type | Null | ... 阅读更多
261 次查看
要仅对字母数字字符串中的数字进行排序,请使用 ORDER BY RIGHT()。让我们首先创建一个表 -mysql> create table DemoTable1948 ( StudentCode varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1948 values('121John_567'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1948 values('Adam_101'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1948 values('Bob_563'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1948 values('Sam_346'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> ... 阅读更多
1K+ 次查看
让我们首先创建一个表 -mysql> create table DemoTable1947 ( Id int, Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1947 values(101, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1947 values(102, 'David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1947 values(103, 'Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1947 values(104, 'Bob'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1947 values(105, 'Sam'); Query OK, 1 row affected (0.00 sec)显示 ... 阅读更多
471 次查看
让我们首先创建一个表 -mysql> create table DemoTable1946 ( ShippingDate date ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1946 values('2019-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2018-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2017-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2019-04-22'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2019-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2015-12-11'); Query OK, 1 ... 阅读更多
5K+ 次查看
要插入来自多个表的数据,请使用 INSERT INTO SELECT 语句。在这里,我们将插入来自 2 个表的数据。让我们首先创建一个表 -mysql> create table DemoTable1943 ( Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1943 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1943 values('Robert'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable1943;这将产生以下输出 -+--------+ | Name | +--------+ | Chris ... 阅读更多
72 次查看
为此,请使用正则表达式。语法如下 -select * from information_schema.schemata WHERE SCHEMA_NAME REGEXP '^yourValue_+[A-Z]';让我们创建一些数据库 -mysql> create database bank_APP1; Query OK, 1 row affected (0.00 sec) mysql> create database bank_APP2; Query OK, 1 row affected (0.00 sec) mysql> create database bank_APP3; Query OK, 1 row affected (0.00 sec)以下是获取名称中某个单词后包含大写字符的所有数据库的查询 -mysql> select * from information_schema.schemata WHERE SCHEMA_NAME REGEXP '^bank_+[A-Z]';这将产生以下输出 -+--------------+-------------+----------------------------+------------------------+----------+ | CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH | +--------------+-------------+----------------------------+------------------------+----------+ | def ... 阅读更多
2K+ 次查看
为此,请使用 COUNT(*) 以及 GROUP BY 子句。让我们首先创建一个表 -mysql> create table DemoTable1942 ( Value int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1942 values(1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1942 values(2); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1942 values(3); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1942 values(2); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1942 values(3); Query OK, 1 row affected (0.00 ... 阅读更多
1K+ 次查看
要返回计数最高的字段,请使用 ORDER BY COUNT(*)。让我们首先创建一个表 -mysql> create table DemoTable1940 ( FirstName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1940 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1940 values('Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1940 values('Adam'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1940 values('Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1940 values('Chris'); Query OK, 1 row ... 阅读更多
177 次查看
为此,您可以使用 LEFT()。让我们首先创建一个表 -mysql> create table DemoTable1939 ( FullName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1939 values('Adam Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1939 values('Robert Downey, Jr.'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1939 values('Sylvester Stallone'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1939 values('Chris Hemsworth'); Query OK, 1 row affected (0.00 sec)显示表中的所有记录 -mysql> ... 阅读更多
1K+ 次查看
要显示所有字段,请使用以下语法设置包含表架构的数据库和包含表名的特定表:−select column_name as anyAliasName from information_schema.columns where table_schema=database() and table_name=’yourTableName’\G让我们首先创建一个表:−mysql> create table DemoTable1938 ( StudentId int, StudentName varchar(20), StudentAge int, StudentCountryName varchar(20), StudentMobileNumber bigint ); Query OK, 0 rows affected (0.00 sec)以下是显示表所有字段的查询:−mysql> select column_name as ALL_FIELDS from information_schema.columns where table_schema=database() and table_name='DemoTable1938'\G这将产生以下输出:−*************************** 1. row *************************** ALL_FIELDS: StudentId ... 阅读更多