SYBASE Table space information - sybase

Can any one help me finding the information of multiple tables in SYBASE. I Know in ORACLE we do Select * from USEr_segments;

Something similar would be visible through running
select * from sysobjects where uid = user_id() and type = 'U'

Related

Is there a way to identify if a column is not been used in a SQL Server Database?

I have a big database and a lot tables and I would like to identify what columns are not been called by any store procedure or any query, or not in use.
I'm not sure if this is what you're looking for, but in your DB under views there's a folder for System Views - three of which are the following. Looking in all_objects look for the table name, then use the object_id of that table to select from the other queries. There may be other meta-data here that is appropriate for your need.
SELECT *
FROM sys.all_objects
SELECT *
FROM sys.all_columns
WHERE object_id = 981578535
SELECT *
FROM sys.all_views
WHERE object_id = 981578535
After an investigation I have found a new feature of SQL Server called Query Store where you can find in disk the executions with other information. If you have a SQL Server 2016 instance you can find it in the properties of the data base. There you can change the amount of days to capture and then you can in theory try to find the columns in question. The idea of this technology is to give you more options for performance tuning.
You can find the information with this query :
SELECT TOP 10 qt.query_sql_text, q.query_id,
qt.query_text_id, p.plan_id, rs.last_execution_time
FROM sys.query_store_query_text AS qt
JOIN sys.query_store_query AS q
ON qt.query_text_id = q.query_text_id
JOIN sys.query_store_plan AS p
ON q.query_id = p.query_id
JOIN sys.query_store_runtime_stats AS rs
ON p.plan_id = rs.plan_id
where qt.query_sql_text LIKE '%ColumnToFind%'
ORDER BY rs.last_execution_time;
Credits: Query Store

Is Sybase {ASE} uses "schema.table" or just "table"

ALL,
The title pretty much says it all. I was looking here, but couldn't find any information about the schema.
Could someone please sched some light?
I know MS SQL Server uses "schema.name" to reference a table in a database, but for Sybase I'm not sure.
TIA!
EDIT:
I guess I should be more specific.
I know in MS SQL Server it is possible to modify the table owner, but you can still select it with "SELECT su.name FROM sysobjects so, sysusers su, sys.tables t, sys.schemas s WHERE so.uid = su.uid AND t.object_id = so.id AND t.schema_id = s.schema_id AND s.name = ? AND so.name = ?;"
Now with Sybase everywhere I look the query to retrieve the table owner does not reference schema name only the table name. Does this mean that the table owner is not changeable in Sybase? Or it is changeable, but then the schema will also be changed?
Can someone shed some light please?
In Sybase/SAP ASE, all tables have an owner; this owner is effectively the same thing as a schema.
That link you mention points to the sysobjects (system) table, which exists in every database. sysobjects contains some high-level metadata for all objects (eg, tables, procs, triggers, views, etc) in the database.
Two columns of interest in the sysobjects table
name : name of the object (eg, name of a table, name of a proc)
uid : database user id of the object's owner
All system tables have an entry in sysobjects with uid = 1, which refers to the database owner (ie, user_name(1) = dbo).
In most environments it's typical for the database owner (dbo) to also own most other objects in the database (ie, most sysobjects rows have uid=1).
If an object is owned by someone other than the dbo, the sysobjects row will have uid = user_id('non_dbo_owner_name'); for example, if bob's database user id (uid) is 47, then any objects owned by bob will have sysobjects.uid = 47.
When you reference a table without an owner/schema name (eg, select * from tab1), ASE will first look for an object owned by you (ie, do you own a table named 'tab1') and if it doesn't find such a table then it looks for a table owned by the dbo (ie, does 'dbo.tab1' exist?).
When you reference a table with an owner/schema name attached, ASE will only look for the existence of that table.
If you don't own a table named 'tab1' then the following are equivalent:
select * from tab1
select * from dbo.tab1
In response to the updated question:
Sybase/SAP ASE does not support changing the owner of an object.
As for finding the owner(s)/schema(s) of a table, you've got a couple options:
select u.name as 'owner_name',
o.name as 'table_name'
from sysobjects o,
sysusers u
where o.uid = u.uid
and o.name = '<name_of_table>'
and o.type = 'U'
-- or
select user_name(o.uid) as 'owner_name',
o.name as 'table_name'
from sysobjects o
where o.name = '<name_of_table>'
and o.type = 'U'
It works the same like in MS SQL Server. You can use schema.object.
If you use object then the object is searched:
first in our schema
then in dbo schema
You can also use the database.owner.object notation or database..object notation when owner is dbo or event server.database.owner.object notation when you connect an external ASE server.

