数据库的实现
2.1 使用SQL語句管理數據庫
一,創建數據庫
create database 數據庫名稱
[ON[primary]]
[
<數據文件參數>[,....n]
[,<文件組參數>[,....n]
]
[log on{<日志文件參數>[,....n]}]
]
carate database t123 on ( name=t123_mdf, filename='E:\t123_mdf.mdf', slze=3MB, maxsize=100MB, filgrowth=1MB ) log on ( name=t123_ldf, filename='E:\t123_ldf.ldf', slze=3MB, maxsize=100MB, filgrowth=1MB ) go
二,刪除數據庫
if DB_ID('t123') is not null
drop database t123
go
三,數據庫的類型
1.字符型數據:char(size),varchar(size)
2,數字型數據:bit,int,float,numeric(m,n)
3,日期時間類型:dateTime
4,二進制數據類型:text,image
5,貨幣數據類型:money,smallmoney
6,Unicode:nchar(size),nvarchar(size),ntext(size)
四,創建表
ccreate table 表名
(
字段1 數據類型 字段特征,
)
create table t_info ( t_id int not null identity(1,1),--會員編號 t_number nvarchar(50) not null, --會員號 .......... )
1.添加列
alter table t_info
add t_age varchar(50) null
go
alter table t_info
add t_age varchar(50) null,
t_sex int null
go
2,刪除列
alter table 表名
drop column {字段}[.....n]
alter table t_info
drop column t_age
go
3,修改列
alter table 表名
alter column 字段 數據類型[null | not null]
alter table t_info alter column t_age declmal(..n) go
五,刪除表
if exists(select*from sys.sysobjects where name='t_info')
drop table t_info
go
六,數據完整性的分類
1,域完整性
域即是列(字段).
2,實體完整性
行完整性
3,參照完整性
引用完整性(表與表之間的引用)
4,用戶定義完整性
2和3是關系模型最基本的要求,用戶可以定義一些特殊的約束條件.
七,約束
1,主鍵約束(primary key)
alter tabke 表名
add constralnt 約束名稱 primary key(字段[...n])
2,唯一約束(unlpue)
alter tabke 表名
add constralnt 約束名稱 unlpue(字段[...n])
3,默認約束(default)
alter tabke 表名
add constralnt 約束名稱 default 默認值 for 字段
4,檢查約束(check)
alter tabke 表名
add constralnt 約束名稱 check(邏輯表達式)
5,外鍵約束()
alter tabke 表名
add constralnt 約束名稱 primary key(從表字段)pefferences主表表名(主表字段)
總結
- 上一篇: 方正飞越 A600硬改BIOS激活win
- 下一篇: 建行信用卡现金转出和现金分期有什么区别?