01SqlServer資料庫管理與維護

2021-03-04 03:22:06 字數 3925 閱讀 1669

資料庫的安裝與配置

資料庫建立、刪除、備份、分離等

資料表的建立、刪除、修改

約束型別及建立,修改

一、概述:

1、專業術語:

sql:structured query language的縮寫,意思為結構化查詢語言。

sql server:是乙個關聯式資料庫管理系統

2、發展歷程:

2023年:微軟與sybase共同開發,執行於os/2平台。

2023年:sql server 4.2

2023年:microsoft與sybase在資料庫開發方面的合作中止。

2023年:sql server 6.05

2023年:sql server 6.5

2023年:sql server 7.0

2023年:sql server 2000

2023年:sql server 2005

2023年:sql server 2008

3、如何安裝:

1)、microsoft sql server 2008 常見版本:

sql server 2008 enterprise 版本

sql server 2008 developer 版本

sql server 2008 express 版本

2)、系統要求:

enterprise:windows 2003、2008、2008 r2

developer:windows xp、vista、7、2003、2008、2008 r2

.*** framework 3.5 sp1

inter*** information services

4、儲存結構:

1)、邏輯儲存結構

表,試圖等各種資料庫物件組成

2)、物理儲存結構

主資料庫檔案

次資料庫檔案

日誌檔案

二、資料庫操作:

1、建立資料庫:

1)、使用ide建立資料庫:

2)、使用sql建立資料庫:

create database [dbstudent] on primary

( name = 'dbstudent',

filename = 'd:\database\dbstudent.mdf' ,

size = 3072kb ,

maxsize = unlimited,

filegrowth = 1024kb

)log on

( name = 'dbstudent_log',

filename = 'd:\database\dbstudent.ldf' ,

size = 1536kb ,

maxsize = 2048gb ,

filegrowth = 10%)go

2、刪除資料庫:

1)、使用ide刪除資料庫:

2)、使用sql刪除資料庫:

if exists (select name from sys.databases where name = 'dbstudent')

drop database [dbstudent]

go3、備份及還原資料庫:

1)、備份的方式:

完全備份:是整個資料庫的乙個副本

差異備份:從上次完全備份後,資料庫所有變化的乙個副本

事務日誌備份:包含事務日誌的備份,它包括了資料庫中所發生的每個資料改動前後的乙個映象

資料庫檔案和檔案組備份:針對某乙個檔案或檔案組的備份

2)、使用ide備份及還原資料庫:

3)、使用計畫任務備份資料庫:

a)、使用計畫任務備份資料庫的條件:

啟動sql server **

正確並可執行的備份指令碼

分析備份的頻率

b)、sql指令碼

backup database [dbstudent] to disk = 'd:\db_student_2010_07_25.bak'

with noformat, noinit,skip, norewind, nounload,

name = '完整備份', description = '', stats = 10

gobackup database [dbstudent] to disk = n'd:\db_student_2010_07_25.bak'

with differential , noformat, noinit, skip, norewind, nounload,

name = '差異備份', description = '', stats = 10

gobackup log [dbstudent] to disk = n'd:\db_student_2010_07_25.bak'

with noformat, noinit, skip, norewind, nounload,

name = '事務日誌備份', description = '', stats = 10

go注:nchar 、nvarchar、ntext等資料型別的字首n來自sql-92標準中的national(unicode)資料型別。

unicode 常量使用 n 開頭來指定:n 'a unicode string '。

4、分離及附加資料庫:

1)、基本概念:

分離資料庫是指將資料庫從 sql server 例項中刪除;

附加資料庫是附加複製或分離的 sql server 資料庫。

2)、使用ide分離及附加資料庫:

三、資料表操作:

1、建立資料表:

1)、約束型別:

主鍵約束:唯一標誌表中的一行空值約束:限制列是否能夠輸入空值唯一值約束:對於約束的一列或多列在資料表中起到唯一標誌的作用預設值約束:在插入資料時,對未賦值的列初始乙個預設值

check約束:通過邏輯表示式,對行的完整性進行驗證

2)、使用ide建立資料表:

3)、使用sql建立資料表:

create table [dbo].[tstudentinfo]

([id] [uniqueidentifier] not null primary key,

[studentname] [varchar](50) null,

[studentidcard] [varchar](50) not null unique,

[studentage] [int] not null check ([studentage]>18 and [studentage]<150),

[isdelete] [bit] not null default 0

) 2、修改資料表:

1)、使用ide修改資料表:

2)、使用sql修改資料表:

alter table dbo.tstudentinfo

--drop constraint ck_tstudentinfo

--add constraint ck_tstudentinfo check (userage>18)

--add constraint df_tstudentinfo default 0 for (isdelete)

--add constraint uq_tstudentinfo unique (useridcard)

--add constraint pk_tstudentinfo primary key (id)

--alter column usertname not null

--alter column entrydate varchar(60)

--drop column entrydate

--rename column entrydate to endtryadd

--add entrydate datetime null

3、刪除資料表:

1)、使用ide刪除資料表:

2)、使用sql刪除資料表:

drop table student

SQL server資料庫總結筆記

建表的兩種方式 一 兒子,爸爸,爺爺式 包含式,屬於式 至少需要兩個表。經典案例 學校 班級 學生 建表訣竅 1 乙個物件 實體 乙個表 2 小表裡面有大表 主鍵 下級的小表包含上一級大表的主鍵,比如學生表裡面包含班級表的主鍵,班級表包含學校表的主鍵,學生表裡面沒有必要包含學校表的主鍵,不是不行,而...

SQLserver資料庫設計餐飲管理系統

遼寧工業大學 sql server資料庫設計實訓 報告 題目 餐飲管理系統 院 系 軟體學院 專業班級 電子商務 國際 學號學生姓名 指導教師 翟寶峰 教師職稱 副教授 起止時間 2011.09.03 2011.09.14 設計任務及評語 院 系 軟體學院教研室 軟體教研室 目錄第1章設計目的與要求...

sqlserver資料庫大型應用解決方案經驗總結

資料條數很少,資料內容也不大,則直接同步資料 資料條數很少,但是裡面包含大資料型別,比如文字,二進位制資料等,則先對資料進行壓縮然後再同步,從而減少網路頻寬的占用和傳輸所用的時間。資料條數很多,此時中介軟體會拿到造成資料變化的sql語句,然後對sql語句進行解析,分析其執行計畫和執行成本,並選擇是同...