数据库基本语法
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
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
相关文章推荐
- SQL Server -数据库基本语法的总结
- Sql链接数据库基本语法
- 数据库sqlite3的使用-基本语法
- 数据库基本语法
- mysql之数据库操作基本语法
- JDBC连接数据库-基本语法:
- Hive 数据库相关基本语法
- 数据库之SQL基本语法
- txt文本内容写入数据库&MySQL基本语法
- 数据库基本操作语法归纳总结
- 数据库基本语法
- 【数据库】 sql的一些基本语法(一)
- 数据库SQL基本语法
- 【sql入门】根据要求绘制E/R图,创建数据库(2)mySQL建表基本语法及主键外键选择
- 数据库学习笔记之SQL查询的基本语法结构
- 数据库数据类型、约束、基本语法
- 【数据库】 sql的一些基本语法(二)
- 【数据库】 sql的一些基本语法(三)
- 数据库的一些基本语法一
- Hive 数据库相关基本语法