DDL (Data Discription Language) 数据库定义语言
basic object | operation | ||
Create | Alter | Drop | |
database | create database | drop database | |
table | create table | alter table | drop table |
view | create view | drop view | |
index | create index | drop index |
DataBase
View Code
create database Three_Kingdom on primary ( name='Three_Kingdom_data', filename='d:\Three_Kingdom.mdf', size=3mb, maxsize=100mb, filegrowth=2% ) log on( name='Three_Kingdom_ldf', filename='d:\Three_Kingdom.ldf', size=1mb, maxsize=50mb, filegrowth=2 ) /*drop database*/ drop database Three_Kingdom
primary:指定主文件组中的文件。
log on:指明事务日志文件的明确定义。
name:指定数据库的逻辑名称
filename :指定数据库文件.mdf或.ndf的名称和路径。
size:数据库初始容量。
maxsize:数据库最大容量。
filegrowth:指定文件每次增加容量的大小,当指定为0时,表示文件不增长。可以按百分比增长、数值增长。
Table
View Code
use Three_Kingdom create table sanguo( id smallint identity(1,1), [number] nvarchar(5) not null, [name] nvarchar(10) not null, [address] nvarchar (20) default'地址不详', email nvarchar(20) check(email like'%@%'), country nchar(1) check(country like'[魏蜀吴]') primary key(number), constraint cons_num check(number like'[0-9][0-9][0-9]') ) drop table sanguo alter table sanguo add age int not null, salary decimal(6,2) default 3200, constraint cons_age check (age>20) alter table sanguo drop constraint cons_age,column age
View
View Code
create view V_Profile as select [sanguo].[number],[sanguo].[name],[sanguo2].[zi] from [sanguo],[sanguo2] where[sanguo].[number]=[sanguo2].[number] drop view V_profile
Index
View Code
create nonclustered index name_index
on sanguo([name])
drop index [sanguo].name_index