找到 4379 篇文章 关于 MySQL
1K+ 次浏览
要在列中插入多个值,语法如下:insert into yourTableName values(yourValue1), (yourValue2), ..........N;为了理解上述语法,让我们创建一个表:mysql> create table DemoTable2022 -> ( -> Department varchar(100) -> ); Query OK, 0 rows affected (0.49 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2022 values('Computer Science'), ('Information Technology'), ('Civil'), ('Mechanical'), ('Electronics'), ('Electrical'); Query OK, 6 rows affected (0.46 sec) Records: 6 Duplicates: 0 Warnings: 0使用 select 语句显示表中的所有记录:mysql> select *from DemoTable2022;这将产生以下结果... 阅读更多
1K+ 次浏览
要将数据从一个模式插入到另一个模式,语法如下。这里,我们有两个数据库“yourDatabaseName1”和“yourDatabaseName2”:insert into yourDatabaseName2.yourTableName2 select *from yourDatabaseName1.yourTableName1;为了理解上述语法,让我们创建一个表。我们在数据库“web”中创建一个表:mysql> create table DemoTable2020 -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.67 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2020 values(101, 'Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2020 values(102, 'David'); Query OK, 1 ... 阅读更多
723 次浏览
要使用 GROUP BY 更新字段,请使用带有 UPDATE 命令的 ORDER BY LIMIT:mysql> create table DemoTable2018 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeSalary int -> ); Query OK, 0 rows affected (0.61 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2018(EmployeeName, EmployeeSalary) values('Chris', 10000); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable2018(EmployeeName, EmployeeSalary) values('David', 12560); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable2018(EmployeeName, EmployeeSalary) values('Chris', 25400); Query OK, 1 row affected (0.09 sec)显示... 阅读更多
730 次浏览
让我们首先创建一个表:mysql> create table DemoTable2017 -> ( -> Name text -> ); Query OK, 0 rows affected (0.55 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2017 values('JOHN SMITH, MYSQL'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2017 values('DAVID MILLER, MONGODB'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2017 values('CHRIS BROWN, JAVA'); Query OK, 1 row affected (0.11 sec)使用 select 语句显示表中的所有记录:mysql> select *from DemoTable2017;这将产生以下输出:+----------------------+ | Name ... 阅读更多
229 次浏览
为此,您可以使用 CONCAT_WS() 和 GROUP_CONCAT()。让我们首先创建一个mysql> create table DemoTable2016 -> ( -> UserId int, -> UserName varchar(20) -> ); Query OK, 0 rows affected (0.51 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2016 values(1, 'Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2016 values(2, 'Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable2016 values(1, 'David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2016 values(2, 'Carol'); Query OK, 1 row affected (0.12 ... 阅读更多
115 次浏览
让我们首先创建一个表:mysql> create table DemoTable2015 -> ( -> StudentId int, -> StudentName varchar(20), -> StudentCountryName varchar(20) -> ); Query OK, 0 rows affected (1.20 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2015 values(1, 'Chris', 'US'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable2015 values(2, 'Bob', 'UK'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2015 values(3, 'David', 'AUS'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable2015 values(4, 'Robert', 'US'); Query OK, 1 ... 阅读更多
271 次浏览
要为列名设置别名,语法如下:select yourColumnName1 anyAliasName1, yourColumnName2 anyAliasName2 from yourTableName anyAliasName;为了理解上述语法,让我们创建一个表:mysql> create table DemoTable2014 -> ( -> FirstName varchar(20), -> LastName varchar(20) -> ); Query OK, 0 rows affected (0.70 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2014 values('John', 'Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2014 values('David', 'Miller'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable2014 values('John', 'Doe'); Query OK, ... 阅读更多
339 次浏览
让我们首先创建一个表:mysql> create table DemoTable2013 -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.63 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2013 values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2013 values('David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2013 values('Mike'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable2013 values('Sam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable2013 values('Bob'); Query OK, 1 row affected (0.12 sec)显示... 阅读更多
472 次浏览
要在插入记录时格式化日期,请在 MySQL INSERT 语句中使用 DATE_FORMAT()。让我们首先创建一个表:mysql> create table DemoTable2012 -> ( -> ShippingDate varchar(20) -> ); Query OK, 0 rows affected (0.48 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable2012 values(date_format(curdate(), '%d.%m.%Y')); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2012 values(date_format(now(), '%d.%m.%Y')); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2012 values(date_format('2014-01-21', '%d.%m.%Y')); Query OK, 1 row affected (0.17 sec)使用 select 语句显示表中的所有记录:mysql> select *from ... 阅读更多
402 次浏览
要在存储过程中执行 SHOW CREATE TABLE,请使用 SHOW CREATE TABLE 语句。 让我们先创建一个表:
mysql> create table DemoTable2011
-> (
-> StudentId int NOT NULL AUTO_INCREMENT,
-> StudentName varchar(20),
-> StudentAge int,
-> StudentCountryName varchar(20),
-> PRIMARY KEY(StudentId)
-> );
Query OK, 0 rows affected (0.80 sec)
以下是执行 SHOW CREATE TABLE 的存储过程:
mysql> delimiter //
mysql> create procedure test_show_create_demo(table_name varchar(100))
-> begin
-> set @query=concat("SHOW CREATE TABLE ", table_name);
-> prepare st from @query;
-> execute st;
-> end
... 阅读更多