SQL創(chuàng)建數(shù)據(jù)庫(kù) Visual Studio中如何新建SQL Server數(shù)據(jù)庫(kù)項(xiàng)目?
Visual Studio中如何新建SQL Server數(shù)據(jù)庫(kù)項(xiàng)目?在Visual Studio中創(chuàng)建新的SQL Server數(shù)據(jù)庫(kù)項(xiàng)目的步驟如下。1.單擊文件菜單下的新建,然后選擇項(xiàng)目選項(xiàng)。2.接下
Visual Studio中如何新建SQL Server數(shù)據(jù)庫(kù)項(xiàng)目?
在Visual Studio中創(chuàng)建新的SQL Server數(shù)據(jù)庫(kù)項(xiàng)目的步驟如下。
1.單擊文件菜單下的新建,然后選擇項(xiàng)目選項(xiàng)。
2.接下來(lái),在新建項(xiàng)目界面中,選擇SQL Server選項(xiàng),然后選擇SQL Server數(shù)據(jù)庫(kù)項(xiàng)目。
3.完成的數(shù)據(jù)庫(kù)項(xiàng)目如下圖所示,沒(méi)有任何文件,需要手動(dòng)導(dǎo)入。
4.接下來(lái),右鍵單擊選擇數(shù)據(jù)項(xiàng)名稱,然后選擇導(dǎo)入以下數(shù)據(jù)庫(kù)的選項(xiàng)。
5.在彈出的導(dǎo)入數(shù)據(jù)庫(kù)界面中,讓 設(shè)置數(shù)據(jù)源的庫(kù)名。
6.導(dǎo)入后,數(shù)據(jù)庫(kù)項(xiàng)目文件夾下有更多的文件夾,如表和視圖。
如何使用SQL代碼創(chuàng)建數(shù)據(jù)庫(kù)?
創(chuàng)建數(shù)據(jù)庫(kù)和表有兩種方法:
第一,可視化操作
1.創(chuàng)建數(shù)據(jù)庫(kù)
右鍵單擊選定的數(shù)據(jù)庫(kù),在出現(xiàn)的對(duì)話框中選擇“新建數(shù)據(jù)庫(kù)”,然后在“新建”對(duì)話框中填寫(xiě)數(shù)據(jù)庫(kù)的名稱。
創(chuàng)建數(shù)據(jù)表
右鍵單擊數(shù)據(jù)庫(kù)下的表,在出現(xiàn)的對(duì)話框頂部會(huì)出現(xiàn)一個(gè)新表選項(xiàng)。新對(duì)話框有三列:列名、數(shù)據(jù)類型和允許的空值。在這里,您可以添加表格的列,添加列后保存Ctrl,或者單擊頂部的保存,填寫(xiě)表格名稱并確認(rèn)以創(chuàng)建表格。是的。
二、使用SQL語(yǔ)句創(chuàng)建
1.創(chuàng)建數(shù)據(jù)庫(kù)創(chuàng)建數(shù)據(jù)庫(kù)stuDB - stuDB是數(shù)據(jù)庫(kù)的名稱。
On primary -默認(rèn)情況下,它屬于主文件組,可以省略。
(
/*-數(shù)據(jù)文件的具體描述-*/
NamestuDB_data,-主數(shù)據(jù)文件的邏輯名稱
Filenamed : studb _,-主數(shù)據(jù)文件的物理路徑和名稱。
Size5mb,-主數(shù)據(jù)文件的初始大小。
Maxsize100mb,-主數(shù)據(jù)文件的最大增長(zhǎng)。
Filegrowth15% -主數(shù)據(jù)文件的增長(zhǎng)率
)
log in
(
/*-日志文件的具體描述,各參數(shù)的含義同上-*/
namestuDB_log,
The file name is :stuDB_log.ldf,
size2mb,
File growth of 1mb
)
-2.創(chuàng)建數(shù)據(jù)表
使用StuDB -使用數(shù)據(jù)庫(kù)(在數(shù)據(jù)庫(kù)下建立一個(gè)表)
go to
Select * from sysobjects where name stumarks-query whether this table already exists in the database.
如果表格存在,刪除它。如果不存在,就不要執(zhí)行這句話。
Create Table Tag-Tag is the name of the table.
(
Exam no int identity (1,1) primary key,-column name data type constraint
Stunochar (6) not Null,-列名數(shù)據(jù)類型是否允許插入空值?
writtenExam int不為空,
LabExam int不為空
)
go to
-其中列屬性