Search the Blog

Tuesday, August 31, 2021

SQL Error Type List with description

Error Type =1001,/n Error Description Line %d: Length or precision specification %d is invalid.. Error Severity  Level=16

Resolve Error 40: Could Not Open a Connection to SQL Server

Error Type =1002, Error Description Line %d: Specified scale %d is invalid.. Error Severity  Level=16

Microsoft SQL Server Error 5242 – Resolved with Best Tips & Tricks

Error Type =1003, Error Description Line %d: %ls clause allowed only for %ls.. Error Severity  Level=15

Error Type =1004, Error Description Invalid column prefix '%.*ls': No table name specified. Error Severity  Level=16

Error Type =1005, Error Description Line %d: Invalid procedure number (%d). Must be between 1 and 32767.. Error Severity  Level=15

Error Type =1006, Error Description CREATE TRIGGER contains no statements.. Error Severity  Level=15

Error Type =1007, Error Description The %S_MSG '%.*ls' is out of the range for numeric representation (maximum precision 38).. Error Severity  Level=15

Error Type =1008, Error Description The SELECT item identified by the ORDER BY number %d contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name.. Error Severity  Level=15

Error Type =1010, Error Description Invalid escape character '%.*ls'.. Error Severity  Level=15

Error Type =1011, Error Description The correlation name '%.*ls' is specified multiple times in a FROM clause.. Error Severity  Level=15

Error Type =1012, Error Description The correlation name '%.*ls' has the same exposed name as table '%.*ls'.. Error Severity  Level=15

Error Type =1013, Error Description Tables or functions "Object Name" and "Object Name" have the same exposed names. Use correlation names to distinguish them.. Error Severity  Level=15

Error Type =1014, Error Description TOP clause contains an invalid value.. Error Severity  Level=15

Error Type =1015, Error Description An aggregate cannot appear in an ON clause unless it is in a subquery contained in a HAVING clause or select list, and the column being aggregated is an outer reference.. Error Severity  Level=15

Error Type =1016, Error Description Outer join operators cannot be specified in a query containing joined tables.. Error Severity  Level=15

Error Type =1019, Error Description Invalid column list after object name in GRANT/REVOKE statement.. Error Severity  Level=15

Error Type =1020, Error Description Column list cannot be specified for object-level permissions.. Error Severity  Level=15

Error Type =1021, Error Description FIPS Warning: Line %d has the non-ANSI statement '%ls'.. Error Severity  Level=10

Error Type =1022, Error Description FIPS Warning: Line %d has the non-ANSI clause '%ls'.. Error Severity  Level=10

Error Type =1023, Error Description Invalid parameter %d specified for %ls.. Error Severity  Level=15

Error Type =1024, Error Description FIPS Warning: Line %d has the non-ANSI function '%ls'.. Error Severity  Level=10

Error Type =1025, Error Description FIPS Warning: The length of identifier '%.*ls' exceeds 18.. Error Severity  Level=10

Error Type =1027, Error Description Too many expressions are specified in the GROUP BY clause. The maximum number is %d when either CUBE or ROLLUP is specified.. Error Severity  Level=15

Error Type =1028, Error Description The CUBE and ROLLUP options are not allowed in a GROUP BY ALL clause.. Error Severity  Level=15

Error Type =1029, Error Description Browse mode is invalid for subqueries and derived tables.. Error Severity  Level=15

Error Type =1031, Error Description Percent values must be between 0 and 100.. Error Severity  Level=15

Error Type =1032, Error Description Cannot use the column prefix '%.*ls'. This must match the object in the UPDATE clause '%.*ls'.. Error Severity  Level=15

Error Type =1033, Error Description The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.. Error Severity  Level=15

Error Type =1035, Error Description Incorrect syntax near '%.*ls', expected '%.*ls'.. Error Severity  Level=15

Error Type =1036, Error Description File option %hs is required in this CREATE/ALTER DATABASE statement.. Error Severity  Level=15

Error Type =1037, Error Description The CASCADE, WITH GRANT or AS options cannot be specified with statement permissions.. Error Severity  Level=15

Error Type =1038, Error Description Cannot use empty object or column names. Use a single space if necessary.. Error Severity  Level=15

Error Type =1039, Error Description Option '%.*ls' is specified more than once.. Error Severity  Level=15

