sql 常用语句

性能测试
/****** SSMS 的 SelectTopNRows 命令的脚本 ******/

查询

SELECT *  FROM [CL0011].[dbo].[AlarmData20200605] where szConditionName = '事件顺序记录SOE' and szDesc like '1_1RTU_888_YX1合'


  SELECT *  FROM [CL0011].[dbo].[AlarmData20200526]

查询并插入某表

insert into [CL0011].[dbo].[AlarmData20200526] select  * from [CL0011].[dbo].[AlarmData20200604] where szConditionName = '事件顺序记录SOE'

删除某表数据

delete from [CL0011].[dbo].[AlarmData20200604]

新建表

 /*select * into newtable from  (select * from [CL0011].[dbo].[AlarmData20200526] union all select * from [CL0011].[dbo].[AlarmData20200527] )


    CREATE TABLE total 
    (
    [szSource] nvarchar(256)
  ,[szDesc] nvarchar(256)
  ,[dtTime] datetime2(7)
  ,[nEventCategory] int
  ,[nSeverity] int
  ,[szAlarmVal] nvarchar(256)
  ,[szAlarmStatus] nvarchar(256)
  ,[szLimitVal] nvarchar(256)
  ,[nActorID] int
  ,[IDIED] int
  ,[nCookie] int
  ,[dtAck] datetime
  ,[dtActiveTime] nvarchar(256)
  ,[szConditionName] nvarchar(256)

    );

多表查询并插入某表

  INSERT INTO total ([szSource]
  ,[szDesc]
  ,[dtTime]
  ,[nEventCategory]
  ,[nSeverity]
  ,[szAlarmVal]
  ,[szAlarmStatus]
  ,[szLimitVal]
  ,[nActorID]
  ,[IDIED]
  ,[nCookie]
  ,[dtAck]
  ,[dtActiveTime]
  ,[szConditionName]) ( select * from [CL0011].[dbo].[AlarmData20200526] union all select * from [CL0011].[dbo].[AlarmData20200527]) GROUP BY [szSource],[dtTime]

  */

  select distinct [szSource],[dtTime]  from [CL0011].[dbo].[total]

你可能感兴趣的:(sql 常用语句)