Sql语句学习笔记(2) 创建数据表
use RetalDB--表示在数据库RetalDB中进行的操作
go
if exists (select * from sysobjects where name='tb_user')
drop table tb_user
go
--创建客户表tb_user
create table tb_user
(
user_id int primary key,--指定为主键时,此列默认为非空,指定过多个限制条件时不用“'”隔开
user_name varchar(20) not null,
user_point int not null,
)
--创建影碟类型表tb_MovieType
if exists (select *from sysobjects where name='tb_movie_type')
drop table tb_movie_type
go
create table tb_movie_type
(
type_id int primary key,--指定主键
type_name varchar(20) not null,
type_english_name varchar(20) not null
)
--创建影碟表
if exists (select * from sysobjects where name='tb_movie')
drop table tb_movie
go
create table tb_movie
(
movie_id int primary key,
movie_name varchar(20) not null,
movie_price float,
movie_type_id int not null,
movie_detail varchar(255)
--添加外键约束
constraint FK_movie_id foreign key(movie_type_id) references tb_movie_type(type_id)--引用影片类型表中的type_id字段
)
--创建租赁信息表
if exists (select * from sysobjects where name='tb_retal')
drop table tb_retal
go
create table tb_retal
(
id int identity(1,1) primary key,--信息编号
user_id int not null,--外键,引用客户表中的主键user_id
movie_id int not null, --外键,引用影片表中的movie_id
rent_time datetime not null default(getdate()),--租出时间,以插入数据时的时间为默认值
return_time datetime,--归还时间
rent_fee float default(0)--租金
constraint FK_user_id foreign key(user_id) references tb_user(user_id),
constraint FK_movie_id foreign key(movie_id) references tb_movie(movie_id)
)
创建好的表如图所示:(后来为了保证tb_retal中数据的唯一性,将user_id,movie_id,rent_time这3个键设置成了联合主键,即同一个客户不可能在同一时间租了同一张影碟多次)
相关文档:
说到事务,首先我们就要知道为什么需要事务,这就要先看看锁机制的相关概念!
锁的概述
一. 为什么要引入锁
多个用户同时对数据库的并发操作时会带来以下数据不一致的问题:
丢失更新
A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破坏了另一个修改的结果,比如订票系统&nb ......
1、关于SQL server 2000 在安装过程中遇到文件挂起的解决办法:
在Ghost 版 windows xp 中安装 SQL server 2000 时经常会遇到安装程序运行到第二步(如下图所示)时点击下一步显示有文件挂起操作,提示重新起
动计算机解决这个问题,可重新起动计算机后,安装程序进行到此仍然显示有文件挂起操作。这个问题的产生实际并 ......
下载地址:http://download.csdn.net/source/2384982
----------------------------------------------------------------------------
软件名称:通用Sql备份恢复工具
执行程序:iNethink_SqlTool.exe
程序版本:V1.0.0.1
----------------------------------------------------------------------------
Md5值:E511 ......
1:当 SQL 语句引用非索引视图时,分析器和查询优化器将分析 SQL 语句的源和视图的源,然后将它们解析为单个执行计划。没有单独用于 SQL 语句或视图的计划。
2:索引视图的行以表的格式存储在数据库中。如果查询优化器决定使用查询计划的索引视图,则索引视图将按照基表的处理方式进行处理 ......