SQL Server 根据表名获取表的所有列及属性(数据同步服务数据分析需要)
来源:互联网 发布:jdk 6u45 windows x64 编辑:程序博客网 时间:2024/06/06 16:31
实例一:
select a.name columnname,c.name as typename,case when a.is_nullable =0 then 'Not Null' else 'Null' end as nullable,a.*
from sys.columns a , sys.objects b, sys.types c
where a.object_id= b.object_id and b.name='表名' and a.system_type_id=c.system_type_id order by a.column_id
实例二:
select
c.name as [字段名],t.name as [字段类型]
,convert(bit,c.IsNullable) as [可否为空]
,convert(bit,case when exists(select 1 from sysobjects where xtype='PK' and parent_obj=c.id and name in (
select name from sysindexes where indid in(
select indid from sysindexkeys where id = c.id and colid=c.colid))) then 1 else 0 end)
as [是否主键]
,convert(bit,COLUMNPROPERTY(c.id,c.name,'IsIdentity')) as [自动增长]
,c.Length as [占用字节]
,COLUMNPROPERTY(c.id,c.name,'PRECISION') as [长度]
,isnull(COLUMNPROPERTY(c.id,c.name,'Scale'),0) as [小数位数]
,ISNULL(CM.text,'') as [默认值]
,isnull(ETP.value,'') AS [字段描述]
--,ROW_NUMBER() OVER (ORDER BY C.name) AS [Row]
from syscolumns c
inner join systypes t on c.xusertype = t.xusertype
left join sys.extended_properties ETP on ETP.major_id = c.id and ETP.minor_id = c.colid and ETP.name ='MS_Description'
left join syscomments CM on c.cdefault=CM.id
where c.id = object_id('表名')
实例三:
SELECT NAME FROM SYSOBJECTS WHERE XTYPE='U' ORDER BY name ASC
实例四:(ping网络链路通信情况检测):
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Net.NetworkInformation;
namespace SynchronizationService
{
public class InternetHelp
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(int Description, int ReservedValue);
#region 方法一
/// <summary>
/// 用于检查网络是否可以连接互联网,true表示连接成功,false表示连接失败
/// </summary>
/// <returns></returns>
public static bool IsConnectInternet()
{
int Description = 0;
return InternetGetConnectedState(Description, 0);
}
#endregion
#region 方法二
/// <summary>
/// 用于检查IP地址或域名是否可以使用TCP/IP协议访问(使用Ping命令),true表示Ping成功,false表示Ping失败
/// </summary>
/// <param name="strIpOrDName">输入参数,表示IP地址或域名</param>
/// <returns></returns>
public static bool PingIpOrDomainName(string strIpOrDName)
{
try
{
Ping objPingSender = new Ping();
PingOptions objPinOptions = new PingOptions();
objPinOptions.DontFragment = true;
string data = "";
byte[] buffer = Encoding.UTF8.GetBytes(data);
int intTimeout = 120;
PingReply objPinReply = objPingSender.Send(strIpOrDName, intTimeout, buffer, objPinOptions);
string strInfo = objPinReply.Status.ToString();
if (strInfo == "Success")
{
return true;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
}
#endregion
}
}
其它代码不一一贴出........
c.name as [字段名],t.name as [字段类型]
,convert(bit,c.IsNullable) as [可否为空]
,convert(bit,case when exists(select 1 from sysobjects where xtype='PK' and parent_obj=c.id and name in (
select name from sysindexes where indid in(
select indid from sysindexkeys where id = c.id and colid=c.colid))) then 1 else 0 end)
as [是否主键]
,convert(bit,COLUMNPROPERTY(c.id,c.name,'IsIdentity')) as [自动增长]
,c.Length as [占用字节]
,COLUMNPROPERTY(c.id,c.name,'PRECISION') as [长度]
,isnull(COLUMNPROPERTY(c.id,c.name,'Scale'),0) as [小数位数]
,ISNULL(CM.text,'') as [默认值]
,isnull(ETP.value,'') AS [字段描述]
--,ROW_NUMBER() OVER (ORDER BY C.name) AS [Row]
from syscolumns c
inner join systypes t on c.xusertype = t.xusertype
left join sys.extended_properties ETP on ETP.major_id = c.id and ETP.minor_id = c.colid and ETP.name ='MS_Description'
left join syscomments CM on c.cdefault=CM.id
where c.id = object_id('表名')
实例三:
SELECT NAME FROM SYSOBJECTS WHERE XTYPE='U' ORDER BY name ASC
实例四:(ping网络链路通信情况检测):
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Net.NetworkInformation;
namespace SynchronizationService
{
public class InternetHelp
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(int Description, int ReservedValue);
#region 方法一
/// <summary>
/// 用于检查网络是否可以连接互联网,true表示连接成功,false表示连接失败
/// </summary>
/// <returns></returns>
public static bool IsConnectInternet()
{
int Description = 0;
return InternetGetConnectedState(Description, 0);
}
#endregion
#region 方法二
/// <summary>
/// 用于检查IP地址或域名是否可以使用TCP/IP协议访问(使用Ping命令),true表示Ping成功,false表示Ping失败
/// </summary>
/// <param name="strIpOrDName">输入参数,表示IP地址或域名</param>
/// <returns></returns>
public static bool PingIpOrDomainName(string strIpOrDName)
{
try
{
Ping objPingSender = new Ping();
PingOptions objPinOptions = new PingOptions();
objPinOptions.DontFragment = true;
string data = "";
byte[] buffer = Encoding.UTF8.GetBytes(data);
int intTimeout = 120;
PingReply objPinReply = objPingSender.Send(strIpOrDName, intTimeout, buffer, objPinOptions);
string strInfo = objPinReply.Status.ToString();
if (strInfo == "Success")
{
return true;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
}
#endregion
}
}
其它代码不一一贴出........
0 0
- SQL Server 根据表名获取表的所有列及属性(数据同步服务数据分析需要)
- SQL获取SQL Server 根据表名获取表的所有列及属性
- [MSSQL]Sql Server根据表名获取表的所有列及属性
- SQL Server 根据表名获取表的所有列及属性
- SQL Server 中获取数据库内所有表名的实现方法
- 如何获取SQL Server所有的数据库名、表名、字段名及字段类型?
- 获取sql server数据库中所有用户表名及在sql server中怎样用sql得到库中所有的表名以及表的结构(列名和数据类型)
- SQL Server中获取所有数据库名、所有表名、所有字段名的SQL语句
- sql查询分析器:获取表名、获取表所有列、执行sql、根据bostype获取表名
- 查询SQL Server中某个表的所有列名
- 【SQL】中获取特定表的所有列名
- 获取所有数据名、数据库表名
- [SQL]Oracle,SqlServer,根据表名获取主键列名
- Mysql 查询数据含某一列名的所有表
- 获取SQL Server所有数据库名,表名,字段名
- 根据数据动态显示列及数据的SQL语句
- 数据库:读取指定表的所有列名&读取指定表某一列的所有数据
- asp.net获取SQL所有数据库名、所有表名、所有字段名、列描述
- Java系列-Socket网络编程,TCP/IP和Http等网络协议理解
- ABAP modify screen:修改屏幕,实现隐藏、禁止输入字段
- spring类扫描注入-----类扫描的注解解析器
- 移动应用实战(移动OA)之三_客户端与服务端数据通讯
- 在OpenWrt上移植fcgiwrap为nginx提供cgi支持
- SQL Server 根据表名获取表的所有列及属性(数据同步服务数据分析需要)
- 从热更新到Nuwa源码分析
- 算法导论第五章
- Redis安装配置教程
- 安卓开发不得不收集的工具类
- 一个管理nginx和php-fpm的脚本
- Struts环境搭建
- Data URI scheme - 数据的uri模式
- RunLoop