MS SQL Server
  Home arrow MS SQL Server arrow Page 2 - Altering and Dropping Databases And Tables...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Altering and Dropping Databases And Tables In Microsoft SQL Server 2000, Part 3
By: Gayathri Gokul
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 31
    2003-10-10

    Table of Contents:
  • Altering and Dropping Databases And Tables In Microsoft SQL Server 2000, Part 3
  • The General Syntax
  • ALTER TABLE

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Altering and Dropping Databases And Tables In Microsoft SQL Server 2000, Part 3 - The General Syntax


    (Page 2 of 3 )

    ALTER DATABASE <database name>   ADD FILE([Name 
    ‘logical file name’ >,]         Filename = < ‘File Name’ >           [, Size 
    <
    Size in Megabytes or kilobytes>]           [, Maxsize = <Size in Megabytes or 
    kilobytes>]           [, Filegrowth  = <No of Megabytes or 
    kilobytes/percentage>][,…n]               [ TO FILEGROUP filegroup_name][ ADD 
    Log FILE     
    ([Name ‘logical file name’ >,]         Filename = < ‘File Name’ 
              [, 
    Size = <Size in Megabytes or kilobytes>]           [, Maxsize 
    <
    Size in Megabytes or kilobytes>]           [, Filegrowth  = <No of Megabytes or 
    kilobytes/percentage>])]          | REMOVE FILE <logical_file_name> [WITH 
    DELETE
    ]| ADD FILEGROUP <filegroup_name>| REMOVE FILEGROUP <filegroup_name >| 
    MODIFY FILE filespec >| MODIFY NAME = <new_dbname >| MODIFY FILEGROUP 
    <filegroup_name> {filegroup_property NAME = <new_filegroup_name >}| SET 
    optionspec > [ ,...] [ WITH termination > ]| COLLATE collation_name >}



    The reality in this case is that we will rarely be using all the above stuff, but since it was syntax definition did not want to cut it short.

    So after looking at all the boring stuff, now come to the exciting part, we need to expand our database to 100MB more. We do this by using a simple syntax given below:

    ALTER DATABASE Customers     MODIFY FILE       
     (NAME Customerdata,             SIZE =100MB)



    Now unlike when we created our database, SQL Server does not give us back the above two table of information, instead we get a non-verbose:

    The command(scompleted 
    successfully



    So how do you make sure if the changes we made have been updated to the database? We have to do it ourselves using the command below:

    EXCEC sp_helpdb Customers



    Name db_size Owner dbid Created Status Compatibility
    Customers 120MB sa 10 May 24, 2002 Status=online,
    Updateability=Read_write,
    UserAccess=MULTI_USER,
    Recovery =FULL
    Version=538, Collation=SQL_LATIN1_
    General_CP1_C1_AS,
    SQLSortOrder =52
    IsTornPageDetectionEnable,
    IsAutoCreateStatistics,
    IsAutoUpdateStatistics
    80


    And the following table: (Please note just giving you approximate file sizes, not exact figure).

    Home FieldField
      Field Filename Filegroup Size MaxSize Growth Usage
    Customers 1 ‘C:\Program Files\Microsoft SQL Server \MSSQL \data\Customerdata.mdf’, PRIMARY 10240 KB 102400KB 5120 KB Data
    Only.
    Customer Log 2 ‘C:\Program Files\Microsoft SQL Server \MSSQL \data\Customelog.ldf’, NULL 5120KB 25600 KB 5210KB LOG ONLY.


    One thing worth noting is that even though we exceed the pervious maximum size, we did not get an error. This is because we have explicitly increased the size. Another thing to note is that our MaxSize was only increased to our new explicitly specified value, leaving no space for any file growth. If only we had done things our original way, by just allowing SQL Server auto expand itself, then our import would have blown up in the middle due to size restriction. Things pretty much work the same way for any common database-level modification you’ll make. The permutations are endless. The more complex filegroup modification is outside the scope of this article. But just giving a short example

    ALTER DATABASE Customers      ADD FILE       
     (NAME =  ‘Emp_File’,           FILENAME ‘C:Program FilesMicrosoft SQL 
    ServerMSSQLdataEMP_File
    .mdf’,             SIZE =4MB,               MAXSIZE 
    100MB,                 FILEGROWTH =2            )



    Adds a file Emp_File of size 4MB to the database Customers. Similarly we can add a file group to the existing database. Below we add filegroup fgrp1 to the existing Customer:

    ALTER DATABASE Customers      ADD FILEGROUP fgrp1

    So we have seen how to alter an existing database by increasing its size, adding a file and even a filegroup. Now we will move into altering a table.

    More MS SQL Server Articles
    More By Gayathri Gokul


     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT