SQL Server 2008 FileStream
FileStream:ÎļþÁ÷,ΪÁ˽â¾ö´ó¶ÔÏóBLOB(Binary Large Objects)µÄ´æ´¢ÎÊÌâ.¶ÔÓÚ´ó¶ÔÏó´æ´¢,²¢ÇÒ²»ÊÜ2GBµÄÏÞÖÆ.
ÒÔÍùÓÐÁ½ÖÖ·½Ê½:
(1)´æ´¢ÔÚÊý¾Ý¿âÀïÃæ,ÕâÖÖ·½Ê½Ò»°ãʹÓÃimage×Ö¶Î,»òÕßvarbinary(max)À´×ö,ºÃ´¦ÊÇ¿ÉÒÔͳһ±¸·Ý,µ«Êµ¼ÊЧÂʽϵÍ;
(2)´æ´¢ÔÚÎļþϵͳ,¶øÊý¾Ý¿âÖд洢Îļþ·¾¶,ÕâÖÖ·½Ê½Êý¾Ý¿âѹÁ¦¼õÇáÁË,µ«È´²»·½±ãͳһ±¸·ÝºÍ¹ÜÀí.
SQL SERVER 2008ÐÂÒýÈëµÄÎļþÁ÷¾ÍÊÇÁ½ÕßµÄͳһ.Îļþ»¹ÊÇ·ÅÔÚÎļþϵͳ,µ«ÓÉÊý¾Ý¿â½øÐйÜÀí,¿ÉÒÔͳһ±¸·ÝºÍ»¹Ô.
ÈçºÎʹÓÃFileStream?
Ò».ÆôÓÃFileStream
(1)ÔÚSQL ServerÅäÖùÜÀíÆ÷Öдò¿ªSQL ServerÊý¾Ý¿âÒýÇæµÄÊôÐÔ´°¿Ú.
(2)Çл»µ½FILESTREAMÑ¡Ï,Ñ¡ÖÐ"Õë¶ÔTransact-SQL·ÃÎÊÆôÓÃFILESTREAM",ÆäËûÑ¡ÏîÊÇÕë¶Ôwindows½øÐжÁдµÄ,¶¼¿ÉÒÔÑ¡ÖÐ.
(3)´ò¿ªSSMSÁ¬½Óµ½Êý¾Ý¿âʵÀý(ÊÇʵÀý,²»ÊǾßÌåµÄÊý¾Ý¿â),ÓÒ»÷Êý¾Ý¿âʵÀý,Ñ¡Ôñ"ÊôÐÔ"Ñ¡Ïî,Çл»µ½"¸ß¼¶"Ñ¡ÏîÒ³,ÔÚÎļþÁ÷·ÃÎʼ¶±ðÏÂÀÁбí¿òÖÐÑ¡Ôñ"ÒÑÆôÓÃÍêÈ«·ÃÎÊ"
¶þ.³õʼ»¯»·¾³
(1)Ìí¼ÓÎļþ×é
ALTER DATABASE [DBName] ADD FILEGROUP [FileGrp1] CONTAINS FILESTREAM
(2)Ìí¼Ó´æ·ÅÎļþµÄ·¾¶
ALTER DATABASE [DBName] ADD FILE(Name=N'filestream',FILENAME=N'C:\FileStream') TO FILEGROUP [FileGrp1]
ϵͳ½«×Ô¶¯´´½¨C:\FileStreamÎļþ¼Ð²¢ÔÚÆäÖÐдÈëfilestream.hdrÎļþ£¬¸ÃÎļþÊÇ FILESTREAMÈÝÆ÷µÄÍ·Îļþ²»ÄÜɾ³ý£¬Ò»¶¨ÒªÈ·±£ÔÚÔËÐиÃÓï¾ä֮ǰC:\FileStream²¢²»´æÔÚ¡£
×¢Òâ:Îļþ×é±ØÐ붨ÒåÔÚNTFS¸ñʽ·ÖÇøϵĴÅÅÌ,²¢ÇÒÐèÒªÖ¸Ïò±¾µØÎļþϵͳλÖÃÉÏ,²»ÔÊÐíÖ¸ÏòÍøÂçµØÖ·network addressable storage (NAS),³ý·Çͨ¹ý iSCSI½«NASÉ豸ÉèÖÃΪ±¾µØNFS¾í
ÔÎÄ(the DBA must define a database filegroup that ties an NTFS file system location to a SQL Server database. Note that the filegroup needs to point to a local file system location; filestreams can't live on a remote server or a network addressable storage (NAS) devices unless the NAS device is presented as a local NFS volume via iSCSI)
ÈçÊý¾Ý¿â֮ǰ´Óδ±¸·Ý¹ý,ÔÚÖ´ÐÐÒÔÉÏÓï¾äʱ»áÌáʾÐëÏȱ¸·ÝLOG
Èý.Ä£Äâ²âÊÔ
(1)½¨±í
CREATE TABLE FileStreamTest
(
ID uniqueidentifier ROWGUID NOT NULL UNIQUE DEFAULT NewID(),
FilesName varbinary(max) FILESTREAM NULL
)
FILESTREAM_ON [FileGrp1] --ָʾ´æ´¢µ½ÄÄÒ»¸öÎļþÁ÷
*Èç¹ûÒ»¸ö±íҪʹÓÃÎļþÁ÷,Ôò±ØÐëÓÐÒ»
Ïà¹ØÎĵµ£º
ÎÒÃǶ¼ÖªµÀÔÚOracleÖÐÿÌõSQLÓï¾äÔÚÖ´ÐÐ֮ǰ¶¼ÐèÒª¾¹ý½âÎö£¬ÕâÀïÃæÓÖ·ÖΪÈí½âÎöºÍÓ²½âÎö¡£ÔÚOracleÖдæÔÚÁ½ÖÖÀàÐ͵ÄSQLÓï¾ä£¬Ò»ÀàΪ
DDLÓï¾ä£¨Êý¾Ý¶¨ÒåÓïÑÔ£©£¬ËûÃÇÊÇ´ÓÀ´²»»á¹²ÏíʹÓõģ¬Ò²¾ÍÊÇÿ´ÎÖ´Ðж¼ÐèÒª½øÐÐÓ²½âÎö¡£»¹ÓÐÒ»Àà¾ÍÊÇDMLÓï¾ä£¨Êý¾Ý²Ù×ÝÓïÑÔ£©£¬ËûÃÇ»á¸ù¾ ......
´´½¨Íâ¼üÔ¼Êø
CREATE TABLE order_sample
(
orderid int PRIMARY KEY,
cust_id int FOREIGN KEY REFERENCES cuts_sample(cust_id) ON DELETE NO CASCADE
)
ON DELETE--ÓÃÓÚ¿ØÖƳ¢ÊÔɾ³ýÍâ¼üÏà¹ØÁªµÄÖ÷±íÖ¸ÏòÐÐʱ²ÉÈ¡µÄ²Ù×÷
-NO ACTION
ɾ³ýÍâ¼üÏà¹ØÁªµÄÖ÷±íÖ¸ÏòÐÐʱ£¬±¨´í
-CASCADE
ɾ³ýÍâ¼üÏà¹ØÁªµÄÖ÷±íÖ¸ÏòÐÐʱ ......
SQL×¢ÈëÊÇÄ¿Ç°±È½Ï³£¼ûµÄÕë¶ÔÊý¾Ý¿âµÄÒ»ÖÖ¹¥»÷·½Ê½¡£ÔÚÕâÖÖ¹¥»÷·½Ê½ÖУ¬¹¥»÷Õ߻ὫһЩ¶ñÒâ´úÂë²åÈëµ½×Ö·û´®ÖС£È»ºó»áͨ¹ý¸÷ÖÖÊֶν«¸Ã×Ö·û´®´«µÝµ½SQLServerÊý¾Ý¿âµÄʵÀýÖнøÐзÖÎöºÍÖ´ÐС£Ö»ÒªÕâ¸ö¶ñÒâ´úÂë·ûºÏSQLÓï¾äµÄ¹æÔò£¬ÔòÔÚ´úÂë±àÒëÓëÖ´ÐеÄʱºò£¬¾Í²»»á±»ÏµÍ³Ëù·¢ÏÖ¡£Óɴ˿ɼûSQL×¢Èëʽ¹¥»÷µÄΣº¦ÊǺܴóµÄ£¬ÄÇô ......
¿´µ½±ðÈËÔÚÂÛ̳µÄÌáÎÊ£º
Ò»¸ö±íµÄЧÂÊÎÊÌâ
½ñÌìÅöµ½2Õűí
1ÕÅ ÓÐ×Ö¶Î
±íAÓÐ
jtbh(¼ÒÍ¥±àºÅ) hzxm(»§Ö÷ÐÕÃû) hnbh(»§ÄÚ×î´ó±àºÅ)
1000 ÕÅÈý 03
1001 ÕÔÁù..........................
±í ......
1.¹ØÓÚÊý¾Ý¿â¹¹¼ÜÌåϵ
¢Ù±í¿Õ¼äµÄ¼à¿ØÊÇÒ»¸öÖØÒªµÄÈÎÎñ£¬ÎÒÃDZØÐëʱ¿Ì¹ØÐıí¿Õ¼äµÄÉèÖã¬ÊÇ·ñÂú×ãÏÖÔÚÓ¦
ÓõÄÐèÇó£¬ÒÔϵÄÓï¾ä¿ÉÒÔ²éѯµ½±í¿Õ¼äµÄÏêϸÐÅÏ¢¡£
SQL code
SELECT TABLESPACE_NAME,
INITIAL_EXTENT,
NEXT_EXTENT,
&nb ......