易截截图软件、单文件、免安装、纯绿色、仅160KB

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个键设置成了联合主键,即同一个客户不可能在同一时间租了同一张影碟多次)


相关文档:

SQL日期类大全(convert)

---用convert转换参数对比
select CONVERT(varchar, getdate(), 120 )
2004-09-12 11:06:08
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
20040912110608
select CONVERT(varchar(12) , getdate(), 111 )
2004/09/12
select CONVERT(varchar(12) , getdate(), 112 ) ......

SQL语句

前段时间学的有关sql的相关知识,很多都没及时去整理,今天刚好有时间有没心情做其他的是,就整理整理吧
      一直以为做开发的对数据库操作方面的要求不会很高,只要会对数据增删改查就ok了.现在才知道对数据库的操作还应该包括写存储和函数,还要创建序列、索引,视图等.
     ......

Java命令行执行从SQL 2000数据库转移到2005数据库

1.下载2005数据库驱动(sqljdbc.jar)
2.这时要用Eclipse等集成开发环境,在build path里面把2000数据库驱动包删除了,然后导进2005数据包。
3.把代码中注册数据库驱动的代码换成2005的代码。
如:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); // 2005 version
Class.forName("com.microsoft.jdb ......

免安装Oracle客户端软件 使用pl/sql配置登陆

虽然这是我找到最详细的配置描述,但是尝试还是没有成功。
 
1.下载Oracle Client Package
.

http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html
下载
Instant
Client Package – Basic

(

标注
:All files
required to run OCI, OCCI, and JDBC-OC ......

sql server2005 rownum通用存储过程分页

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER   PROCEDURE [dbo].[sp_GetRecordfromPage]
@TableName varchar(350),        --表名
@Fields varchar(5000) = '*',    --字段名(全部字段为*)
@OrderField varchar(5000),   &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号