Diff for "MSSqlWorkBook" | UserPreferences |
===== ¿ÀÈÄ 1:27 2004-09-14, p.329 =====
Ä¿¼ÀÇ Á¾·ù - t-sql server cursor, api server cursor, client cursor ;
t-sql ;
DECLARE testcursor CURSOR FOR
SELECT * FROM testtb2
OPEN testcursor
FETCH NEXT/PRIOR/FIRST/LAST FROM testcursor
FETCH RELATIVE 0 FROM testcursor
FETCH ABSOLUTE 0 FROM testcursor
UPDATE testtb2
SET test_text ='test'
WHERE CURRENT OF testcursor
CLOSE testcursor
DEALLOCATE testcursor
api - oledb, odbc, db-library (¼¹öÃø api)
client - odbc, db-library, ado api ³»ºÎ ±¸Çö. forwardonly, static Ä¿¼¸¸ °¡´É
xml Áö¿ø
SELECT * FROM testtb2 t1 inner join testtb2 t2
on t1.tempid = t2.tempid
FOR XML
RAW AUTO EXPLICIT, (XMLDATA, ELEMENTS, BINARY BASE64)
XMLDATA - schema Ãâ·Â
ELEMENTS - ÇÏÀ§ µ¥ÀÌÅ͸¦ Ư¼ºproperty°¡ ¾Æ´Ñ ¿ä¼Òelement·Î Ãâ·Â, auto¿¡¼¸¸ °¡´É
BINARY BASE64 - ÀÌÁø µ¥ÀÌÅ͸¦ base64 ÀÎÄÚµùÀ¸·Î Ç¥½Ã
openxml
DECLARE @hdoc INT
EXEC sp_xml_preparedocument @hdoc OUTPUT,
N'<ROOT>
<Customers CustomerID="XYZAA" Contactname="Joe" Companyname="Company1">
<Orders CustomerID="XYZAA" Orderdate="2000-08-25T00:00:00" />
<Orders CustomerID="XYZAA" Orderdate="2000-08-31T00:00:00" />
</Customers>
<Customers CustomerID="XYZAB" Contactname="Steve" Companyname="Company2">
No orders yet?
<Orders CustomerID="XYZAB" Orderdate="2000-02-25T00:00:00" />
<Orders CustomerID="XYZAB" Orderdate="2000-03-31T00:00:00" />
</Customers>
</ROOT>'
SELECT * FROM OPENXML(@hdoc, N'/ROOT/Customers/Orders')
WITH ( CustomerID NCHAR(5) './@CustomerID',
Contactname NVARCHAR(50) '../@Contactname', Orderdate DATETIME)
EXEC sp_xml_removedocument @hdoc
sp_rename 'customers.contacttitle', 'title', 'COLUMN' ; Ä÷³ À̸§ º¯°æ
ÀúÀå ÇÁ·Î½ÃÀú - ½Ã½ºÅÛ ÀúÀå ÇÁ·Î½ÃÀú, ·ÎÄà ÀúÀå ÇÁ·Î½ÃÀú, Àӽà ÀúÀå ÇÁ·Î½ÃÀú, È®Àå ÀúÀå ÇÁ·Î½ÃÀú, ¿ø°Ý ÀúÀå ÇÁ·Î½ÃÀú
OBJECTPROPERTY ÇÔ¼ö¸¦ »ç¿ë, isextendedproc ¼Ó¼ºÀ¸·Î È®ÀåspÀÎÁö ½Ã½ºÅÛspÀÎÁö ÆǺ° °¡´É
ÇØ´ç °³Ã¼ÀÇ ½ºÅ©¸³Æ® ¿¶÷
sp_helptext master.dbo.sp_who
select text from master.dbo.sp_who s inner join master.dbo.sp_who c on s.id = c.id
where s.name = 'sp_who'
ÇÁ·Î½ÃÀúÀÇ À̸§ ¾Õ¿¡ #¸¦ Ç¥½ÃÇÔÀ¸·Î½á tempdb¿¡ »ý¼ºÇÏ´Â Àӽà ÀúÀå ÇÁ·Î½ÃÀú¸¦ ¸¸µç´Ù.
##ÀÏ °æ¿ì ±Û·Î¹ú Àӽà ÀúÀå ÇÁ·Î½ÃÀú°¡ µÈ´Ù
CREATE PROCEDURE up_temptb
AS
SELECT * From testtb2
WITH RECOMPILE - ½ÇÇà½Ã¸¶´Ù ÄÄÆÄÀÏÇÑ´Ù.
WITH ENCRYPTION - ½ºÅ©¸³Æ® ³»¿ëÀ» ¾ÏÈ£ÈÇÑ´Ù.
OBJECTPROPERTY ÇÔ¼öÀÇ isencrypt ¼Ó¼ºÀ¸·Î ¾ÏȣȵǾú´ÂÁö ÆǺ° °¡´É
autostart ÇÁ·Î½ÃÀú°¡ ÀÚµ¿À¸·Î ½ÃÀ۵ǵµ·Ï ±¸¼º(dbo ¼ÒÀ¯À̸ç master db¿¡ ÀÖ¾î¾ß ÇÔ) ;
sp_procoption
@procname = autostart,
@optioname = startup,
@optionvalue = true
OBJECTPROPERTY ÇÔ¼öÀÇ execisstartup ¼Ó¼ºÀ¸·Î ÀÚµ¿ ½ÃÀÛ ÆǺ°
sql server°¡ ´ÙÀ½¹ø¿¡ ½ÃÀÛÇÒ ¶§ ÀÚµ¿ ½ÃÀÛ ±¸¼ºÀ» ÇÏÁö ¾Êµµ·Ï ÇÔ ;
EXECUTE sp_configure
@configname = 'scan for startup procs', @configvalue = 0
RECONFIGURE
GO
ALTER PROCEDURE ±¸¹® »ç¿ë½Ã, WITH ¼Ó¼ºÀº À¯ÁöµÇÁö ¾ÊÀ¸¹Ç·Î ´Ù½Ã ¸í½ÃÇØ¾ß ÇÔ.
sp_rename @objname = 'up_test', @newname = 'up_testnew', @objtype = 'object' ; sp À̸§ ¼öÁ¤
sp_depends ; ÀÇÁ¸ °ü°è °Ë»ç
DROP PROCEDURE¸¦ ½ÇÇàÇϸé ÇöÀç db¿¡¼ ÇØ´ç sp¸¦ ã°í, ¾øÀ¸¸é master db¸¦ °Ë»öÇÑ´Ù.
ntext, text, image
; ado - appendchunk·Î ¼öÁ¤
; oledb - ISequentialStream ÀÎÅÍÆäÀ̽º·Î »õ °ªÀ» ¾µ ¼ö ÀÖÀ½
; odbc - sqlpudataÀÇ data-at-execution ÆûÀ» »ç¿ë °¡´É
; db-library ¾îÇÃÀº dbwritetext ÇÔ¼ö¸¦ »ç¿ë, ¼öÁ¤Àº dbupdatetext ÇÔ¼ö
; t-sql - updatetext ±¸¹® »ç¿ë
delete, api, cursor, truncate table ; rowsetÀ» »èÁ¦ÇÒ ¼ö ÀÖ´Â ±¸¹®µé
delete like this ; DELETE books FROM titles WHERE books.title = titles.title AND titles.royalty = 10
truncate table is not LOGGED!
bcp tempdb..testtb out c:\testtb.txt -c -T
bcp tempdb..testtb2 in c:\testtb.txt -c -T
(´ë»ó Å×À̺íÀº ¸¸µé¾îÁ® ÀÖ¾î¾ß ÇÔ)
or
BULK INSERT testtb2
FROM 'c:\testtb.txt'
WITH (DATAFILETYPE = 'char')
* bcp´Â Å×ÀÌºí ´ÜÀ§ÀÇ ´ë·® Insertion¿¡ ÀûÇÕ
linked server ; sp_addlinkedserver or em¿¡¼ ¼¹ö Á¤ÀÇ
Select * From addServer.targetDB.dbo.Table °°Àº ÇüÅ·ΠÁ¢±Ù °¡´É
openquery ; Select * From OPENQUERY ( addServer, 'SELECT lastname FROM customer)
ad-hoc query ; openrowset, opendatasource ... oledb¸¸ Àû¿ë °¡´É
SELECT * FROM OPENROWSET
('Microsoft.jet.oledb.4.0', 'c:\testdb.mdb';'admin';' ', customer) as c
SELECT * FROM OPENDATASOURCE
('Microsoft.jet.oledb.4.0', 'Data Source = c:\testdb.mdb; User ID=admin; Password=')...customer as c