Error Type =1040, Error Description Mixing old and new syntax in CREATE/ALTER DATABASE statement is not allowed.. Error Severity  Level=15

Error Type =1041, Error Description Option %.*ls is not allowed for a LOG file.. Error Severity  Level=15

Error Type =1042, Error Description Conflicting %ls optimizer hints specified.. Error Severity  Level=15

Error Type =1043, Error Description %hs' is not yet implemented.. Error Severity  Level=15

Error Type =1044, Error Description Cannot use an existing function name to specify a stored procedure name.. Error Severity  Level=15

Error Type =1045, Error Description Aggregates are not allowed in this context. Only scalar expressions are allowed.. Error Severity  Level=15

Error Type =1046, Error Description Subqueries are not allowed in this context. Only scalar expressions are allowed.. Error Severity  Level=15

Error Type =1047, Error Description Conflicting locking hints specified.. Error Severity  Level=15

Error Type =1048, Error Description Conflicting cursor options %ls and %ls.. Error Severity  Level=15

Error Type =1049, Error Description Mixing old and new syntax to specify cursor options is not allowed.. Error Severity  Level=15

Error Type =1050, Error Description This syntax is only allowed within the stored procedure sp_executesql.. Error Severity  Level=15

Error Type =, Error Description The collation '%.*ls' of receiving variable is not equal to the collation '%.*ls' of column '%.*ls'.. Error Severity  Level=16

Error Type =1051, Error Description Cursor parameters in a stored procedure must be declared with OUTPUT and VARYING options, and they must be specified in the order CURSOR VARYING OUTPUT.. Error Severity  Level=15

Error Type =1052, Error Description Conflicting %ls options %ls and %ls.. Error Severity  Level=15

Error Type =1053, Error Description For DROP STATISTICS, you must give both the table and the column name in the form 'tablename.column'.. Error Severity  Level=15

Error Type =1054, Error Description Syntax '*' is not allowed in schema-bound objects.. Error Severity  Level=15

Error Type =1055, Error Description %.*ls' is an invalid name because it contains a NULL character.. Error Severity  Level=15

Error Type =1056, Error Description The maximum number of elements in the select list is %d and you have supplied %d.. Error Severity  Level=15

Error Type =1057, Error Description The IDENTITY function cannot be used with a SELECT INTO statement containing a UNION operator.. Error Severity  Level=15

Error Type =1058, Error Description Cannot specify both READ_ONLY and FOR READ ONLY on a cursor declaration.. Error Severity  Level=15

Error Type =1059, Error Description Cannot set or reset the %ls option within a procedure.. Error Severity  Level=15

Error Type =1060, Error Description The number of rows in the TOP clause must be an integer.. Error Severity  Level=15

Error Type =1061, Error Description The text/ntext/image constants are not yet implemented.. Error Severity  Level=16

Error Type =1062, Error Description The TOP N WITH TIES clause is not allowed without a corresponding ORDER BY clause.. Error Severity  Level=16

Error Type =1063, Error Description A filegroup cannot be added using ALTER DATABASE ADD FILE. Use ALTER DATABASE ADD FILEGROUP.. Error Severity  Level=16

Error Type =1064, Error Description A filegroup cannot be used with log files.. Error Severity  Level=16

Error Type =1065, Error Description The NOLOCK, READUNCOMMITTED, and READPAST lock hints are only allowed in a SELECT statement.. Error Severity  Level=15

Error Type =1066, Error Description Warning. Line %d: The option '%ls' is obsolete and has no effect.. Error Severity  Level=10

Error Type =1067, Error Description The SET SHOWPLAN statements must be the only statements in the batch.. Error Severity  Level=15

Error Type =1068, Error Description Only one list of index hints per table is allowed.. Error Severity  Level=16

Error Type =1069, Error Description Index hints are only allowed in a FROM clause.. Error Severity  Level=16

Error Type =1070, Error Description CREATE INDEX option '%.*ls' is no longer supported.. Error Severity  Level=15

Error Type =1071, Error Description Cannot specify a JOIN algorithm with a remote JOIN.. Error Severity  Level=16

Error Type =1072, Error Description A REMOTE hint can only be specified with an INNER JOIN clause.. Error Severity  Level=16

