SQL Server 資料庫建立基礎練習(二)

2021-10-07 06:13:35 字數 742 閱讀 2957

--使用主資料庫

use master

go--判斷當前資料庫是否存在,存在則刪除

ifexists

(select

*from sys.

databases

where name =

'資料庫名'

)drop

database digitalproductshop

go--建立資料庫

create

database 資料庫名

go--使用建立的資料庫

use 資料庫名

go--判斷當前資料庫中是否存在建立的表,存在則刪除

ifexists

(select

*from sys.objects where name =

'表名1'

)drop

table 表名1

ifexists

(select

*from sys.objects where name =

'表名2'

)drop

table 表名2

go--建立表

create

table 表名1

( 表的內容

)create

table 表名2

( 表的內容

)go

要點:

1、多表建立與單錶建立區別不大。(不涉及約束的情況下,這個以後再說)

SQL Server建立資料庫

建立資料庫的基本語句 create database 資料庫名稱 create database studentdb onprimary 主資料檔案 name student data,資料檔案邏輯名稱 filename c db student data.mdf 資料檔案物理名稱 size 3mb...

建立SQL Server資料庫

建立sql server資料庫 1 以介面方式建立資料庫 下面在sql server management studio中建立資料庫 db database 具體操作步驟如下。1 啟動sql server management studio,並連線到sql server 2012中的資料庫。2 滑鼠...

SQL Server 建立資料庫

建立資料庫有兩種方式 方式1 圖形化介面建立 1.滑鼠右擊 資料庫 然後點選新建資料庫 2.設定常規選項卡 2.1 給資料庫命名,一般多個單詞要用下劃線連線,不建議用空格,如test db。2.2 所有者 預設即為當前伺服器的administrator,可以點選 把sa也加進來,很簡單不做截圖了。2...