sql 脚本
select [name] from [sysdatabases] order by [name]
查询一个数据库中的所有表
select [id], [name] from [sysobjects] where [type] = 'u' and status>0
都知道[type] = 'u' 是用户表,[type] = 's'是系统表吧。
根据上个语句的查询结果然后再
查询一个表中的所有字段(我尝试不用[ID],而用[name]去查,结果报错了)
select [name] from [syscolumns] where [id] = 1931153925
查询表结构
SELECT table_name,column_name,column_default,
is_nullable,data_type,character_maximum_length
FROM INFORMATION_SCHEMA.COLUMNS
SELECT table_name as '表名',column_name as '列名',data_type as '类型',
character_maximum_length as '长度',column_default as '默认值',is_nullable as '是否为空'
FROM INFORMATION_SCHEMA.COLUMNS
where table_name in(select name from sysobjects where xtype='u' and status>0)
order by table_name
将孤立的用户名关联
sp_change_users_login 'report'
sp_change_users_login 'update_one','OAS','OAS'
sp_change_users_login 'Auto_Fix', 'test', NULL, 'testpassword'
查询一个数据库中的所有表
select [id], [name] from [sysobjects] where [type] = 'u' and status>0
都知道[type] = 'u' 是用户表,[type] = 's'是系统表吧。
根据上个语句的查询结果然后再
查询一个表中的所有字段(我尝试不用[ID],而用[name]去查,结果报错了)
select [name] from [syscolumns] where [id] = 1931153925
查询表结构
SELECT table_name,column_name,column_default,
is_nullable,data_type,character_maximum_length
FROM INFORMATION_SCHEMA.COLUMNS
SELECT table_name as '表名',column_name as '列名',data_type as '类型',
character_maximum_length as '长度',column_default as '默认值',is_nullable as '是否为空'
FROM INFORMATION_SCHEMA.COLUMNS
where table_name in(select name from sysobjects where xtype='u' and status>0)
order by table_name
将孤立的用户名关联
sp_change_users_login 'report'
sp_change_users_login 'update_one','OAS','OAS'
sp_change_users_login 'Auto_Fix', 'test', NULL, 'testpassword'