SQL Server系统表的使用

1. 如何取得一个数据表的所有列名
方法如下:先从sysobjects系统表中取得数据表的systemid,然后再syscolumns表中取得该数据表的所有列名。
SQL语句如下:

SQL Code
 
2. 通过SQL语句来更改用户的密码
修改别人的,需要sysadmin role 
 
Exec Sp_password '原始密码','更改后密码','账号'
Exec sp_password null,ok,sa

 

3. 怎么判断出一个表的哪些字段不允许为空?

Declare @objname Varchar(50)
set @objname = 'ColumnToRow'
Select Column_Name from information_schema.Columns where is_nullable = 'No' and Table_Name = @objname

 

4. 如何在数据库里找到含有相同字段的表?

SQL Code

 

5.查询第N行数据
假设id是主键: 

select * 
from (select top N * from 表) aa 
where not exists(select 1 from (select top N-1 * from 表) bb where aa.id=bb.id)

 

6.查询某一个表的字段和数据类型

select column_name,data_type 
from information_schema.columns
where table_name = '表名' 

 

7.几个用法

SQL Code

 

8.获取某一个表的所有字段

select name from syscolumns where id=object_id('表名')

 

9.查询用户创建的所有数据库

SQL Code


 

posted on 2009-07-08 11:18  尤章金的博客  阅读(309)  评论(0编辑  收藏  举报

导航