반응형
/*******************************************************************************************************************
-- Title : [Cb5.0] SIMBA ODBC를 통한 SQL Server 연결된 서버에서의 Couchbase 원격 쿼리 호출
-- Reference : simba.com
-- Key word : linked server 연결된 서버 4-partname 4 part name 오픈 쿼리 openquery n1ql N1QL
*******************************************************************************************************************/
■ SIMBA Couchbase ODBC Driver 설정
o dbrang.tistory.com/1349
■ CRUD Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 166 137 138 139 140 141 142 143 144 145 146 147 148 149 | /******************************************************************** -- LINKED_CB 조회 (SELECT) ********************************************************************/ /* -- 4-partname 호출 vs. OPENQUERY 호출 */ SELECT TOP 10 * FROM LINKED_CB.cbdefault.test.test; SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test LIMIT 10'); /* -- OPENQUERY내 쿼리문 개체명 사용 */ SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM cbdefault.test.test LIMIT 10'); -- 정상 SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test LIMIT 10'); -- 정상 SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test LIMIT 10'); -- 정상 /* -- 출력 건수 제약 (TOP, LIMIT) */ SELECT TOP (10) * FROM LINKED_CB.cbdefault.test.test; -- LIMIT 사용하면 에러남 SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test LIMIT 10'); -- LIMIT 가능 SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT TOP 10 * FROM test.test'); -- TOP n 가능 SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT TOP (10) * FROM test.test'); -- TOP (n) 불가 /* -- OPENQUERY시 쿼리 종결자(세미콜론) 사용하면 에러남 */ SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test LIMIT 10;'); -- 에러 SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test LIMIT 10'); -- 정상 /* -- WHERE 조건문 */ SELECT * FROM LINKED_CB.cbdefault.test.test WHERE skey = '3515531000183KO-1'; SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test WHERE skey = ''3515531000183KO'''); SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test use keys [''3515531000183KO'']'); -- 에러/N1QL은 안되는 듯 /******************************************************************** -- LINKED_CB 저장 (INSERT) ********************************************************************/ /* <OLE DB 공급자 "MSDASQL"이(가) 필요한 트랜잭션 인터페이스를 제공하지 않으므로 요청한 작업을 수행할 수 없습니다>라는 에러 발생시.. "연결된 서버 > 공급자 > MSDASQL > 속성"에서 Inprocess 허용, 트랜잭션되지 않은 업데이트가 체크되어야 함. */ INSERT INTO LINKED_CB.cbdefault.test.test (skey, ab, bt) VALUES ('3515531000183KO-4', 'ab ab ab', 'bt bt bt'); SELECT * FROM LINKED_CB.cbdefault.test.test WHERE skey = '3515531000183KO-4'; INSERT OPENQUERY(LINKED_CB, 'SELECT skey, ab, bt, cl FROM cbdefault.test.test') VALUES ('3515531000183KO-5', 'ab ab ab', 'bt bt bt ', 'cl cl cl'); SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test WHERE skey LIKE ''3515531000183%'''); /******************************************************************** -- LINKED_CB 수정 (UPDATE) ********************************************************************/ UPDATE LINKED_CB.cbdefault.test.test SET ab = 'ab ab ab ab ab ab ab' WHERE skey = '3515531000183KO-2'; SELECT * FROM LINKED_CB.cbdefault.test.test WHERE skey = '3515531000183KO-2'; UPDATE OPENQUERY(LINKED_CB, 'SELECT * FROM test.test WHERE skey = ''3515531000183KO-4''') SET bt = '{"a1":"1111", "a2":"2222"}' SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test WHERE skey = ''3515531000183KO-4'''); /******************************************************************** -- LINKED_CB 삭제 (DELETE) ********************************************************************/ SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test WHERE skey LIKE ''3515531000183%'''); DELETE FROM LINKED_CB.cbdefault.test.test WHERE skey = '3515531000183KO-5'; SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test WHERE skey LIKE ''3515531000183%'''); DELETE FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test WHERE skey = ''3515531000183KO-4'''); SELECT * FROM OPENQUERY(LINKED_CB, 'SELECT * FROM test.test WHERE skey LIKE ''3515531000183%'''); | cs |
반응형