2014年10月30日 星期四

MS SQL 指令、語法與管理

2014年10月29日 星期三

SQL跨主機連線

SQL跨主機連線

2011/2/16 09:40 | 閱讀數 : 2906 我要推薦 | Add Comment | 文章分類 : SQL 訂閱
嗯~~「SQL」果然博大精深,
今天有需求去查詢資料,
但是,資料庫是位於「其他主機」上,
這‥‥就有趣了,
還好公司「google」能力夠強,
找到二種方式-長久、暫時。

長久-是指先註冊主機資訊,再用此資訊做查詢
1--註冊遠端伺服器名稱
2EXEC   sp_addlinkedserver     'otherDB','','SQLOLEDB','192.168.*.*'   -- 別名固定SQLServer
3EXEC   sp_addlinkedsrvlogin   'otherDB','false',null,'帳號','密碼'     --帳號密碼
4 
5select * from otherDB.資料庫名稱.dbo.表格
6 
7--將伺服器DROP掉
8EXEC   sp_dropserver   'otherDB','droplogins'
暫時-是只查一次,不需另外註冊主機
1SELECT *
2FROM   OPENDATASOURCE ('SQLOLEDB','Data Source=192.168.*.*;User ID=帳號;Password=密碼' ).資料庫.dbo.表格
嗯,結論是「我愛SQL」(它愛不愛我就不知道了~)  XD

2014年10月27日 星期一

Oracle 查空間使用多少 sql語法

col tablespace_name for a20
col used(MB) for a12
col free(MB) for a12
col total(MB) for a12
col PER_FREE for a12
select F.tablespace_name,to_char((T.total_space-F.free_space),'999,999,999') "used(MB)",
to_char(F.free_space,'999,999,999') "free(MB)",to_char(T.total_space,'999,999,999') "total(MB)",
to_char((round((F.free_space/T.total_space)*100)),'999')|| '%' PER_FREE
from  (select tablespace_name,
 round(sum(blocks*(select value/1024 from v$parameter where name='db_block_size')/1024))
  free_space   from dba_free_space group by tablespace_name ) F,
  (select tablespace_name,round(sum(bytes/1048576)) total_space
  from dba_data_files group by tablespace_name) T
 where F.tablespace_name =T.tablespace_name;

2014年10月26日 星期日