Error Type =1073, Error Description %.*ls' is not a recognized cursor option for cursor %.*ls.. Error Severity  Level=15

Error Type =1074, Error Description Creation of temporary functions is not allowed.. Error Severity  Level=15

Error Type =1075, Error Description RETURN statements in scalar valued functions must include an argument.. Error Severity  Level=15

Error Type =1076, Error Description Function '%s' requires at least %d argument(s).. Error Severity  Level=15

Error Type =1077, Error Description INSERT into an identity column not allowed on table variables.. Error Severity  Level=15

Error Type =1078, Error Description %.*ls %.*ls' is not a recognized option.. Error Severity  Level=15

Error Type =1079, Error Description A variable cannot be used to specify a search condition in a fulltext predicate when accessed through a cursor.. Error Severity  Level=15

Error Type =1101, Error Description Could not allocate new page for database '%.*ls'. There are no more pages available in filegroup %.*ls. Space can be created by dropping objects, adding additional files, or allowing file growth.. Error Severity  Level=17

Error Type =1102, Error Description IAM page %S_PGID for object ID %ld is incorrect. The %S_MSG ID on page is %ld; should be %ld. The entry in sysindexes may be incorrect or the IAM page may contain an error.. Error Severity  Level=22

Error Type =1103, Error Description Allocation page %S_PGID in database '%.*ls' has different segment ID than that of the object which is being allocated to. Run DBCC CHECKALLOC.. Error Severity  Level=21

Error Type =1105, Error Description Could not allocate space for object '%.*ls' in database '%.*ls' because the '%.*ls' filegroup is full.. Error Severity  Level=17

Error Type =1109, Error Description Could not read allocation page %S_PGID because either the object ID (%ld) is not correct, or the page ID (%S_PGID) is not correct.. Error Severity  Level=21

Error Type =1203, Error Description Process ID %d attempting to unlock unowned resource %.*ls.. Error Severity  Level=20

Error Type =1204, Error Description The SQL Server cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users or ask the system administrator to check the SQL Server lock and memory configuration.. Error Severity  Level=19

Error Type =1205, Error Description Transaction (Process ID %d) was deadlocked on {%Z} resources with another process and has been chosen as the deadlock victim. Rerun the transaction.. Error Severity  Level=13

Error Type =1206, Error Description Transaction manager has canceled the distributed transaction.. Error Severity  Level=18

Error Type =1211, Error Description Process ID %d was chosen as the deadlock victim with P_BACKOUT bit set.. Error Severity  Level=13

Error Type =1220, Error Description No more lock classes available from transaction.. Error Severity  Level=17

Error Type =1222, Error Description Lock request time out period exceeded.. Error Severity  Level=13

Error Type =1223, Error Description Attempting to release application lock '%.*ls' that is not currently held.. Error Severity  Level=16

Friday, August 27, 2021

SQl Server Query to delete the All Object execpt the specific schema

 USE Temp_data


DECLARE @Procedure_name NVARCHAR(MAX)

DECLARE @QUERY NVARCHAR(MAX)

DECLARE @Table_name NVARCHAR(MAX)


SELECT  CONCAT(a.name,'.',b.name)  as proc_name into #Temp_proc_name FROM SYS.schemas  A

INNER JOIN SYS.procedures B ON A.schema_id = B.schema_id

WHERE A.name != 'dbo'


