日期:2014-05-16  浏览次数:20456 次

SYBASE数据库总结
SYBASE中插入数据的方式有:
1.
INSERT INTO #b_header_temp(cust_record_id)
SELECT MIN(id)
FROM   #c_record_temp
GROUP BY out_order_no

2.
SELECT rowid=IDENTITY(18),t.*
INTO #b_cust_temp
FROM  #b_header_temp h,#c_record_temp t
WHERE t.out_order_no=h.out_order_no

SYBASE中给变量赋值的方式有:
1.
DECLARE
@curr_rowid INT
SET @curr_rowid=@curr_rowid+1


2.
SELECT @curr_rowid = NULL
SELECT @outchar='Four'
SELECT @First=123

SYBASE中if语句的使用:
IF
(EXISTS(SELECT * FROM b_header WHERE borr_no=444))
BEGIN
SELECT TOP 1 * FROM b_header
END
ELSE
BEGIN
SELECT TOP 2 * FROM b_header
END

SYBASE中显示定义的变量值的方式:
1.一次只给一个变量赋值
DECLARE
@tt VARCHAR(30), 
@i_count INT 

SELECT @tt='ddddddddd'
SELECT @i_count=10008
PRINT @tt
--PRINT @i_count --说明:sybase中只允许通过PRINT打印VARCHAR或CHAR类型的变量值,不允许打印INT型的变量值

2.一次性给多个变量赋值
DECLARE
--定义多个变量
@i VARCHAR,@t VARCHAR,@y INT 
--分别同时给多个变量赋值
SELECT @i='ddd',@t='fjfjf',@y=3
--给@y变量重新赋值
SET @y=1
PRINT @i,@t

SYBASE中null与null的比较
/**
运行以下代码将打印出"null = null"
**/
IF(isNULL(NULL,null) =  NULL )
	BEGIN
		PRINT 'null = null'--在sybase中null 与null是相等的
	END
ELSE
	BEGIN
		PRINT 'null <> null'
	END 


创建id自增表
drop table s_test
go
create table s_test(
   idn   int  identity,
   pt_no   varchar(48)  null
)with identity_gap=1--with identity_gap = 1 是增幅,等于1表示自增1
go

insert into s_test(part_no)
select test_col
from C_H_20110724


sp_whon  a--查看当前用户在数据库上正在操作的数据库对象和运行状态

sp_who --查看当前数据库的所有登陆用户信息

sp_who itleader --查看当前数据库指定登陆用户(itleader)信息


判断数据库对象是否存在:
if object_id('tempdb..ad185119') is not null
	drop table tempdb..ad185119
go
或
if exists(select 1
		from sysobjects
		where id=object_id('dbo.load_batch')
		and type='P')
	drop procedure dbo.load_batch
go