±¾Ìû×îºóÓÉ ÁõÔóÓî ÓÚ 2023-1-15 14:17 ±à¼
ÏȾöÌõ¼þ¼ÌÐø֮ǰ£¬Çë²é¿´ÒÔÏÂËùÓÐÏȾöÌõ¼þ£º Èç¹ûÒª½«Êý¾Ý¿â´ÓÒ»¸öʵÀýÒƵ½ÁíÒ»¸öʵÀý£¬Ôò±ØÐëÏȽ«Êý¾Ý¿âÓëÈκÎÏÖÓÐ SQL ʵÀý·ÖÀë¡£ Èç¹û³¢ÊÔ¸½¼Óδ·ÖÀëµÄÊý¾Ý¿â£¬»á·µ»Ø´íÎó¡£ ¸½¼ÓÊý¾Ý¿âʱ£¬Êý¾Ý¿âµÄËùÓÐÊý¾ÝÎļþ¶¼±ØÐë¿ÉÓᣠͨ³££¬¶ÔÓÚÊý¾ÝÎļþ£¬ÕâЩÎļþµÄÀ©Õ¹ÃûΪ .mdf »ò ndf£»¶ÔÓÚÊÂÎñÈÕÖ¾Îļþ£¬ÔòÀ©Õ¹ÃûΪ .ldf¡£ ´ËÍ⣬FILESTREAM Êý¾ÝµÄÈκÎÎļþ×鶼±ØÐë´æÔÚ²¢ÇÒ¿ÉÓᣠÈç¹ûÈκÎÊý¾ÝÎļþµÄ·¾¶²»Í¬ÓÚÊ״δ´½¨Êý¾Ý¿â»òÉϴθ½¼ÓÊý¾Ý¿âʱµÄ·¾¶£¬Ôò±ØÐëÖ¸¶¨ÎļþµÄµ±Ç°Â·¾¶¡£ Êý¾Ý¿âÒýÇæ·þÎñÕÊ»§±ØÐë¾ßÓжÁÈ¡ÆäÐÂλÖÃÖеÄÎļþµÄȨÏÞ¡£ Èç¹ûÔÚÄ㸽¼ÓÊý¾Ý¿âʱ£¬MDF ºÍ LDF ÎļþλÓÚ²»Í¬Ä¿Â¼£¬²¢ÇÒÆäÖÐÒ»Ìõ·¾¶°üº¬ \\?\GlobalRoot£¬Ôò¸Ã²Ù×÷½«Ê§°Ü¡£
¶ÔÓÚ±¸·ÝºÍ»¹Ô£¬½¨Ò鲻ҪʹÓ÷ÖÀëÔÙ¸½¼Ó²Ù×÷¡£ ·ÖÀëÒª´Ó SQL Server Íⲿ±¸·ÝµÄÎļþʱ£¬Ã»ÓÐÊÂÎñÈÕÖ¾±¸·Ý»òʱ¼äµã»¹Ô¿ÉÓá£
ȨÏÞÐèÒª CREATE DATABASE¡¢CREATE ANY DATABASE »ò ALTER ANY DATABASE ȨÏÞ¡£ ʹÓà SQL Server Management Studio (SSMS)Òƶ¯Êý¾Ý¿â֮ǰÈç¹ûÒªÒƶ¯Êý¾Ý¿â£¬ÇëÔÚ½«ËüÓëÆäÏÖÓÐ SQL Server ʵÀý·ÖÀë֮ǰ£¬Ê¹Óá°Êý¾Ý¿âÊôÐÔ¡±Ò³²é¿´ÓëÊý¾Ý¿â¹ØÁªµÄÎļþ¼°Æ䵱ǰλÖᣠÔÚSQL Server Management Studio ¶ÔÏó×ÊÔ´¹ÜÀíÆ÷ÖУ¬Á¬½Óµ½SQL ServerÊý¾Ý¿âÒýÇæµÄʵÀý£¬È»ºóÕ¹¿ªÊµÀý¡£ Õ¹¿ª ¡°Êý¾Ý¿â¡± £¬²¢Ñ¡ÔñÒª·ÖÀëµÄÓû§Êý¾Ý¿âµÄÃû³Æ¡£ ÓÒ¼üµ¥»÷Êý¾Ý¿âÃû³Æ£¬²¢Ñ¡Ôñ¡°ÊôÐÔ¡±¡£ Ñ¡Ôñ¡°Îļþ¡±Ò³£¬²¢²é¿´¡°Êý¾Ý¿âÎļþ:¡±±íÖеÄÌõÄ¿¡£
·ÖÀë¡¢Òƶ¯ºÍ¸½¼Ó֮ǰ£¬ÇëÎñ±Ø¿¼ÂÇÓëÊý¾Ý¿â¹ØÁªµÄËùÓÐÎļþ¡£ È»ºó£¬¼ÌÐøÖ´ÐÐÏÂÒ»²¿·ÖÖеķÖÀë¡¢Îļþ¸´Öƺ͸½¼ÓÊý¾Ý¿â²½Öè¡£ ¸½¼ÓÊý¾Ý¿âÔÚSQL Server Management Studio¶ÔÏó×ÊÔ´¹ÜÀíÆ÷ÖУ¬Á¬½Óµ½SQL ServerÊý¾Ý¿âÒýÇæµÄʵÀý£¬È»ºóÑ¡ÔñÔÚ SSMS ÖÐÕ¹¿ª¸ÃʵÀýÊÓͼ¡£ ÓÒ¼üµ¥»÷¡°Êý¾Ý¿â¡±£¬È»ºóÑ¡Ôñ¡°¸½¼Ó¡±¡£ ÔÚ¡°¸½¼ÓÊý¾Ý¿â¡±¶Ô»°¿òÖУ¬ÈôÒªÖ¸¶¨Òª¸½¼ÓµÄÊý¾Ý¿â£¬ÇëÑ¡Ôñ¡°Ìí¼Ó¡±¡£ ÔÚ¡°¶¨Î»Êý¾Ý¿âÎļþ¡±¶Ô»°¿òÖУ¬Ñ¡ÔñÊý¾Ý¿âËùÔÚµÄλÖã¬È»ºóÕ¹¿ªÄ¿Â¼Ê÷À´²éÕÒÊý¾Ý¿âµÄ .mdf Îļþ²¢½«ÆäÑ¡ÖУ¬ÀýÈ磺 C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_Data.mdf
¡°Òª¸½¼ÓµÄÊý¾Ý¿â¡±
ÏÔʾËùÑ¡Êý¾Ý¿âµÄÓйØÐÅÏ¢¡£ <ÎÞÁбêÌâ>
ÏÔʾһ¸öͼ±ê£¬ÓÃÒÔָʾ¸½¼Ó²Ù×÷µÄ״̬¡£ ¡°×´Ì¬¡±ËµÃ÷ÖнéÉÜ¿ÉÄܵÄͼ±ê¡£ MDF ÎļþλÖÃ
ÏÔʾѡ¶¨ MDF ÎļþµÄ·¾¶ºÍÎļþÃû¡£ Database Name
ÏÔʾÊý¾Ý¿âµÄÃû³Æ¡£ ¸½¼ÓΪ
¸ù¾ÝÐèÒª£¬¿ÉÒÔÖ¸¶¨Òª¸½¼ÓÊý¾Ý¿âµÄÆäËûÃû³Æ¡£ ËùÓÐÕß
ÌṩÊý¾Ý¿â¿ÉÄÜËùÓÐÕßµÄÏÂÀÁÐ±í£¬Äú¿ÉÒÔ¸ù¾ÝÐèÒª´ÓÆäÖÐÑ¡ÔñÆäËûËùÓÐÕß¡£ Status
ÏÔʾϱíÖÐÏàÓ¦µÄÊý¾Ý¿â״̬£º
ͼ±ê | ״̬Îı¾ | ˵Ã÷ | £¨ÎÞͼ±ê£© | £¨ÎÞÎı¾£© | ´Ë¶ÔÏóµÄ¸½¼Ó²Ù×÷ÉÐδÆô¶¯»òÕß¿ÉÄܹÒÆð¡£ ÕâÊÇ´ò¿ª¸Ã¶Ô»°¿òʱµÄĬÈÏÖµ¡£ | ÂÌÉ«µÄÓÒÏòÈý½ÇÐÎ | ÕýÔÚ½øÐÐ | ÒÑÆô¶¯¸½¼Ó²Ù×÷£¬µ«ÊǸòÙ×÷δÍê³É¡£ | ÂÌÉ«µÄÑ¡Öбê¼Ç | Success | Òѳɹ¦¸½¼Ó¸Ã¶ÔÏó¡£ | °üº¬°×É«Ê®×ÖÐεĺìɫԲȦ | ´íÎó | ¸½¼Ó²Ù×÷Óöµ½´íÎó£¬Î´³É¹¦Íê³É¡£ | °üº¬×ó¡¢ÓÒÁ½¸öºÚÉ«ÏóÏÞºÍÉÏ¡¢ÏÂÁ½¸ö°×É«ÏóÏÞµÄԲȦ | ÒÑÍ£Ö¹ | ÓÉÓÚÄãÍ£Ö¹Á˸½¼Ó²Ù×÷£¬¸Ã²Ù×÷δ³É¹¦Íê³É¡£ | °üº¬Ò»¸öÖ¸ÏòÄæʱÕë·½ÏòµÄÇúÏß¼ýÍ·µÄԲȦ | Òѻعö | ¸½¼Ó²Ù×÷Òѳɹ¦£¬µ«ÒѶÔÆä½øÐлعö£¬ÒòΪÔÚ¸½¼ÓÆäËû¶ÔÏóµÄ¹ý³ÌÖгöÖÁË´íÎó¡£ |
ÏûÏ¢
ÏÔʾ¿ÕÏûÏ¢»ò¡°ÕÒ²»µ½Îļþ¡±³¬Á´½Ó¡£ Ìí¼Ó
²éÕÒ±ØÐèµÄÖ÷Êý¾Ý¿âÎļþ¡£ Ñ¡Ôñ .mdf Îļþʱ£¬¾Í»áÔÚ¡°Òª¸½¼ÓµÄÊý¾Ý¿â¡±Íø¸ñµÄÏàÓ¦×Ö¶ÎÖÐ×Ô¶¯Ìî³äºÏÊʵÄÐÅÏ¢¡£ ɾ³ý
´Ó ¡°Òª¸½¼ÓµÄÊý¾Ý¿â¡± Íø¸ñÖÐɾ³ýÑ¡¶¨Îļþ¡£ ¡°<database_name>¡±Êý¾Ý¿âÏêϸÐÅÏ¢
ÏÔʾҪ¸½¼ÓµÄÎļþµÄÃû³Æ¡£ ÔʼÎļþÃû ÏÔʾÊôÓÚÊý¾Ý¿âµÄÒѸ½¼ÓÎļþµÄÃû³Æ¡£ ÎļþÀàÐÍ
ָʾÎļþÀàÐÍ£¬¼´ ¡°Êý¾Ý¡± »ò ¡°ÈÕÖ¾¡± ¡£ µ±Ç°Îļþ·¾¶
ÏÔʾËùÑ¡Êý¾Ý¿âÎļþµÄ·¾¶¡£ ¿ÉÒÔÊÖ¶¯±à¼¸Ã·¾¶¡£ ÏûÏ¢
ÏÔʾ¿ÕÏûÏ¢»ò ¡°ÕÒ²»µ½Îļþ¡± ³¬Á´½Ó¡£
ʹÓà Transact-SQLÒƶ¯Êý¾Ý¿â֮ǰÈç¹ûÒªÒƶ¯Êý¾Ý¿â£¬ÇëÔÚ½«ËüÓëÆäÏÖÓÐ SQL Server ʵÀý·ÖÀë֮ǰ£¬Ê¹Óà sys.database_files ϵͳĿ¼ÊÓͼ²é¿´ÓëÊý¾Ý¿â¹ØÁªµÄÎļþ¼°Æ䵱ǰλÖᣠÔÚSQL Server Management StudioÖУ¬Ñ¡Ôñ¡°Ð½¨²éѯ¡±ÒÔ´ò¿ª²éѯ±à¼Æ÷¡£ ½«ÒÔÏ Transact-SQL ½Å±¾¸´ÖƵ½²éѯ±à¼Æ÷£¬È»ºóÑ¡Ôñ¡°Ö´ÐС±¡£ ´Ë½Å±¾ÏÔʾÎïÀíÊý¾Ý¿âÎļþµÄλÖᣠͨ¹ý·ÖÀë/¸½¼ÓÀ´Òƶ¯Êý¾Ý¿âʱ£¬ÇëÎñ±Ø¿¼ÂÇËùÓÐÎļþ¡£ USE [database_name] GO SELECT type_desc, name, physical_name from sys.database_files;
·ÖÀë¡¢Òƶ¯ºÍ¸½¼Ó֮ǰ£¬ÇëÎñ±Ø¿¼ÂÇÓëÊý¾Ý¿â¹ØÁªµÄËùÓÐÎļþ¡£ È»ºó£¬¼ÌÐøÖ´ÐÐÏÂÒ»²¿·ÖÖеķÖÀë¡¢Îļþ¸´Öƺ͸½¼ÓÊý¾Ý¿â²½Öè¡£ ¸½¼ÓÊý¾Ý¿âÁ¬½Óµ½ Êý¾Ý¿âÒýÇæ¡£ ÔÚ±ê×¼À¸ÉÏ£¬Ñ¡Ôñ¡°Ð½¨²éѯ¡±¡£ ʹÓôø FOR ATTACH ×Ó¾äµÄ [color=var(--theme-hyperlink)] CREATE DATABASE Óï¾ä¡£ ½«ÒÔÏÂʾÀý¸´ÖƲ¢Õ³Ìùµ½²éѯ´°¿ÚÖУ¬È»ºóÑ¡Ôñ¡°Ö´ÐС±¡£ ±¾Ê¾Àý¸½¼Ó AdventureWorks2019 Êý¾Ý¿âµÄËùÓÐÎļþ£¬²¢½«Êý¾Ý¿âÖØÃüÃûΪ MyAdventureWorks¡£ CREATE DATABASE MyAdventureWorks ON (FILENAME = 'C:\MySQLServer\AdventureWorks_Data.mdf'), (FILENAME = 'C:\MySQLServer\AdventureWorks_Log.ldf') FOR ATTACH; ÄãµÄÊý¾Ý¿â¿ÉÄÜÓÐÆäËûÊý¾ÝÎļþ£¨Í¨³£ÊÇ .mdf »ò .ndf£©£¬²¢ÇÒÐèÒªÔÚ CREATE DATABASE ... FOR ATTACH Óï¾äÖаüº¬ÆäËûÎļþ¡£ ´ËÍ⣬»¹±ØÐëÔÚÓï¾äÖаüº¬ FILESTREAM Êý¾ÝµÄÈκÎÎļþ×é¡£
|