SQL Anywhere5.5: Metadata

2018/3/7 9:55:02 人评论 次浏览 分类:操作技巧

http://dcx.sybase.com/1101/en/dbprogramming_en11/ianywhere-data-sqlanywhere-saconnection-getschem6330755502-0.html

http://razorsql.com/articles/sybase_admin_queries.html

http://infocenter.sybase.com/help/topic/com.sybase.help.sqlanywhere.11.0.0/pdf/dbadmin_en11.pdf

http://www.mono-project.com/docs/database-access/providers/sybase/

https://github.com/mono/old-code

 https://benohead.com/sybase-create-a-proxy-for-a-remote-database/

http://www.dofactory.com/reference/connection-strings

Columns collection
  • table_schema (Owner)
  • table_name (Table)
  • column_name (Column)
  • ordinal_position
  • column_default
  • is_nullable
  • data_type
  • precision
  • scale
  • column_size
DataSourceInformation collection
  • CompositeIdentifierSeparatorPattern
  • DataSourceProductName
  • DataSourceProductVersion
  • DataSourceProductVersionNormalized
  • GroupByBehavior
  • IdentifierPattern
  • IdentifierCase
  • OrderByColumnsInSelect
  • ParameterMarkerFormat
  • ParameterMarkerPattern
  • ParameterNameMaxLength
  • ParameterNamePattern
  • QuotedIdentifierPattern
  • QuotedIdentifierCase
  • StatementSeparatorPattern
  • StringLiteralPattern
  • SupportedJoinOperators
DataTypes collection
  • TypeName
  • ProviderDbType
  • ColumnSize
  • CreateFormat
  • CreateParameters
  • DataType
  • IsAutoIncrementable
  • IsBestMatch
  • IsCaseSensitive
  • IsFixedLength
  • IsFixedPrecisionScale
  • IsLong
  • IsNullable
  • IsSearchable
  • IsSearchableWithLike
  • IsUnsigned
  • MaximumScale
  • MinimumScale
  • IsConcurrencyType
  • IsLiteralSupported
  • LiteralPrefix
  • LiteralSuffix
ForeignKeys collection
  • table_schema (Owner)
  • table_name (Table)
  • column_name (Column)
IndexColumns collection
  • table_schema (Owner)
  • table_name (Table)
  • index_name (Name)
  • column_name (Column)
  • order
Indexes collection
  • table_schema (Owner)
  • table_name (Table)
  • index_name (Name)
  • primary_key
  • is_unique
MetaDataCollections collection
  • CollectionName
  • NumberOfRestrictions
  • NumberOfIdentifierParts
ProcedureParameters collection
  • procedure_schema (Owner)
  • procedure_name (Name)
  • parmeter_name (Parameter)
  • data_type
  • parameter_type
  • is_input
  • is_output
Procedures collection
  • procedure_schema (Owner)
  • procedure_name (Name)
ReservedWords collection
  • reserved_word
Restrictions collection
  • CollectionName
  • RestrictionName
  • RestrictionDefault
  • RestrictionNumber
Tables collection
  • table_schema (Owner)
  • table_name (Table)
  • table_type (TableType)
UserDefinedTypes collection
  • data_type
  • default
  • precision
  • scale
Users collection
  • user_name (UserName)
  • resource_auth
  • database_auth
  • schedule_auth
  • user_group
ViewColumns collection
  • view_schema (Owner)
  • view_name (Name)
  • column_name (Column)
Views collection
  • view_schema (Owner)
  • view_name (Name)

 

 

/*
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 – user table
V – view
XP – extended stored procedure
*/

SELECT * FROM sys.systable

SELECT * FROM sysobjects WHERE type = 'U'
select * from customer   --- 查-詢錶
go

SELECT * FROM syscolumns
GO
SELECT * FROM sysobjects
GO


SELECT sys.sysuserperm.user_name
          + '.' 
          + sys.systable.table_name
          + '.' 
          + sys.syscolumn.column_name
   FROM sys.systable,
        sys.syscolumn,
        sys.sysuserperm
  WHERE sys.systable.table_id = sys.syscolumn.table_id
    AND sys.systable.creator = sys.sysuserperm.user_id
    AND sys.sysuserperm.user_name NOT IN ( 'SYS', 'dbo' ) 
    AND sys.systable.table_name NOT LIKE 'pbcat%'
  ORDER BY sys.sysuserperm.user_name,
        sys.systable.table_name,
        sys.syscolumn.column_id
GO

SELECT b.name + '.' + a.name
  FROM sysobjects a, sysusers b
 WHERE a.type IN ('U', 'S')
   AND a.uid = b.uid
 ORDER BY b.name, a.name

  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
using System.Data.SqlClient;


namespace SQLanyWhereDemo
{

    /// <summary>
    /// http://dcx.sybase.com/1101/en/dbprogramming_en11/ianywhere-data-sqlanywhere-saconnection-getschem6330755502-0.html
    /// </summary>
    public partial class Form3 : Form
    {

