您的位置:首页 > 数据库

数据库基本语法

2014-06-09 21:44 417 查看
--创建studb数据库

create database studb

--修改studb数据库

alter database studb

--删除studb数据库

drop database studb

--查询数据库信息

exec sp_helpdb 'studb'

--创建stuInfo数据表

create table stuInfo

(

id int identity(1,1) not null, --自增长编号

name varchar(15) not null, --姓名

utime datetime not null, --注册时间

stuID numeric(18,0) not null --身份证号

)

go

USE stuDB

go

--向表添加column_add列

alter table stuInfo

add column_add varchar(20) NULL

go

--修改列数据类型

alter table stuInfo

alter column column_add DECIMAL(20,4)

go

--删除olumn_add 列

alter table stuInfo

drop column column_add

go

--添加主键约束

alter table stuInfo

add constraint pk_stuNo primary key (stuNo)

--添加唯一约束

alter table stuInfo

add constraint uq_stuID unique(stuID)

--添加默认约束

alter table stuInfo

add constraint df_stuAddress

default('地址不详') for stuAddress

--添加检查约束

alter table stuInfo

add constraint ck_stuAge

check(stuAge between 15 and 40)

--添加外键约束

alter table stuMarks

add constraint fk_stuNo

foreign key(stuNo) references stuInfo(stuNo)

GO

--创建视图并给视图加密

CREATE VIEW View_stu with encryption

AS

SELECT * from student

go

with check option

--创建聚集索引

CREATE Clustered index IX_tel

on student(tel)

go

--修改索引 并重新生成索引

alter index IX_tel on student rebuild
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: