Full Trust European Hosting

BLOG about Full Trust Hosting and Its Technology - Dedicated to European Windows Hosting Customer

SQL Server 2019 Hosting - HostForLIFEASP.NET :: Query to Repair Suspect Database In SQL Server

clock January 29, 2021 06:43 by author Peter

Query to Repair Suspect Database In SQL Server
This is the query to repair suspect database in SQL Server. 
If your Database is marked as suspected, here are the steps to fix it.
In this you have replace “dbName” with suspected db name and run this query in master database.

Step 1
--command to recover suspected database

ALTER DATABASE DbName SET EMERGENCY

DBCC checkdb('DbName')

ALTER DATABASE DbName SET SINGLE_USER WITH ROLLBACK IMMEDIATE

DBCC CheckDB ('DbName', REPAIR_ALLOW_DATA_LOSS)

ALTER DATABASE DbName SET MULTI_USER


This step 1 cannot set Index created for that database so now we have to rebuild the index. This query should be run in that suspected database.

Step 2
-- command to rebuild all indexes
EXEC sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?', ' ', 80)"



Europe SQL Hosting - HostForLIFEASP.NET :: SQL Comments Statement

clock January 15, 2021 08:10 by author Peter

SQL Comments statement can make your application easier for you to read and maintain. For example, we can include a comment in a statement that describes the purpose of the statement within your application with the exception of hints, comments within SQL. The statement does not affect the statement execution. Please refer to using hints on using this particular form of comment statement.  
 

A comment can appear between any keywords, parameters, or punctuation marks in a statement. You can include a comment in a statement in two ways:
    Begin the comment with a slash and an asterisk (/*). Proceed with the text of the comment. This text can span multiple lines.
    End the comment with an asterisk and a slash (*/). The opening and terminating characters need not be separated from the text by a space or a line break.
    Begin the comment with -- (two hyphens). Proceed with the text of the comment. This text cannot extend to a new line. End the comment with a line break.

Some of the tools used to enter SQL have additional restrictions. For example, if you are using SQL*plus, by default you cannot have a blank line inside a multiline comment.
 
For more information, please refer to the documentation for the tool you use as an interface to the database. A SQL statement can contain multiple comments of both styles. The text of a comment can contain any printable characters in your database character set.
 
The comment statement indicates the user-provided text. Comments can be inserted on a separate line, nested at the end of a SQL command line, or within a SQL statement. The server does not evaluate the comment.  
 
SQL Comment uses the two hyphens (--) for single-line or nested comments. Comments inserted with -- are terminated by a new line, which is specified with a carriage return. Character (U+000A), line feed character (U+000D), or a combination of the two in SQL comments.
 
There is no maximum length for comments. The following table lists the keyboard shortcuts that you can use to comment or uncomment text.
 
Syntax
    -- text_of_comment     

Examples
The following example uses the -- commenting characters.
 
Syntax
    -- Choose the sample database.      
    USE sample;      
    GO      
    -- Choose all columns and all rows from the Address table.      
    SELECT *      
    FROM OrderDetails      
    ORDER BY OrderId  ASC; -- We do not have to specify ASC because       
    -- that is the default.      


SQL Single Line Comments
Single line comments start with --. Any text between -- and the end of the line will be ignored (will not be executed). The following example uses a single-line comment as an explanation.
 
Syntax  
    --Select all:    
    SELECT * FROM OrderDetails ;  


The following example uses a single-line comment to ignore the end of a line.
 
Syntax
    SELECT * FROM OrderDetails -- WHERE OrderName='Coffee';   

The following example uses a single-line comment to ignore a statement.
 
Syntax
    --SELECT * FROM OrderDetails;    
    SELECT * FROM OrderDetails ;   


SQL Multi-line Comments
SQL Multi-line comments start with /* and end with */. Any text between /* and */ will be ignored. The following example uses a multi-line comment as an explanation.
 
Syntax  
    /*Select all the columns    
    of all the records    
    in the OrderDetails table:*/    
    SELECT * FROM OrderDetails;   

The following example uses a multi-line comment to ignore many statements.
 
Syntax
    /*SELECT * FROM Customers;    
    SELECT * FROM Products;    
    SELECT * FROM Orders;    
    SELECT * FROM Categories;*/    
    SELECT * FROM OrderDetails; 
 

To ignore just a part of a statement, also use the /* */ comment. The following example uses a comment to ignore part of a line.
 
Syntax
    SELECT CustomerName, /*City,*/ Country FROM Customers;   

The following example uses a comment to ignore part of a statement
 
Syntax
    SELECT * FROM OrderDetails WHERE (OrderName LIKE 'L%'    
    OR OrderName LIKE 'R%' /*OR OrderName  LIKE 'S%'    
    OR OrderName LIKE 'T%'*/ OR OrderName LIKE 'W%')    
    AND OrderName ='Mango'    
    ORDER BY OrderrAddress;   


In this article, you learned how to use a SQL Comments statement with various options.



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Tag cloud

Sign in