WHILE EXISTS ( SELECT 1 FROM #Temp_proc_name )

BEGIN

SET @Procedure_name =  (SELECT top 1 proc_name from #Temp_proc_name order by proc_name desc)

SET @QUERY = N'DROP PROCEDURE ' + @Procedure_name;

EXECUTE sp_executesql @QUERY


DELETE FROM #Temp_proc_name WHERE proc_name = @Procedure_name

END



SELECT  CONCAT(a.name,'.',b.name)  as table_name into #Temp_table_name FROM SYS.schemas  A

INNER JOIN SYS.tables B ON A.schema_id = B.schema_id

WHERE A.name != 'dbo'


WHILE EXISTS ( SELECT 1 FROM #Temp_table_name )

BEGIN

SET @Table_name =  (SELECT top 1 table_name from #Temp_table_name order by table_name desc)

SET @QUERY = N'DROP TABLE ' + @Table_name;

EXECUTE sp_executesql @QUERY


DELETE FROM #Temp_table_name WHERE table_name = @Table_name

END

DROP TABLE #Temp_table_name

DROP TABLE #Temp_proc_name






Thursday, August 26, 2021

INDEXED VIEW IN SQL SERVER and Materialized Views in Oracle

 INDEXED VIEW IN SQL SERVER

 

Indexed View is similar to Materialized Views. Indexed Views used in SQL server and Materialized Views used in Oracle.

Indexed Views

The Result Set is stored in the Database. Query Performance can be dramatically enhanced using Indexed Views. Create an Indexed View by implementing a UNIQUE CLUSTERED index on the view. The results of the view are stored in the leaf-level pages of the clustered index.

An Iindexed View automatically reflects modifications made to the data in the base tables after the index is created, the same way an index created on a base table does. As modifications are made to the data in the base tables, the data modifications are also reflected in the data stored in the indexed view. The requirement that the clustered index of the view be unique improves the efficiency with which SQL Server can find the rows in the index that are affected by any data modification.

Guidelines for Creating Indexed Views

The SQL Server Query Optimizer automatically determines whether a given query will benefit from using an Index View.

Create Indexed Views when:

1. The performance gain of improved speed in retrieving results outweighs the increased maintenance cost.

2. The underlying data is infrequently updated.

3. Queries perform a significant number of joins and aggregations that either process many rows or are performed frequently by many users.

Restrictions on Creating Indexed Views

Consider the following guidelines:

1. The first index that you create on the view must be a UNIQUE CLUSTRERD index

2. You must create the view with the SCHEMABINDING option.

3. The view can reference base tables, but it cannot reference other views.

4. You must use two-part names to reference tables.

For example: -

 

CREATE VIEW VW_EXAMPLE

WITH SCHEMABINDING

AS

SELECT SUM(UnitPrice * Quantity * (1.00-Discount)) As Rev,

OrderDate, ProductID, COUNT_BIG() AS COUNT

FROM dbo.[Order_details] od

INNER JOIN dbo.Orders O

WHERE od.OrderID = O.OrderID

GROUP BY OrderDate, ProductID


----- Create UNIQUE CLUSTERED index on the view

CREATE UNIQUE CLUSTERED INDEX INDEX_VW_EXAMPLE
  ON VW_EXAMPLE (OrderDate, ProductID)

WITH SCHEMABINDING

We bind the object to the schema of all the underlying tables and views. This means that the underlying tables and views cannot be modified in a way that would affect the definition of the schema-bound object.

NOTE:

 

For schema binding, SQL server requires a more specific and safer SELECT statement. There are a couple of restrictions, which we must remember:

1. We must use two-part names, when referencing tables, views or functions (SchemaName.ObjectName).

2. We cannot use SELECT *, so we must choose specific column names. Otherwise, we will get the following error:

For example:

CREATE VIEW dbo.vwName

WITH SCHEMABINDING

AS

SELECT * FROM dbo.Employee

 

It shows you below error: -

Msg 1054, Level 15, State 6, Procedure vwName, Line x

Syntax ‘*’ is not allowed in schema-bound objects.

 

Materialized Views

Materialized view in SQL is also a logical structure which is stored physically on the disc. Like a view in Materialized views in SQL we are using simple select statement to create it. You should have created materialized views privileges to create a Materialized view. Definition of Materialized views (called as MV) has been stored in databases.  

 

 

Materialized views in SQL Syntax and Examples:

“Materialized views are also known as snapshots.”

Snapshots acts like a physical table because data from snapshots are storing in to physical memory. Snapshot retrieves data very fast. So, for performance tuning Snapshots are used. Following is the syntax of materialized view:

Create materialized view View_Name

 

Build [Immediate/Deffered]

 

Refresh [Fast/Complete/Force]

 

on [Commit/Demand]

 

as Select ..........;

 

Using above syntax, you can create materialized views. The Syntax includes some different optional fields:

1.Build Immediate: Means materialized views(mv) created immediately.

2.Build Deferred: Means materialized views(mv) created after one refresh.

3.Refresh on commit:

This option committed the data in materialized views in SQL immediately after data inserted and committed in table. This option is known as incremental refresh option. View is not fully refreshed with this option

4.Refresh on Demand:

Using this option, you can add the condition for refreshing data in materialized views.

 

 

Translate