查看: 680|回复: 0
打印 上一主题 下一主题

[其他] 常用sql笔记

[复制链接]

9903

主题

126

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
53488
精华
316

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2015-12-25 06:52:49 |只看该作者 |倒序浏览

1、查询锁住的表,并删除
select  
    request_session_id spid ,
    OBJECT_NAME(resource_associated_entity_id ) tableName   
from  
    sys.dm_tran_locks  
where  
    resource_type='OBJECT'  
KILL 107--spid


2、跨数据库,将表A插到表B
SET IDENTITY_INSERT [dbo]. T_Bas_Enterprise ON
INSERT INTO dbo. T_Bas_Enterprise
        ( PK_UCode ,
          PK_EntID,
          EntCode ,
          UnitName ,
          ShortName ,
          UCPinyin ,
          Leager ,
          LeagerPhone ,
          Licence ,
          FK_EntTypeID ,
          FK_CTCode ,
          FK_VTCode ,
          FK_ESCode ,
          FK_RTCode ,
          FK_ERCode ,
          LinkName ,
          LinkPhone ,
          LinkMPhone ,
          LinkMail ,
          Fax ,
          PostCode ,
          PPDate ,
          Address ,
          EntPic ,
          PosX ,
          PosY ,
          fbitIsAnnex ,
          fbitStop ,
          CreateDate ,
          Creater ,
          UpdateDate ,
          Updater         
        )
SELECT
       NEWID() PK_UCode,PK_EntID ,EntCode, UnitName,ShortName ,UCPinyin, Legaler,BPhone LeagerPhone,NULL Licence,
       NULL fk_entTypeID,FK_CTCode ,FK_VTCode, FK_ESCode,FK_RTCode ,FK_ERCode ,
       LinkName,Phone linkphone, Mobile linkmphone ,EMail linkMail,Fax ,PostCode, PPDate,Address ,
       EntPic,PosX ,PosY, fbitIsAnnex,fbitStop ,fdtmCreateDate CreateDate,fdtmCreateUser Creater,
       fdtmCreateDate updateteDate ,fdtmCreateUser updater
FROM [192.168.253.63] .[DB_JJDC]. [CSBAS].[T_Bas_Enterprise]



3、当前数据库中,将表A插入到表B
insert into a (a的字段 ) select * form b
a的字段与*字段要一致


4、将List 以 指定字符 连接成一个字符串  如  1、2、 3
List<string> list = new List<string>();
            var str = list.Aggregate((p, next) => (p + "-" + next));

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-12 07:13 , Processed in 0.256558 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部