数据库的实现【笔记】
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                数据库的实现【笔记】
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            一、創(chuàng)建數(shù)據(jù)庫
1.簡單的方式
? create database 數(shù)據(jù)庫名
2.指定主文件和日志文件參數(shù)
? create database 數(shù)據(jù)庫名 on [primary]
?? (
??? name='數(shù)據(jù)庫邏輯名',??????????????? --數(shù)據(jù)庫名_data
??? filename='數(shù)據(jù)庫主文件(包括路徑)',--E:\第二期\第二章數(shù)據(jù)庫的實(shí)現(xiàn)\數(shù)據(jù)庫名_data.mdf
??? size=初始大小MB,?????????????? ?
??? maxsize=最大大小
??? filegrowth=文件增長率(可以指定MB或百分比
),
(
??? name='次要數(shù)據(jù)庫邏輯名',??????????????? --數(shù)據(jù)庫名_ndf
??? filename='次要數(shù)據(jù)庫主文件(包括路徑)',--E:\第二期\第二章數(shù)據(jù)庫的實(shí)現(xiàn)\數(shù)據(jù)庫名_ndf.ndf
)
log on
(
??? name='數(shù)據(jù)庫日志名',??????????????? --數(shù)據(jù)庫名_log
??? filename='數(shù)據(jù)
??? filegrowth=文件增長率(可以指定MB或百分比
)
3.刪除數(shù)據(jù)庫
?? drop database 數(shù)據(jù)名
4.判斷數(shù)據(jù)庫是否存在
? use master 數(shù)據(jù)庫?? --選擇master數(shù)據(jù)庫
?? go
?? if exists(select * from sysdatabases where name='數(shù)據(jù)庫名')
?? drop database 數(shù)據(jù)庫名
?? 注:sysdatabases 表是master數(shù)據(jù)庫中的表,此表保存了數(shù)據(jù)庫系統(tǒng)中所有的數(shù)據(jù)庫
二、表
1.創(chuàng)建表
??? create table 表名
?? (
??? 列名1 數(shù)據(jù)類型 not null,
??? 列名2 數(shù)據(jù)類型 null
???? //默認(rèn)為null
??? 列名3 整型 identity(種子,增量) not null --表示列
??? )
2.刪除表
?? drop table 表名
3.判斷表是否存在
?? if exists (select * from sysobjects where name='表名') drop table 表名
??? 注:sysobjects 是系統(tǒng)表,任何數(shù)據(jù)庫都存在該表,sysobjects保存了當(dāng)前數(shù)據(jù)庫中的所有的表
三、數(shù)據(jù)完整
?? 1.實(shí)體完整性:保證行不重復(fù),保證實(shí)體唯一
?? 2.域完整性:限制列數(shù)據(jù)的取值
?? 3.引用完整性:建立表和表之間的關(guān)系(實(shí)體之間的關(guān)系)
?? 4.用戶定義:用戶編寫邏輯
四、約束
?? 1.主鍵約束(primary key):實(shí)現(xiàn)實(shí)體完整性
?? 2.唯一約束(unique):實(shí)現(xiàn)域完整性
?? 3.默認(rèn)約束(default):實(shí)現(xiàn)域完整性
?? 4.檢查約束(check):實(shí)現(xiàn)域完整性
?? 5.外鍵約束(foreignkey):實(shí)現(xiàn)引用完整性
五、給表添加約束
?? alter table 表名
??? add constraint 約束名 約束類型 約束說明
? 1.添加主鍵約束
??? alter table 表名
??? add constraint PK_列名 primary key (列名)
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎
                        
                        
                        1.簡單的方式
? create database 數(shù)據(jù)庫名
2.指定主文件和日志文件參數(shù)
? create database 數(shù)據(jù)庫名 on [primary]
?? (
??? name='數(shù)據(jù)庫邏輯名',??????????????? --數(shù)據(jù)庫名_data
??? filename='數(shù)據(jù)庫主文件(包括路徑)',--E:\第二期\第二章數(shù)據(jù)庫的實(shí)現(xiàn)\數(shù)據(jù)庫名_data.mdf
??? size=初始大小MB,?????????????? ?
??? maxsize=最大大小
??? filegrowth=文件增長率(可以指定MB或百分比
),
(
??? name='次要數(shù)據(jù)庫邏輯名',??????????????? --數(shù)據(jù)庫名_ndf
??? filename='次要數(shù)據(jù)庫主文件(包括路徑)',--E:\第二期\第二章數(shù)據(jù)庫的實(shí)現(xiàn)\數(shù)據(jù)庫名_ndf.ndf
)
log on
(
??? name='數(shù)據(jù)庫日志名',??????????????? --數(shù)據(jù)庫名_log
??? filename='數(shù)據(jù)
??? filegrowth=文件增長率(可以指定MB或百分比
)
3.刪除數(shù)據(jù)庫
?? drop database 數(shù)據(jù)名
4.判斷數(shù)據(jù)庫是否存在
? use master 數(shù)據(jù)庫?? --選擇master數(shù)據(jù)庫
?? go
?? if exists(select * from sysdatabases where name='數(shù)據(jù)庫名')
?? drop database 數(shù)據(jù)庫名
?? 注:sysdatabases 表是master數(shù)據(jù)庫中的表,此表保存了數(shù)據(jù)庫系統(tǒng)中所有的數(shù)據(jù)庫
二、表
1.創(chuàng)建表
??? create table 表名
?? (
??? 列名1 數(shù)據(jù)類型 not null,
??? 列名2 數(shù)據(jù)類型 null
???? //默認(rèn)為null
??? 列名3 整型 identity(種子,增量) not null --表示列
??? )
2.刪除表
?? drop table 表名
3.判斷表是否存在
?? if exists (select * from sysobjects where name='表名') drop table 表名
??? 注:sysobjects 是系統(tǒng)表,任何數(shù)據(jù)庫都存在該表,sysobjects保存了當(dāng)前數(shù)據(jù)庫中的所有的表
三、數(shù)據(jù)完整
?? 1.實(shí)體完整性:保證行不重復(fù),保證實(shí)體唯一
?? 2.域完整性:限制列數(shù)據(jù)的取值
?? 3.引用完整性:建立表和表之間的關(guān)系(實(shí)體之間的關(guān)系)
?? 4.用戶定義:用戶編寫邏輯
四、約束
?? 1.主鍵約束(primary key):實(shí)現(xiàn)實(shí)體完整性
?? 2.唯一約束(unique):實(shí)現(xiàn)域完整性
?? 3.默認(rèn)約束(default):實(shí)現(xiàn)域完整性
?? 4.檢查約束(check):實(shí)現(xiàn)域完整性
?? 5.外鍵約束(foreignkey):實(shí)現(xiàn)引用完整性
五、給表添加約束
?? alter table 表名
??? add constraint 約束名 約束類型 約束說明
? 1.添加主鍵約束
??? alter table 表名
??? add constraint PK_列名 primary key (列名)
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎
總結(jié)
以上是生活随笔為你收集整理的数据库的实现【笔记】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 数据库设计【笔记】
- 下一篇: office办公笔记本推荐?
