找到关于数据库的 6705 篇文章
1K+ 阅读量
让我们首先创建一个表 - mysql> create table DemoTable1966 ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(20), PhotoLiked int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1966(UserName, PhotoLiked) values('Chris', 57); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1966(UserName, PhotoLiked) values('David', 100); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1966(UserName, PhotoLiked) values('Mike', 68); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1966(UserName, PhotoLiked) values('Sam', 78); Query OK, 1 row affected (0.00 sec)显示所有 ... 阅读更多
112 阅读量
要识别列名,请在 MySQL 中使用 INFORMATION_SCHEMA.COLUMNS。以下是语法 - select table_name, column_name from INFORMATION_SCHEMA.COLUMNS where table_schema = SCHEMA() andcolumn_name='anyColumnName';让我们实现上述查询以识别所有表中存在的列。在这里,我们正在查找列 EmployeeAge 的存在 - mysql> select table_name, column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = SCHEMA() AND column_name='EmployeeAge';这将生成以下输出,显示具有特定列“EmployeeAge”的表 - +---------------+-------------+ | TABLE_NAME | COLUMN_NAME | +---------------+-------------+ | demotable1153 | EmployeeAge | | demotable1297 | EmployeeAge | | demotable1303 | EmployeeAge | | demotable1328 ... 阅读更多
976 阅读量
为此,您可以使用 GROUP BY 以及聚合函数 MAX()。让我们首先创建一个表 - mysql> create table DemoTable1964 ( StudentName varchar(20), StudentAge int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1964 values('Chris', 23); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1964 values('David', 34); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1964 values('Chris', 27); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1964 values('Sam', 31); Query OK, 1 row affected (0.00 sec) mysql> ... 阅读更多
359 阅读量
要创建用户并授予权限,语法如下 - create database yourDatabaseName DEFAULT CHARACTER SET utf8; create user `yourUserName` identified by yourPassword; GRANT SELECT ON yourDatabaseName .* TO `yourUserName`; GRANT INSERT ON yourDatabaseName .* TO `yourUserName`; GRANT UPDATE ON yourDatabaseName .* TO `yourUserName`; GRANT DELETE ON yourDatabaseName .* TO `yourUserName`; GRANT EXECUTE ON yourDatabaseName .* TO `yourUserName`;以下是创建用户并授予权限的查询 - mysql> create database demo_app DEFAULT CHARACTER SET utf8; Query OK, 1 row affected, 1 warning (0.00 sec) mysql> create user `John_123` identified by '123456'; Query OK, 0 rows affected (0.00 sec) ... 阅读更多
430 阅读量
为此,您可以使用 SUBSTRING_INDEX()。让我们首先创建一个表 - mysql> create table DemoTable1962 ( EmployeeInformation text ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1962 values('101-John-29'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1962 values('102-David-35'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1962 values('103-Chris-28'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 - mysql> select * from DemoTable1962;这将生成以下输出 - +---------------------+ | EmployeeInformation | +---------------------+ | 101-John-29 ... 阅读更多
85 阅读量
让我们首先创建一个表 - mysql> create table DemoTable1961 ( Title text ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1961 values('You_can_remove_the_string_part_only-10001-But_You_can_not_remove_the_numeric_parts'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 - mysql> select * from DemoTable1961;这将生成以下输出 - +------------------------------------------------------------------------------------+ | Title ... 阅读更多
296 阅读量
为此,您可以使用 GROUP_CONCAT()。使用 SUM() 添加用户 ID。让我们首先创建一个表 - mysql> create table DemoTable1960 ( StudentId int, StudentName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1960 values(100, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1960 values(101, 'Bob'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1960 values(102, 'David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1960 values(103, 'Mike'); Query OK, 1 row affected (0.00 sec)显示 ... 阅读更多
956 阅读量
要创建像年份(2019)这样的表名,请使用 PREPARE 语句。让我们首先创建一个表 - mysql> create table DemoTable1959 ( UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1959 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1959 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1959 values('Bob'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 - mysql> select * from DemoTable1959;这将生成以下输出 - +----------+ | UserName ... 阅读更多
648 阅读量
为此,请使用 ZEROFILL 并更改表以从相同的序列开始 -alter table yourTableName change yourColumnName yourColumnName int(3) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY; 为了理解上述语法,让我们先创建一个表 -mysql> create table DemoTable1958 ( UserId int, UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec) 以下是将生成的序列号更改为从 001 开始的查询:mysql> alter table DemoTable1958 change UserId UserId int(3) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY; Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0 让我们 ... 阅读更多
330 次查看
让我们先创建一个表 -mysql> create table DemoTable1957 ( EmployeeId int, EmployeeName varchar(20), EmployeeSalary int ); Query OK, 0 rows affected (0.00 sec) 使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1957 values(1, 'Chris', 240000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(2, 'Bob', 120000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(3, 'David', 180000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(4, 'Mike', 650000); Query OK, 1 row affected (0.00 sec) 使用 ... 阅读更多