{"id":103,"date":"2017-09-18T21:00:27","date_gmt":"2017-09-18T21:00:27","guid":{"rendered":"http:\/\/www.manualsqlserver.com\/?p=103"},"modified":"2020-05-20T04:34:04","modified_gmt":"2020-05-20T04:34:04","slug":"alter-database-grupos-de-archivos","status":"publish","type":"post","link":"https:\/\/manualsqlserver.com\/?p=103","title":{"rendered":"Alter Database &#8211; Grupos de archivos"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/manualsqlserver.com\/wp-content\/uploads\/2020\/05\/ManualSQL_ServiciosSQLGruposArchivosAlter.png\" alt=\"\" class=\"wp-image-1287\" width=\"270\" height=\"270\" srcset=\"https:\/\/manualsqlserver.com\/wp-content\/uploads\/2020\/05\/ManualSQL_ServiciosSQLGruposArchivosAlter.png 300w, https:\/\/manualsqlserver.com\/wp-content\/uploads\/2020\/05\/ManualSQL_ServiciosSQLGruposArchivosAlter-150x150.png 150w\" sizes=\"auto, (max-width: 270px) 100vw, 270px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Modificar una base de datos &#8211; manejo de grupos de archivos<\/strong><\/h1>\n\n\n\n<p>Los archivos de las bases de datos en SQL Server se agrupan en grupos de archivos (<a href=\"http:\/\/www.manualsqlserver.com\/?p=78\">Ver Post<\/a>), en este post aprenderemos como trabajar con los grupos de la base de datos.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Para modificar la base de datos y trabajar con grupos se puede:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong> Agregar:<\/strong>&nbsp; &nbsp; &nbsp;Alter database NombreBaseDatos &nbsp;add filegroup NombreGrupoNuevo<\/li><li><strong>Modificar:<\/strong>&nbsp; Alter database NombreBaseDatos modify filegroup NombreGrupo, &nbsp;las opciones posibles son cambiar el nombre y cambiar el grupo por defecto.<\/li><li><strong>Eliminar:<\/strong>&nbsp; Alter database NombreBaseDatos remove filegroup NombrerupoEliminar (debe estar vac\u00edo, es decir sin archivos.)<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Ejercicios<\/strong><\/h3>\n\n\n\n<p><strong>1. Creamos primero la base de datos<\/strong><\/p>\n\n\n\n<p>xp_create_subdir &#8216;C:\\BD&#8217;<br>go<br>xp_create_subdir &#8216;D:\\Data\\Respaldo&#8217;<br>go<br>Create Database SistemasE<br>on Primary<br>(Name=&#8217;S01&#8242;,Filename=&#8217;C:\\BD\\S01.mdf&#8217;, Size = 10MB, Maxsize= 200GB,<br>Filegrowth= 5MB),<br>(Name=&#8217;S02&#8242;,Filename=&#8217;D:\\Data\\S02.ndf&#8217;),<br>filegroup VENTAS<br>(Name=&#8217;S03&#8242;,Filename=&#8217;D:\\Data\\Respaldo\\S03.ndf&#8217;)<br>LOG ON<br>(Name=&#8217;L01&#8242;,Filename=&#8217;C:\\BD\\L01.ldf&#8217;)<br>go<\/p>\n\n\n\n<p><strong>2. Agregar grupos PERSONAL y FINANZAS<\/strong><\/p>\n\n\n\n<p>Alter database SistemasE add filegroup PERSONAL<br>Alter database SistemasE add filegroup FINANZAS<br>go<\/p>\n\n\n\n<p><strong>3. Ver los grupos<\/strong><\/p>\n\n\n\n<p>select * from sys.filegroups<br>go<\/p>\n\n\n\n<p><strong>4. Crear grupo PRESUPUESTO, darle consistencia al script y si existe el grupo no debe reportar error, en el script se ha incluido mensajes solamente para comprobar que el script funciona correctamente.<\/strong><\/p>\n\n\n\n<p>IF not exists (select * from sys.filegroups where name = &#8216;PRESUPUESTO&#8217;)<br>Begin<br>Alter database SistemasE add filegroup PRESUPUESTO<br>Print &#8216;Grupo creado&#8230;&#8217;<br>End<br>Else<br>Begin<br>Print &#8216;Grupo ya existe&#8230;&#8217;<br>End<br>go<\/p>\n\n\n\n<p><strong>El script sin mensajes es como sigue<\/strong><\/p>\n\n\n\n<p>IF not exists (select * from sys.filegroups where name = &#8216;PRESUPUESTO&#8217;)<br>Begin<br>Alter database SistemasE add filegroup PRESUPUESTO<br>End<br>go<\/p>\n\n\n\n<p><strong>4. Cambiar el nombre a un grupo<\/strong><\/p>\n\n\n\n<p>En la base de datos se ha agregado los grupos PERSONAL y FINANZAS, para cambiar el nombre del grupo PERSONAL a RECURSOSHUMANOS se debe escribir:<\/p>\n\n\n\n<p>Alter database SistemasE modify filegroup PERSONAL name = RECURSOSHUMANOS<\/p>\n\n\n\n<p><strong>5. Cambiar el grupo de archivos por defecto<\/strong><\/p>\n\n\n\n<p>Primero agregamos un archivo al grupo Finanzas<\/p>\n\n\n\n<p>alter database SistemasE<br>add file (Name=&#8217;Datos01&#8242;, Filename=&#8217;C:\\BD\\Datos01.ndf&#8217;),<br>(Name=&#8217;Datos02&#8242;, Filename=&#8217;C:\\BD\\Datos02.ndf&#8217;)<br>to filegroup Finanzas<br>go<\/p>\n\n\n\n<p><strong>6. Cambiar el nombre del grupo Finanzas por Bancos<\/strong><\/p>\n\n\n\n<p>alter database SistemasE modify filegroup Finanzas name = Bancos<br>go<\/p>\n\n\n\n<p><strong>7. Cambiar el grupo por defecto a Bancos<\/strong><\/p>\n\n\n\n<p>alter database SistemasE modify filegroup Bancos default<br>go<\/p>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br><ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-8212748961777604\" data-ad-slot=\"5919795031\"><\/ins><br><script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modificar una base de datos &#8211; manejo de grupos de archivos Los archivos de las bases de datos en SQL Server se agrupan en grupos de archivos (Ver Post), en este post aprenderemos como trabajar con los grupos de la base de datos.<\/p><p><a class=\"more-link btn\" href=\"https:\/\/manualsqlserver.com\/?p=103\">Seguir leyendo<\/a><\/p>\n","protected":false},"author":1,"featured_media":1287,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[98,101,53],"class_list":["post-103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-crearbd","tag-alter-database","tag-filegroup","tag-sqlserver","nodate","item-wrap"],"_links":{"self":[{"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=103"}],"version-history":[{"count":1,"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":1289,"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions\/1289"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=\/wp\/v2\/media\/1287"}],"wp:attachment":[{"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/manualsqlserver.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}