How to get properties of a field of table in sybase

Here is details
In sybase, I have a table "abc" having 5 fields(name, roll, address, desc,path). If i would use 'sp_help tablename' then i can see all properties of all fields how i can get properties of a particular field i.e. roll or any one field and their properties using sql or pl/sql.
As we know that we can not use any parameters in sp_help so is there any way to to get the properties of a field, (pl/sql or sql)?
Thanks in advance
sp_help tablename
This depends on what specific properties you are looking for. Assuming you are looking for Table, Column, Datatype, Datatype Length - you have to join sysobjects, syscolumns, and systypes
use YOURDB
go
select o.name, c.name, t.usertype, c.length
from
sysobject o,
syscolumns c,
systypes t
where o.id = c.id
and c.usertype = t.usertype
and o.name like "YOUR_TABLE"
and c.name like "YOUR_COLUMN"
go
If you want more than that, you'll have to bring in other columns and/or tables into the query like sysdepends, sysdefaults or sysconstraints
More information about the system tables can be found here:
Sybase ASE Reference Manual: Tables > System Tables
And the system table diagram, which shows the column mappings can be found here:
http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc70204.1550/pdf/a155pst.pdf
Also, FYI - Sybase uses T-SQL (like SQL Server), not pl/sql.

SQL request to list all databases in an instance of Sql-Server?

Is there a way to list all of the existing databases in an instance of Sql Server via a SQL request ?
More generally can I use SQL to fully read the schema of the databases (tables, columns, ..) ?
Thank you
Jerome Wagner
Yes. See the Information Schema Views and sys.databases.
Here's a script for table definitions that may be useful. http://www.builderau.com.au/program/sqlserver/soa/Script-Table-definitions-using-TSQL/0,339028455,339293405,00.htm
You can get a lot of infos by the following queries:
SELECT * FROM sys.databases
use Northwind
select * from sys.objects where type_desc = 'USER_TABLE'
SELECT t1.name [table], t2.*
FROM sys.objects t1
inner join sys.columns t2 on t1.object_id = t2.object_id
where type_desc = 'USER_TABLE'
sp_help 'Customers' -- Customers = tablename
Yes, Sp_msforeachdb, there is also a sp_msforeachtable. You can use both to iteratively retrieve all tables in all DB's and get what you want.
https://web.archive.org/web/1/http://blogs.techrepublic%2ecom%2ecom/datacenter/?p=395.
Try using the stored procedure sp_databases to get the list of all db

sql server: looking for table usage through out database

How would I figure out what type of sql code such as procs, functions, views etc. are interacting with my table called TABLE1 through out a given database. Sample code would be very helpful for me.
thanks
select so.name, so.xtype
from sysobjects so (nolock)
inner join syscomments sc (nolock) on sc.id = so.id
where sc.text like '%tablename%'
This code will search all SQL Server objects for a reference to your table. You have to run this query for each database.
If a stored procedure uses your table it will appear in this query. The same is true of functions, views, and triggers.
xtype tells you the type of object.
Here are the possible xtype values:
D = Field names
F = Foreign Key
FN = Function
P = Stored Procedures
PK = Primary Key
S = System Tables
U = User tables
V = Hidden tables
Not enough info in your question, but one thing you can do is use SQL Profiler to profile where INSERTs, UPDATEs, and DELETEs are coming from.
I assume you are talking about how an app is interacting with data and what name (of say a sproc) is doing the insert / update / delete.
Look at SQL Profiler, it comes with your client tools install. Filter it to only show connections to your database (either db name or ID).
If you've been good and created your SPs/views/functions after your table was created, sp_depends will tell you evertyhing referencing the table. Exept for dynamic sql that is.

Resources