文档详情

数据库系统SQL实验.doc

发布:2017-06-04约1.64万字共23页下载文档
文本预览下载声明
创建架构 架构是一个对象的容器,可以包含多个数据表,存储过程和视图等基础对象,SQL Server 2008采用架构分离的方式,增强了管理对象的灵活性。 架构创建有两种方式: 图形化界面 选择“数据库”,→架构→角色→配置权限 命令 Create Schema 架构名称(选择数据库已分类定义过)Authorization 用户名或角色 例,先创建用户“李雪0501” 后 创建架构 create schema admin authorization 李雪drop schema admin 1数据定义 1.1模式的定义与删除 1、定义模式 在查询窗口输入, [例1] create database testStudCour 创建数据库testStudCour,在对象资源管理器中的目录“数据库”单击右键“刷新”,出现“testStudCour”数据库 [例2] create database [testStudCour2] on primary ( name = NlixuetestStudCour, filename = Nd:\lixuetestStudCour.mdf , size = 3072KB , maxsize = unlimited, filegrowth = 1024KB ) LOG ON ( name = NlixuetestStudCour_log, filename = Nd:\lixuetestStudCour_log.ldf , size = 1024KB , maxsize = 2048GB, filegrowth = 10% ) [例3] create database testStudCour3 Create table testStudCour3.TabStudCour( 学号 nchar(9) primary key, 姓名 nchar(10) NULL, 性别 nchar(2) NULL, 系别 nchar(20) NULL,) 消息2760,级别16,状态1,第8 行 指定的架构名称testStudCour3 不存在,或者您没有使用该名称的权限。 create database testStudCour3 在执行 Create table testStudCour3.dbo.TabStudCour( 学号 nchar(9) primary key, 姓名 nchar(10) NULL, 性别 nchar(2) NULL, 系别 nchar(20) NULL,) database testStudCour2 删除数据库testStudCour,在对象资源管理器中的目录“数据库”单击右键“刷新”,“testStudCour”数据库被删除 [例5] drop database testStudCour3 Restrict 消息156,级别15,状态1,第13 行 关键字Restrict 附近有语法错误。 drop database testStudCour3 cascade 消息156,级别15,状态1,第13 行 关键字cascade 附近有语法错误。 1.2.1 定义基本表 先执行 create database stud_cour 后执行 [例7] create table [stud_cour].[dbo].student(sno nchar(9) primary key, sname nchar(20) not null, ssex nchar(2), Sage int, sdept nchar(20)) [例8]create table [stud_cour].[dbo].Course(Cno nchar(2) primary key, Cname nchar(10) not null, Cpno nchar(2), Ccredit smallint) [例9]create table [stud_cour].[dbo].SC(Sno nchar(9), Cno nchar(2), Grade smallint, primary key (Sno,Cno), foreign key (sno) references Student(sno), foreign key (cno) references Course(cno)) 1.2.2 修改基本表 [例10] alter table stud_cour.dbo.
显示全部
相似文档