Sqlserver如何把查詢的資料insert進入新表
首先建立新表:
然後用SQL實現把查詢的資料insert進入新表:
Insert into test.dbo.tmp_tj001(server_principal_name,object_name,maxdate)
select s1.server_principal_name,s1.object_name,max(s1.event_time) as maxdate from
(SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_920000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_520000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_450000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_650000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_980000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_730000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_430000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_670000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_380000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U')s1
group by s1.server_principal_name,s1.object_name
然後用SQL實現把查詢的資料insert進入新表:
Insert into test.dbo.tmp_tj001(server_principal_name,object_name,maxdate)
select s1.server_principal_name,s1.object_name,max(s1.event_time) as maxdate from
(SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_920000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_520000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_450000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_650000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_980000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_730000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_430000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_670000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U'
union all
SELECT distinct server_principal_name,object_name,event_time
FROM sys.fn_get_audit_file('\\10.0.2.116\Audit\Audit_380000.sqlaudit ', NULL, NULL)
WHERE database_name = 'HR'and action_id='CR' and class_type='U')s1
group by s1.server_principal_name,s1.object_name
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22996654/viewspace-2146465/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQLSERVER查詢某個資料庫有幾張表SQLServer資料庫
- SQLServer查詢所有資料庫大小SQLServer資料庫
- sqlserver查詢長括號[資料SQLServer
- 用Navicat把SQLServer資料匯入MySQLServerMySql
- 資料庫基礎查詢--單表查詢資料庫
- SqlServer查詢資料改動歷史記錄SQLServer
- INSERT...SELECT語句對查詢的表加鎖嗎
- 如何使用Java Streams進行資料庫查詢?Java資料庫
- Mysql 大資料表 資料匯入到SqlServer 中的方法MySql大資料Server
- 資料庫中單表查詢資料庫
- 查詢資料庫表及表欄位資料庫
- 查詢MySQL資料庫,MySQL表的大小MySql資料庫
- SqlServer遞迴查詢SQLServer遞迴
- 查詢SQLSERVER版本號SQLServer
- 資料庫全表查詢之-分頁查詢優化資料庫優化
- 把TXT文字匯入SQLServer 出錯:資料轉換失敗SQLServer
- efcore 跨表查詢,實現一個介面內查詢兩個不同資料庫裡各自的表資料資料庫
- SQLServer如何查詢近3分鐘最消耗CPU的SQLSQLServer
- 如何查詢某個資料表中除某個欄位的所有資訊???
- 查詢a表中b表沒有的資料,使用not exists
- [MySQL光速入門]005 查詢資料MySql
- java中資料庫查詢,搭配簡單的圖形介面進行查詢Java資料庫
- 查詢資料庫每個表佔用的大小資料庫
- mysql查詢表中日期最大的那條資料MySql
- mysql資料庫連表查詢的幾種方法MySql資料庫
- Sqlserver資料庫郵件的體系結構及常用的查詢檢視SQLServer資料庫
- 【PHP資料結構】雜湊表查詢PHP資料結構
- day95:flask:SQLAlchemy資料庫查詢進階&關聯查詢FlaskSQL資料庫
- MySQL—-MySQL資料庫入門—-第四章 單表查詢MySql資料庫
- 如何在Oracle資料庫中查詢表和欄位說明Oracle資料庫
- SQLSERVER跨伺服器查詢SQLServer伺服器
- SQLServer DML操作阻塞SELECT查詢SQLServer
- 如何查詢GBase資料庫中表的comment資訊資料庫
- 關於SqlServer資料表操作SQLServer
- Flask——資料的查詢Flask
- 億萬級分庫分表後如何進行跨表分頁查詢
- SQL Server 查詢資料庫中所有表資料條數SQLServer資料庫
- SQLServer IDENTITY_INSERT問題SQLServerIDE
- 分庫資料如何查詢統計