        string connectionString = @"DSN=geovindu;UID=dba;PWD=sql;";
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        DataTable setDatat()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("name", typeof(string));
            dt.Rows.Add(1, "Procedures");
            dt.Rows.Add(2, "DataTypes");
            dt.Rows.Add(3, "Foreign Keys");
            dt.Rows.Add(4, "Databases");
            dt.Rows.Add(5, "DBA");
            dt.Rows.Add(6, "Arguments");
            dt.Rows.Add(7, "Collection Name");
            dt.Rows.Add(8, "DatasourceInformation");
            dt.Rows.Add(9, "MetaDataCollections");
            dt.Rows.Add(10, "ForeignKeyColumns");
            dt.Rows.Add(11, "Functions");
            dt.Rows.Add(12, "IndexColumns");
            dt.Rows.Add(13, "Indexes");
            dt.Rows.Add(14, "PrimaryKeys");
            dt.Rows.Add(15, "ReservedWords");
            dt.Rows.Add(16, "Restrictions");
            dt.Rows.Add(17, "Triggers");
            dt.Rows.Add(18, "UDFs");
            dt.Rows.Add(19, "UniqueKeys");
            dt.Rows.Add(20, "UserPrivileges");
            dt.Rows.Add(21, "Users");
            dt.Rows.Add(22, "ViewColumns");

            //DataTable dt = connection.GetSchema("Tables", strRestricted);
            dt.Rows.Add(23, "Tables");
            dt.Rows.Add(24, "Columns");//表的列的详细,有主键TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,PRIVILEGES,COLUMN_COMMENT
            dt.Rows.Add(25, "Views");
            dt.Rows.Add(26, "Indexes");//表的列
            dt.Rows.Add(27, "IndexColumns");//主键

            return dt;
        }

        /// <summary>
        /// 
        /// </summary>
        public Form3()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form3_Load(object sender, EventArgs e)
        {
            this.txtConnection.Text = connectionString;
            this.comboBox1.DataSource = setDatat();
            this.comboBox1.DisplayMember = "name";
            this.comboBox1.ValueMember = "id";
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (OdbcConnection connection = new OdbcConnection(connectionString))
                {
                    connection.Open();
                    DataTable dt = connection.GetSchema(this.comboBox1.Text.Trim());
                    this.dataGridView1.DataSource = dt;

                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
    }
}

  

 

SELECT * FROM master.dbo.sysservers

SELECT * FROM Utilities.dbo.sysservers

sp_addremotelogin logical_name

SELECT * FROM master.dbo.sysservers WHERE srvname = “logical_name“

sp_addremotelogin logical_name, local_user_name


create database proxy_db_name on default = 200M with default_location = ‘logical_name.remote_db_name..’

disk init name=”proxy_dev“, physname=”/var/sybase/ASE/proxy_dev.dat“, size=”200M”


select name from proxy_db_name..sysobjects


select name from sademo..sysobjects


alter database proxy_db_name for proxy_update

相关知识

  • 我必须得告诉大家的MySQL优化原理

    说起MySQL的查询优化,相信大家收藏了一堆奇淫技巧:不能使用SELECT *、不使用NULL字段、合理创建索引、为字段选择合适的数据类型..... 你是否真的理解这些优化技巧?是否理解其背后的工作原理?在实际场景下性能真有提升吗?我想未必。因而理解这些优化建议背后的原理就尤为…

    2017/7/19 8:56:00
  • 优化SQL查询:如何写出高性能SQL语句

    1、 首先要搞明白什么叫执行计划?执行计划是数据库根据SQL语句和相关表的统计信息作出的一个查询方案,这个方案是由查询优化器自动分析产生的,比如一条SQL语句如果用来从一个 10万条记录的表中查1条记录,那查询优化器会选择“索引查找”方式,如果该表进行了归…

    2017/7/19 8:56:00
  • memcached与redis实现的对比

    memcached和redis,作为近些年最常用的缓存服务器,相信大家对它们再熟悉不过了。前两年还在学校时,我曾经读过它们的主要源码,如今写篇笔记从个人角度简单对比一下它们的实现方式,权当做复习,有理解错误之处,欢迎指正。文中使用的架构类的图片大多来自于网络,有部分图…

    2017/7/19 8:56:00
  • SQL Server Management Studio 2016 最让人兴奋的10大新功能

    介绍这篇文章列出了SQL Server Management Studio 2016已经取得的一些令人兴奋的改进。我相信,大多数新功能可以帮助我们提升工作速度,更方便地使用SSMS。1.颜色主题随着SSMS 2016的到来,现在你可以选择自己喜欢的颜色主题,类似于Visual Studio中的相似功能。你可以在两种…

    2017/7/19 8:56:00

共有访客发表了评论 网友评论

验证码: 看不清楚?