平时工作一会搞Oracle一会搞SqlServer,脑子都迷糊了,为了避免继续模糊,今天抽出点时间把我常用的sqlserver的一些东西整理了下,发出来,以后忘了就来找,过几天再整理个Oracle常用知识。没啥技术含量主要是备忘。
1.SQLserver忘记密码修改方法
从"查询分析器"中以"Windows身份验证"连接SQL Server 执行如下过程
EXEC sp_password NULL, ''你的新密码'', ''用户名例如sa''
2.更改当前数据库中对象的所有者。
EXEC sp_changeobjectowner ''dbo.对象名例如表名'', ''新所有者''
3.SQLSERVER与SQLSERVER之间的分布式查询
建立连接服务器
exec sp_addlinkedserver ''TESTLINK'','''',''SQLOLEDB'',''远程数据库的ip地址''
创建链接服务器上远程登录之间的映射
exec sp_addlinkedsrvlogin ''TESTLINK'',''false'',null,''SA'',''密码''
查询示例
select * from TESTLINK.库名.dbo.表名
4.查看库中全部的表
CREATE VIEW dbo.ALL_TABLES
AS
SELECT top 100 PERCENT a.ID,
CASE WHEN a.colorder = 1 THEN d.name ELSE '''' END AS TableName,
CASE WHEN a.colorder = 1 THEN isnull(f.value, '''') ELSE '''' END AS 表说明,
a.colorder AS 字段序号, a.name AS 字段名,
ISNULL(g.[value], '''') AS 字段说明, CASE WHEN COLUMNPROPERTY(a.id,
a.name, ''IsIdentity'') = 1 THEN ''√'' ELSE '''' END AS 标识,
CASE WHEN EXISTS
(SELECT 1
FROM dbo.sysindexes si INNER JOIN
dbo.sysindexkeys sik ON si.id = sik.id AND si.indid = sik.indid INNER JOIN
dbo.syscolumns sc ON sc.id = sik.id AND sc.colid = sik.colid INNER JOIN
dbo.sysobjects so ON so.name = si.name AND so.xtype = ''PK''
WHERE sc.id = a.id AND sc.colid = a.colid) THEN ''√'' ELSE '''' END AS 主键,
b.name AS 类型, a.length AS 长度, COLUMNPROPERTY(a.id, a.name, ''PRECISION'')
AS 精度, ISNULL(COLUMNPROPERTY(a.id, a.name, ''Scale''), 0) AS 小数位数,