mysql 常用语句整理

Posted zhuanjiao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 常用语句整理相关的知识,希望对你有一定的参考价值。

1. 替换某个字段中的部分内容

SET @oldlink1 = ‘http://192.168.100.66‘;
SET @newlink1 = ‘www.baidu.com‘;

UPDATE Test1
SET Content = (
	REPLACE (
		Content ,@oldlink1 ,@newlink1
	)
)
WHERE
	Content LIKE concat(‘%‘ ,@oldlink1, ‘%‘);

 

2.连表删除数据

SET @UnitId = ‘27542‘;

DELETE t1
FROM
	Test1 AS t1
INNER JOIN Test2 AS t2 ON t1.Code = t2.Code
WHERE
	t2.UnitId NOT IN (@UnitId);

  

3.连表插入数据

INSERT INTO Test (
	ID,
	PostTime
) SELECT
	UUID() AS ID,
	t1.PostTime
FROM
	Test1 AS t1
INNER JOIN Test2 AS t2 ON t1.Code = t2.Code;

 

4. 连表更新数据

UPDATE Test1 AS t1
INNER JOIN Test2 AS t2 ON t1.Code = t2.Code
SET t1.NextFlowNodeId = 72
WHERE
	t1.ProcessStepId = 70;

 

5.获取某个库下的所有表名

select table_name from information_schema.tables where table_schema=@dbName

  

6.获取某个表的所有字段名

select COLUMN_NAME from information_schema.COLUMNS where table_name = @tableName and table_schema = @dbName;

 

7.CONCAT 拼接字符串

SET @SearchText= CONCAT(‘%‘,‘测试‘,‘%‘);
SELECT * FROM  Test3 WHERE CONCAT(ItemName,ItemNumber,DeptName,RealName) LIKE @SearchText;

 注意:若拼接项中存在NULL值,结果为NULL。如 CONCAT(‘测试‘,‘001‘,NULL,‘小明‘),结果为NULL,并不是我们想要的结果:"测试001小明"

以上是关于mysql 常用语句整理的主要内容,如果未能解决你的问题,请参考以下文章

mysql 常用语句整理

mysql整理-常用sql语句

MySQL整理

C#常用代码片段备忘

最全最详细publiccms常用的代码片段

最全最详细publiccms其他常用代码片段(内容站点)