Home Database Mysql Tutorial mssql 数据库重命名及错误分析

mssql 数据库重命名及错误分析

Jun 07, 2016 pm 05:47 PM
database nbsp server sp sql

mssql 重命名及错误分析

1. 查看数据库的版本    
   select @@version
   常见的几种SQL SERVER打补丁后的版本号:
   8.00.194   Microsoft SQL Server 2000 
   8.00.384   Microsoft SQL Server 2000 SP1 
   8.00.532   Microsoft SQL Server 2000 SP2 
   8.00.760   Microsoft SQL Server 2000 SP3 
   8.00.818   Microsoft SQL Server 2000 SP3 w/ Cumulative Patch MS03-031 
   8.00.2039  Microsoft SQL Server 2000 SP4  
2. 查看数据库所在机器操作系统参数    
   exec master..xp_msver
3. 查看数据库启动的参数        
   sp_configure
4. 查看数据库启动时间        
   select convert(varchar(30),login_time,120) from master..sysprocesses

where spid=1
   查看数据库服务器名和实例名
   print 'Server Name...............: ' + convert(varchar(30),@@SERVERNAME) 

      
   print 'Instance..................: ' + convert(varchar(30),@@SERVICENAME)

     
5. 查看所有数据库名称及大小
   sp_helpdb
   重命名数据库用的SQL
   sp_renamedb 'old_dbname', 'new_dbname'
6. 查看所有数据库用户登录信息
   sp_helplogins
   查看所有数据库用户所属的角色信息    
   sp_helrvrolemember
   修复迁移服务器时孤立用户时,可以用的fix_orphan_user脚本或者LoneUser过程
   更改某个数据对象的用户属主
   sp_changeobjectowner [@objectname =] 'object', [@newowner =] 'owner'
   注意: 更改对象名的任一部分都可能破坏脚本和存储过程。
   把一台服务器上的数据库用户登录信息备份出来可以用add_login_to_aserver脚本
   查看某数据库下,对象级用户权限
   sp_helprotect
7. 查看链接服务器        
   sp_helplinkedsrvlogin
   查看远端数据库用户登录信息    
   sp_helpremotelogin
8.查看某数据库下某个数据对象的大小
   sp_spaceused @objname
   还可以用sp_toptables过程看最大的N(默认为50)个表
   查看某数据库下某个数据对象的索引信息
   sp_helpindex @objname
   还可以用SP_NChelpindex过程查看更详细的索引情况
   SP_NChelpindex @objname
   clustered索引是把记录按物理顺序排列的,索引占的空间比较少。 
   对键值DML操作十分频繁的表我建议用非clustered索引和约束,fillfactor参数都

用默认值。
   查看某数据库下某个数据对象的的约束信息
   sp_helpconstraint @objname
9.查看数据库里所有的存储过程和函数
   use @database_name
   sp_stored_procedures
   查看存储过程和函数的源代码
   sp_helptext '@procedure_name'
   查看包含某个字符串@str的数据对象名称
   select distinct object_name(id) from syscomments where text like '%@str%'
   创建加密的存储过程或函数在AS前面加WITH ENCRYPTION参数
   解密加密过的存储过程和函数可以用sp_decrypt过程
10.查看数据库里用户和进程的信息
   sp_who
   查看SQL Server数据库里的活动用户和进程的信息
   sp_who 'active'
   查看SQL Server数据库里的锁的情况
   sp_lock
   进程号1--50是SQL Server系统内部用的,进程号大于50的才是用户的连接进程.
   spid是进程编号,dbid是数据库编号,objid是数据对象编号
   查看进程正在执行的SQL语句
   dbcc inputbuffer ()
   推荐大家用经过改进后的sp_who3过程可以直接看到进程运行的SQL语句
   sp_who3
   检查死锁用sp_who_lock过程
   sp_who_lock    
11.查看和收缩数据库日志文件的方法
   查看所有数据库日志文件大小          
   dbcc sqlperf(logspace)
   如果某些日志文件较大,收缩简单恢复模式数据库日志,收缩后

@database_name_log的大小单位为M
   backup log @database_name with no_log
   dbcc shrinkfile (@database_name_log, 5)
12.分析SQL Server SQL 语句的方法:
   set statistics time {on | off}
   set statistics io {on | off}
   图形方式显示查询执行计划
   在查询分析器->查询->显示估计的评估计划(D)-Ctrl-L 或者点击工具栏里的图形
   文本方式显示查询执行计划
   set showplan_all {on | off}
   set showplan_text { on | off }
   set statistics profile { on | off }
13.出现不一致错误时,NT事件查看器里出3624号错误,修复数据库的方法
   先注释掉应用程序里引用的出现不一致性错误的表,然后在备份或其它机器上先恢

复然后做修复操作
   alter database [@error_database_name] set single_user
   修复出现不一致错误的表
   dbcc checktable('@error_table_name',repair_allow_data_loss)
   或者可惜选择修复出现不一致错误的小型数据库名
   dbcc checkdb('@error_database_name',repair_allow_data_loss)
   alter database [@error_database_name] set multi_user
   CHECKDB 有3个参数:
   repair_allow_data_loss 包括对行和页进行分配和取消分配以改正分配错误、结构

行或页的错误,以及删除已损坏的文本对象,这些修复可能会导致一些数据丢失。
   修复操作可以在用户事务下完成以允许用户回滚所做的更改。
   如果回滚修复,则数据库仍会含有错误,应该从备份进行恢复。
   如果由于所提供修复等级的缘故遗漏某个错误的修复,则将遗漏任何取决于该修复

的修复。
   修复完成后,请备份数据库。 
   repair_rest 进行小的、不耗时的修复操作,如修复非聚集索引中的附加键。
   这些修复可以很快完成,并且不会有丢失数据的危险。 
   repair_rebuild 执行由 repair_rest 完成的所有修复,包括需要较长时间的修复

(如重建索引)。
  执行这些修复时不会有丢失数据的危险。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

What is the difference between HQL and SQL in Hibernate framework? What is the difference between HQL and SQL in Hibernate framework? Apr 17, 2024 pm 02:57 PM

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

How to solve discuz database error How to solve discuz database error Nov 20, 2023 am 10:10 AM

The solutions to discuz database error are: 1. Check the database configuration; 2. Make sure the database server is running; 3. Check the database table status; 4. Back up the data; 5. Clear the cache; 6. Reinstall Discuz; 7. Check the server resources ; 8. Contact Discuz official support. Solving Discuz database errors requires starting from multiple aspects, gradually identifying the cause of the problem, and taking corresponding measures to repair it.

See all articles