---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! ----------------------
数据库(仓库)
表table(货架)
行 记录
列 字段
主键 表的唯一标示,并且不能为空
外键 创建表之间的关联,如果一个列是外键则在另一个表中必定是主键
sqlserver版本 Express 免费版
Standard 标准版
数据类型
char 固定长度,char(10) 张三 补6个空格
varchar 可变长度
nchar 固定长度 Unicode编码存储 nchar(10) 张三 补 8个空格
nvarchar 可变长度 Unicode编码存储
sex 男/女 nchar(1)
建库
create database shujuku
on
(
)
删除库
drop database shujuku
建表
create table biao
(
)
删表
drop table biao
增
insert [into] biao (lie1,lie2,lie3) values('值1','值2','值3')
删
delete from biao [where 条件]
truncate table biao 会把自增列 还原成种子值
改
update biao set lie1 = '',lie2='' [where 条件]
约束 保证数据的完整性(正确性)
--主键约束
alter table class
add constraint PK_Class primary key(cId)
--唯一约束
alter table class
add constraint UQ_Class_cName unique(cName)
--默认约束
alter table student
add constraint DF_student_sBirthday default (getdate()) for sBirthday
--添加检查约束
alter table student
add constraint CK_student_sAge check (sAge >= 18 and sAge<=25)
--外键约束
alter table student
add constraint FK_student_sClassId foreign key (sClassId) references class(cId)
--删除约束 因为约束在表中存储
alter table student
drop constraint DF_student_sAge
---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! ---------------------- 详细请查看:http://net.itheima.com/