--导入数据插入标识列,ID重复则替换,旧表中没有的列用'abc' as Field进行插入 SET IDENTITY_INSERT NetCMS.dbo.NT_channel_video ON insert into NetCMS.dbo.NT_channel_video(Id,title,ch_videourl,Author,Souce,CreatTime,[Content],NaviContent,ChID,ClassID,OrderID, isdelpoint,isHTML,isConstr,ConstrTF,TitleITF,TitleBTF,ContentProperty,Templet,islock,Click,iPoint,Gpoint) select id,title,filepath,author,comefrom,adddate,[content],jj,'2' as ChID,'1' as ClassID,'0' as OrderID, '0' as isdelpoint,'1' as isHTML,'0' as isConstr,'0' as ConstrTF,'0' as TitleITF,'0' as TitleBTF,'0|0|0|0|0' as ContentProperty, 'content.html' as Templet,'0' as islock,'0' as Click,'0' as iPoint,'0' as Gpoint from haxq.dbo.Sd_Info SET IDENTITY_INSERT NetCMS.dbo.NT_channel_video OFF --清空表中所有数据,并且重新自动编号 truncate table NT_channel_video --生成GUID在前后加花括号 insert into Article(id) values('{'+cast(newid() as varchar(36))+'}') --更新数据库中所有列的某个相同字段的数据,截取一定长度 Update NT_channel_video set NaviContent=stuff(NaviContent,26,len(NaviContent)-26,'...') --随机查询出一条数据,关键语法Order by newid() select top 1 SUBSTRING(NewsTitle,0,16) as Title,SavePath,FileName,isHtml from NT_News where PicURL = '' and isLock = 0 and isHtml = 1 order by newid() --cast()函数用法,转换数据格式类型 update NT_News set [FileName]='news_'+cast(ID as varchar) --convert()转换时间格式,详细了解请百度 select convert(varchar(30),CreatTime,112) from NT_channel_video --某个字段中数据格式是这样1,0,1,0,1,0,0,1,想要以第3位为1为条件查询数据,用SQL中的'_'(不含引号)匹配任意一个字符,汉字也是。'%'匹配任意字符串 select * from NT_News where NewsProperty like '____1%'(这里是4个下划线) --替换某个字段中的字符串 update NT_News set Tags=replace(Tags,'广广','广告') where Tags like '%广广%' --两张表更新 UPDATE A SET A.Thumbnail =B.Thumbnail from A inner join B on A.ID=B.ID
几个SQL语句,记之,导入数据必备
上一篇: [转]ASP.NET中的Eval和DataBinder.Eval方法
下一篇: [转]C#数字格式化输出