标签:
数据库文件构成:主文件(MDF)、次要文件(NDF)、日志文件(LDF)
其中主文件和日志文件是必须的,次要文件可以有多个(存放在不同分区以提高速度),也可以没有
创建数据库文件主要用到5个属性:
name、filename、size、maxsize、filegrowth
use master go if exists (select * from sysdatabases where name=‘db‘) drop database db go create database db on primary ( name = ‘db_mdf‘, filename = ‘c:\temp\db.mdf‘, size = 10, maxsize = 100, filegrowth = 5 ), ( name = ‘db_ndf‘, filename = ‘c:\temp\db.ndf‘, size = 10, maxsize = 100, filegrowth = 5 ) log on ( name = ‘db_ldf‘, filename = ‘c:\temp\db.ldf‘, size = 10, maxsize = 100, filegrowth = 5 ) go
常见数据类型
use db go if exists (select * from sysobjects where name=‘score‘) drop database score go if exists (select * from sysobjects where name=‘corse‘) drop database corse go if exists (select * from sysobjects where name=‘grade‘) drop database grade go if exists (select * from sysobjects where name=‘student‘) drop database student go create table student ( id int primary key identity(1,1), name nvarchar(50) not null, gender bit default ‘true‘, joindate date default getdate() ) go create table grade ( id int primary key identity(1,1), name nvarchar(50) not null unique, state bit default ‘true‘ ) go create table corse ( id int primary key identity(1,1), name nvarchar(50) not null unique, state bit default ‘true‘, gradeid int not null, constraint fk_corse_gradeid foreign key (gradeid) references grade(id) ) alter table corse nocheck constraint fk_corse_gradeid go create table score ( studentid int foreign key references student(id) on delete cascade, corseid int foreign key references corse(id) on delete cascade, examtime datetime default getdate(), value decimal(4,1) check(value between 0 and 100), constraint pk_score primary key clustered (studentid,corseid) ) go
数据库完整性主要包括:
标签:
原文地址:http://www.cnblogs.com/rammderek/p/4260529.html