sql语句查询数据库中的表名/列名/主键/自动增长
网络编程 2021-07-05 13:42www.168986.cn编程入门
sql语句查询数据库中的表名/列名/主键/自动增长值实例,需要的朋友可以参考下
sql语句查询数据库中的表名/列名/主键/自动增长值
----查询数据库中用户创建的表
----jsj01 为数据库名
select name tablename from jsj01..sysobjects where type='U' and name not in ('dtproperties')
--查询表里的字段信息
---docs为表名
---- select from syscolumns where id = object_id('docs')
----查询数据库中所有类型
----select name,xtype from systypes
----两表联查,显示表中所有字段和对应的数据类型
----syscolumns里字段‘xtype' 对应 systypes里的 ‘xusertype' ,systypes 里的‘name'字段就是字段的数据类型
----docs 为表名
select a.name as fieldname,b.name as type from
syscolumns as a
join systypes as b
on a.xtype = b.xusertype
where id=object_id('docs')
----docs为数据表名 查询表字段、类型、说明
select a.name fieldname,b.name type,c.value ment from
syscolumns as a
full join systypes as b
on a.xtype = b.xusertype
full join ::fn_listextendedproperty(NULL, 'user', 'dbo', 'table', 'docs', 'column', default) as c ----这是2000版本,2005把user改为schema
on a.name=c.objname COLLATE Chinese_PRC_CI_AS -----排序规则(有时不加也可以,如果两表的排序规则不同,则会报错)
--join sysproperties c
--on a.id=c.major_id
where id=object_id('docs')
----查询表里的主键,没有主键为空,如果是多个组合主键就有多个值 pk为主键 fk为外键
--- jsj01 为数据库名 docs为表名 fk表示外键
select column_name as primarykey, from
[jsj01].INFORMATION_SCHEMA.KEY_COLUMN_USAGE
where Table_name='docs' and constraint_name like 'fk_%'
--select from sysobjects WHERE OBJECT_NAME(sysobjects.parent_obj)='docs' --and xtype='pk'
--select from sysconstraints where id = object_id('docs')
--select from syscolumns where id = object_id('docs')
--select from sysindexes
--select from sysindexkeys
----查询表中自动增长的字段,没有为空,如果有就只有一个
----docs为表名
SELECT a.name column_name,b.name data_type
FROM syscolumns a,systypes b
WHERE a.id=object_id('docs') and a.xtype = b.xusertype
AND a.autoval is not null
作者 pukuimin1226
----查询数据库中用户创建的表
----jsj01 为数据库名
select name tablename from jsj01..sysobjects where type='U' and name not in ('dtproperties')
--查询表里的字段信息
---docs为表名
---- select from syscolumns where id = object_id('docs')
----查询数据库中所有类型
----select name,xtype from systypes
----两表联查,显示表中所有字段和对应的数据类型
----syscolumns里字段‘xtype' 对应 systypes里的 ‘xusertype' ,systypes 里的‘name'字段就是字段的数据类型
----docs 为表名
select a.name as fieldname,b.name as type from
syscolumns as a
join systypes as b
on a.xtype = b.xusertype
where id=object_id('docs')
----docs为数据表名 查询表字段、类型、说明
select a.name fieldname,b.name type,c.value ment from
syscolumns as a
full join systypes as b
on a.xtype = b.xusertype
full join ::fn_listextendedproperty(NULL, 'user', 'dbo', 'table', 'docs', 'column', default) as c ----这是2000版本,2005把user改为schema
on a.name=c.objname COLLATE Chinese_PRC_CI_AS -----排序规则(有时不加也可以,如果两表的排序规则不同,则会报错)
--join sysproperties c
--on a.id=c.major_id
where id=object_id('docs')
----查询表里的主键,没有主键为空,如果是多个组合主键就有多个值 pk为主键 fk为外键
--- jsj01 为数据库名 docs为表名 fk表示外键
select column_name as primarykey, from
[jsj01].INFORMATION_SCHEMA.KEY_COLUMN_USAGE
where Table_name='docs' and constraint_name like 'fk_%'
--select from sysobjects WHERE OBJECT_NAME(sysobjects.parent_obj)='docs' --and xtype='pk'
--select from sysconstraints where id = object_id('docs')
--select from syscolumns where id = object_id('docs')
--select from sysindexes
--select from sysindexkeys
----查询表中自动增长的字段,没有为空,如果有就只有一个
----docs为表名
SELECT a.name column_name,b.name data_type
FROM syscolumns a,systypes b
WHERE a.id=object_id('docs') and a.xtype = b.xusertype
AND a.autoval is not null
作者 pukuimin1226
上一篇:教你怎么使用sql游标实例分享
下一篇:分享整理的12条sql语句连同数据
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指