zoukankan      html  css  js  c++  java
  • Part 2 Creating, altering and dropping a database

    A SQL Server database can be created, altered and dropped
    1. Graphically using SQL Server Management Studio (SSMS) or
    2. Using a Query

    To create the database graphically
    1. Right Click on Databases folder in the Object explorer
    2. Select New Database
    3. In the New Database dialog box, enter the Database name and click OK.


    To Create the database using a query
    Create database DatabaseName


    Whether, you create a database graphically using the designer or, using a query, the following 2 files gets generated.
    .MDF file - Data File (Contains actual data)
    .LDF file - Transaction Log file (Used to recover the database)


    To alter a database, once it's created 
    Alter database DatabaseName Modify Name = NewDatabaseName


    Alternatively, you can also use system stored procedure
    Execute sp_renameDB 'OldDatabaseName','NewDatabaseName'


    To Delete or Drop a database
    Drop Database DatabaseThatYouWantToDrop


    Dropping a database, deletes the LDF and MDF files.


    You cannot drop a database, if it is currently in use. You get an error stating - Cannot drop database "NewDatabaseName" because it is currently in use. So, if other users are connected, you need to put the database in single user mode and then drop the database.
    Alter Database DatabaseName Set SINGLE_USER With Rollback Immediate


    With Rollback Immediate option, will rollback all incomplete transactions and closes the connection to the database.

  • 相关阅读:
    cdoj1325卿学姐与基本法
    HUAS 1476 不等数列(DP)
    BZOJ 1818 内部白点(离散化+树状数组)
    BZOJ 1816 扑克牌(二分)
    BZOJ 1801 中国象棋(DP)
    BZOJ 1791 岛屿(环套树+单调队列DP)
    BZOJ 1797 最小割(最小割割边唯一性判定)
    BZOJ 1789 Y形项链(思维)
    BZOJ 1787 紧急集合(LCA)
    BZOJ 1786 配对(DP)
  • 原文地址:https://www.cnblogs.com/gester/p/4866255.html
Copyright © 2011-2022 走看看