MS SQL Server
  Home arrow MS SQL Server arrow 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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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


    (Page 1 of 3 )

    Transact-SQL is central to the use of Microsoft SQL Server. All applications that communicate with SQL Server do so by sending Transact-SQL statements to the server, regardless of an application's user interface.It is trivial that we master some of the basics T-SQL, which you will be using quite often as programmers in either building new applications or modifying and supporting existing ones. Today we will see how to alter or modify existing databases and tables and also examine some drop statements.

    The Alter Statement

    Sometimes, in fact far more often than we would like, we get requests to change a table rather than recreate it. Similarly, need may arise to change the file size, its location or add some new features to our database. This is where our ALTER statement comes in.

     ALTER
    <OBJECT type="">
    <
    OBJECT>



    The above syntax is pretty much the bare bone structure on which we build our syntax to various complex ALTER issues, which we will encounter in real time coding.

    ALTER DATABASE provides the ability to change the database name, filegroup names, and the logical names of data files and log files. Let’s get right into our job by taking a look at how to change our database. In our example below we actually make a couple of changes just so that we can see the effect in our result and how the syntax works. The trickiest part about ALTER statement is remembering what already exists. Having said this let us take a look at the Customers database which we had created in the very first part of this tutorial. Let us look at it again to examine what we had created by using the command below.

    EXCEC sp_helpdb Customers



    Name db_size Owner dbid Created Status Compatibility
    Customers 20MB 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 Field Filename Filegroup Size MaxSize Growth Usage
    Customers 1 ‘C:\Program Files\Microsoft SQL Server \MSSQL\data\Customerdata.mdf’, PRIMARY 10240 KB 51200 KB 5120 KB Data
    Only.
    Customer Log 2 ‘C:\Program Files\Microsoft SQL Server \MSSQL\data\Customelog.ldf’,
    NULL 5120 KB 25600 KB 5210 KB LOG ONLY.


    Now let us say we want to change things a bit. A current database is only 20MB in, say we want to import large amount of data from another database. Since we have Autogrowth turned on; SQL Server would automatically grow as we start importing data at a rate of 5 MB each time. But if you were inserting 100MB of data, then the SQL server would have to deal with that relocation at least 16 times (at 25, 30, 35 MB etc.) this is really a lot of work on the server. Since we know we are going to add some 100MB data, we would do so easily using ALTER DATABASE command.

    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...





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