SQL簡略教程【種子張】

來源:互聯網
上載者:User

1.建立資料庫
create database bvtc_db       --資料庫名
  on primary    --在主檔案組中指定檔案.預設為第一個檔案
(
name=''bvtc_db_data'',       --指定主要資料檔案名稱(邏輯名)
filename=''F:bvtc_db_data.mdf'',  --指定主檔案的作業系統檔案名稱和路徑.必須為安裝SQL伺服器的電腦上的檔案夾.(物理檔案名稱)
size=5MB,     --初始容量大小
maxsize=20MB,  --最大容量
filegrowth=20%   --檔案增長量(預設時為10%,不能超過maxsize)
)
  log on    --指定建立資料庫的交易記錄檔,副檔名為:ldf
(name=''bvtc_db_log'',  -- 指定交易記錄檔邏輯名稱
filename=''F:bvtc_db_log.ldf'',--指定物理檔案名稱
size=10MB,   --初始容量大小
filegrowth=2MB   --檔案增長量
)
collate Chinese_PRC_CI_AS   --指定預設排序方法
GO
2.查看資料庫資訊
除了直接查看資料庫屬性外,我們以用系統預存程序式sp_helpdb:
exec sp_helpdb ''bvtc_db''    --exec為執行語句,bvtc_db為資料庫名
3.管理資料庫
    (1)開啟或切換資料庫: use bvtc_db
    (2)修改資料庫容量:可以直接在資料庫屬性裡改,也可以用如下語句:
    use bvtc_db
       go
       alter database bvtc_db
        modify file
       (
         name=bvtc_db_data,--同樣也可以是交易記錄檔(bvtc_db_log)
         size=20MB
        )
     (3)縮減資料庫容量:
        方法1:右擊資料庫名-所有任務-收縮資料庫
        方法2:
              dbcc shrinkdatabase(database_name[,new_size,[,''masteroverride'']])
          執行個體:
                use bvtc_db
                go
                exec sp_dboption ''bvtc_db'',''single user'',TRUE  --在縮減資料庫前要將其設為單一使用者模式.
       

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.