自己用到的一些SQL语句汇总
扫描二维码
随时随地手机看文章
1、关联更新字段值(从另外一个表中找到当前表记录的所属的另外一个表中记录的上级名称)
update A set [CarBrandName]=(select [itemname] from [TTC].[dbo].[auto_car_brand] where [id]=(select pid from [TTC].[dbo].[auto_car_brand] where id=A.[CarID] ) ) FROM [TTC].[dbo].[tuan_base] A
2、批量体会掉车型名称中的品牌
declare @i int set @i=1 while(@i<3171) BEGIN declare @aaa nvarchar(200) select @aaa=ShowName from tuan_base where tb_id=@i if(@aaa<>'') begin print 'update record '+convert(varchar(5),@i) update tuan_base set ShowName= REPLACE(ShowName,(select top 1 a+' ' from dbo.f_split(@aaa,' ')) ,'') where tb_id=@i end SET @i+=1 END
3、查看最后修改的存储过程
SELECT [name],create_date,modify_date FROM sys.all_objects WHERE type_desc = N'SQL_STORED_PROCEDURE' AND modify_date >='2017-01-05 00:00:00'