sybase

Identifying Sybase tables, fields, keys, constraints

我与影子孤独终老i 提交于 2019-11-28 09:24:21
问题 I'm trying to set up a Sybase query that will give me the following output: Table KeyType KeyNumber Column table1 PK 1 table1_id table1 FK 2 table2_id table1 FK 3 table3_id table1 FK 4 table4_id table1 Unique 5 table1_abc table1 Unique 5 table1_def In other words, I need the PK for each table, and every foreign key it has, as well as every unique key (not where a key has more than one element, such as the unique key above, this is identified by having the same KeyNumber). I'm guessing I need

How to convert a string to a date in sybase

泄露秘密 提交于 2019-11-28 05:29:07
I need to specify a date value in a sybase where clause. For example: select * from data where dateVal < [THE DATE] Use the convert function, for example: select * from data where dateVal < convert(datetime, '01/01/2008', 103) Where the convert style (103) determines the date format to use. Edwin Here's a good reference on the different formatting you can use with regard to the date: http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/Convert.htm Jose B. Several ways to accomplish that but be aware that your DB date_format option & date_order

sybase数据库统计记录

六眼飞鱼酱① 提交于 2019-11-28 05:05:40
概述 网上关于sybase数据库的资料很少,很多功能可能都不如oracle等其他数据库,最近在做一个涉及统计的需求,对于我这种数据库菜鸟来说,当接触到新的东西最好的方法就是记录下来,方便下次使用或者翻阅。 需求 需求单就不奉上了,主要就是统计用户测速成功率的一个统计报表,包含测速的属地,不达标的数量,达标的数量,总计以及成功率,其中同一个用户取测速结果最好的一次,测速速率的计算方式按设备的上行方式来定。 执行sql //大概思路如下,其中....是需要关联的表或者加的where条件 select sum(case when (nvl(a.rate,0)>=0.9*TO_NUMBER(a.speed)) then 1 else 0 end) reached, sum(case when (nvl(a.rate,0)<0.9*TO_NUMBER(a.speed)) then 1 else 0 end) noReached from (select round(nvl(avg,0)*8/1024,2) rate,usernm,speed from (select row_number() over(partition by usernm order by avg desc ) rn , bb.usernm,bb.speed from xxxxx bb where bb.wanType=

From a Sybase Database, how I can get table description ( field names and types)?

爷,独闯天下 提交于 2019-11-28 03:16:28
I have access to command line isql and I like to get Meta-Data of all the tables of a given database, possibly in a formatted file. How I can achieve that? Thanks. Lukasz Lysik Check sysobjects and syscolumns tables. Here is a diagram of Sybase system tables. List of all user tables: SELECT * FROM sysobjects WHERE type = 'U' You can change 'U' to other objects: C – computed column D – default F – SQLJ function L – log N – partition condition P – Transact-SQL or SQLJ procedure PR – prepare objects (created by Dynamic SQL) R – rule RI – referential constraint S – system table TR – trigger U –

Getting ExecuteBatch to execute faster

大憨熊 提交于 2019-11-28 01:44:18
问题 I'm trying to read a table from a sybase server, process the rows, and output the results to another table. (Below is my code) The code retrieves the table pretty fast and processes equally fast (get's to the part where it sends within 30 seconds). But When I run execute batch it sits there for 20 minutes before finish (fyi, I have a table which I'm testing with 8400 rows). Is there a more efficient way to do this? I'm amenable as to how I can recieve or send the queries (I can create a new

Performance of different approaches to time-based data

浪子不回头ぞ 提交于 2019-11-27 19:56:34
I'm asking this in the context of PerformanceDBA's claim in this answer to another question that this query: SELECT ProductId, Description FROM Product p, ProductStatus ps WHERE p.ProductId = ps.ProductId -- Join AND StatusCode = 2 -- Request AND DateTime = ( -- Current Status on the left ... SELECT MAX(DateTime) -- Current Status row for outer Product FROM ProductStatus ps_inner WHERE p.ProductId = ps_inner.ProductId ) using a ProductStatus table that holds only an effective (start) date for a status that changes over time, will outperform this query: SELECT ProductId, Description FROM

Difference between drop table and truncate table?

孤街醉人 提交于 2019-11-27 17:25:56
I have some tables that I build as a part of my report rollup. I don't need them afterwards at all. Someone mentioned to truncate them as it would be faster. Deleting records from a table logs every deletion and executes delete triggers for the records deleted. Truncate is a more powerful command that empties a table without logging each row. SQL Server prevents you from truncating a table with foreign keys referencing it, because of the need to check the foreign keys on each row. Truncate is normally ultra-fast, ideal for cleaning out data from a temporary table. It does preserve the

How to get list of values in GROUP_BY clause?

a 夏天 提交于 2019-11-27 11:44:21
问题 If I have data like this in a table id data -- ---- 1 1 1 2 1 3 2 4 2 5 3 6 3 4 How do I get results like this in a query (on sybase server)? id data -- ---- 1 1, 2, 3 2 4, 5 3 6, 4 回答1: I know that in MySQL there is GROUP_CONCAT and in Sybase I think it's LIST as stated in another answer: SELECT id, LIST(data||', ') FROM yourtable GROUP BY id 回答2: In MsSQL you can use a function (Don't know if there is somenthing similar in SyBase) CREATE FUNCTION [dbo].[GetDataForID] ( @ID int ) RETURNS

Convert INT to VARCHAR SQL

那年仲夏 提交于 2019-11-27 09:07:57
问题 I am using Sybase and I am doing a select which returns me a column called "iftype", but its type is int and I need to convert into varchar. When I try to do the select without the convert function I get this error: Error code 257, SQL state 37000: Implicit conversion from datatype 'VARCHAR' to 'INT' is not allowed. Use the CONVERT function to run this query. I dont know how to implement the function CONVERT . Can anyone help me, please ? 回答1: Use the convert function. SELECT CONVERT(varchar

SYBASE存储过程详解

我们两清 提交于 2019-11-27 06:44:56
SYBASE存储过程 一、存储过程简介 二、存储过程的创建、修改、删除 三、存储过程中的参数、返回值和变量 四、存储过程中的流程控制语言 五、存储过程中的事务、游标 六、ASE存储过程和IQ存储过程的常见区别(附例子) 1 存储过程简介 存储过程(Stored Procedure)是为了完成特定的功能而汇集成一组的SQL语句 集,并为该组SQL语句命名、经编译后 存储在SQL Server的数据库中。用户可以 根据需要决定是 否在每次执行时让SQL Server进行重新编译。用户可以指 定存 储过程的名字和给出参数来执行它。 允许多个用户(有权)访问相同的代码。 提供一种集中且一致的实现数据完整性逻辑的方法。 存储过程用于实现: -- 频繁使用的查询 -- 业务规则 -- 被其他过程使用的公共例行程序,例如错误处理例行程序等 1.1 存储过程的优点 使用存储过程可加快运行速度 可减少网络交通 可重用、可共享性 存储过程也是一种安全机制 使用存储过程实现数据库完整性 提高数据与应用的独立性 1.2 存储过程的分类 系统存储过程主要 系统提供存储过程 用于从系统表中获取信息、为系统管理员和有权用户提供更新系统表 的途径。系统存储 过程的名字都以"sp_"为前缀。 如:sp_help 。 用户定义的存储过 用户定义存储过程 程是由用户为完成某一特定功能 而编写的存储过程。 1.2.1