Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts

Saturday, December 7, 2024

Dynamic Pivot with SQL in SQL Server

 In our example we have a Dynamic Survey form in the database which we would use to take survey of employees across an agency. Now when we have collected the survey we need to generate a report in pivot format which would give u one row per employee and in the columns we would get answers to each question. Interesting!

Lets look at the options available in SQL Server.

To pivot your query and transform it into a format where each row represents an employee and the columns contain answers for each question, you can use a PIVOT operation.

Steps:

  1. Aggregate the Data:

    • Use the base query to gather the employee data, question texts, and their corresponding answers.
  2. Prepare the Pivot:

    • Use the PIVOT operator to dynamically transform rows (questions and answers) into columns for each question.
If the questions are dynamic and you don't know them in advance, you need to dynamically generate the column list using dynamic SQL.

Handling Dynamic Questions:

If the list of questions is not fixed and changes frequently, you can use dynamic SQL to generate the column list automatically.


DECLARE @Columns NVARCHAR(MAX);
DECLARE @SQL NVARCHAR(MAX);

-- Step 1: Generate the Column List Using FOR XML PATH
SELECT @Columns = STUFF((
    SELECT DISTINCT ',' + QUOTENAME(QUESTION)
    FROM QUIZ_QUESTIONS
    WHERE QUESTIONID IN (
        SELECT DISTINCT QUESTIONID
        FROM QUIZ_ATTEMPT_RESULT
        WHERE QUIZASSIGNID IN (SELECT QUIZASSIGNID FROM QUIZ_ASSIGNMENT WHERE QUIZID = 1)
    )
    FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '');

-- Step 2: Construct the Dynamic Pivot Query
SET @SQL = '
WITH BaseData AS (
    SELECT 
        EMPLOYEES.EMPLOYEEID,
        EMPLOYEES.FIRSTNAME + '' '' + EMPLOYEES.LASTNAME AS EmployeeName,
        QUIZ_QUESTIONS.QUESTION AS QuestionText,
        QUIZ_QUESTION_ANSWERS.ANSWER AS Answer
    FROM [dbo].[QUIZ_ASSIGNMENT]
    INNER JOIN EMPLOYEES
        ON EMPLOYEES.EMPLOYEEID = [QUIZ_ASSIGNMENT].EMPLOYEEID
    INNER JOIN [dbo].[QUIZ_ATTEMPT_RESULT]
        ON QUIZ_ATTEMPT_RESULT.QUIZASSIGNID = QUIZ_ASSIGNMENT.QUIZASSIGNID
    INNER JOIN [dbo].[QUIZ_QUESTION_ANSWERS]
        ON QUIZ_QUESTION_ANSWERS.ANSWERID = QUIZ_ATTEMPT_RESULT.ANSWERID
    INNER JOIN [dbo].[QUIZ_QUESTIONS]
        ON QUIZ_QUESTIONS.QUESTIONID = QUIZ_ATTEMPT_RESULT.QUESTIONID
    WHERE QUIZ_ASSIGNMENT.QUIZID = 1
)
SELECT *
FROM (
    SELECT 
        EmployeeName,
        QuestionText,
        Answer
    FROM BaseData
) AS SourceTable
PIVOT (
    MAX(Answer)
    FOR QuestionText IN (' + @Columns + ')
) AS PivotTable;
';

-- Step 3: Execute the Dynamic SQL
EXEC sp_executesql @SQL;


Sample Input Data:

NameQuestionAnswer
John SmithWhat is your name?John
John SmithWhat is your age?30
Jane DoeWhat is your name?Jane
Jane DoeWhat is your age?25


Sample Output Data:

NameWhat is your name?What is your age?
John SmithJohn30
Jane DoeJane25

Friday, March 12, 2010

SQL Server 2005 - Get Size of Databases

EXEC DATABASE.dbo.sp_spaceused

EXEC DATABASE.dbo.sp_spaceused 'TABLE_NAME'

EXEC DATABASE.dbo.sp_spaceused '?'

Saturday, June 27, 2009

Microsoft SQL Server 2008 - Maximum Capacity Specifications

Maximum Capacity Specifications for SQL Server 2008

The following tables specify the maximum sizes and numbers of various objects defined in SQL Server components.

Database Engine Objects

The following table specifies the maximum sizes and numbers of various objects defined in SQL Server databases or referenced in Transact-SQL statements.

SQL Server Database Engine object

Maximum sizes/numbers SQL Server (32-bit)

Maximum sizes/numbers SQL Server (64-bit)

Batch size1

65,536 * Network Packet Size

65,536 * Network Packet Size

Bytes per short string column

8,000

8,000

Bytes per GROUP BY, ORDER BY

8,060

8,060

Bytes per index key2

900

900

Bytes per foreign key

900

900

Bytes per primary key

900

900

Bytes per row8

8,060

8,060

Bytes in source text of a stored procedure

Lesser of batch size or 250 MB

Lesser of batch size or 250 MB

Bytes per varchar(max), varbinary(max), xml, text, or image column

2^31-1

2^31-1

Characters per ntext or nvarchar(max) column

2^30-1

2^30-1

Clustered indexes per table

1

1

Columns in GROUP BY, ORDER BY

Limited only by number of bytes

Limited only by number of bytes

Columns or expressions in a GROUP BY WITH CUBE or WITH ROLLUP statement

10

10

Columns per index key7

16

16

Columns per foreign key

16

16

Columns per primary key

16

16

Columns per nonwide table

1,024

1,024

Columns per wide table

30,000

30,000

Columns per SELECT statement

4,096

4,096

Columns per INSERT statement

4096

4096

Connections per client

Maximum value of configured connections

Maximum value of configured connections

Database size

524,272 terabytes

524,272 terabytes

Databases per instance of SQL Server

32,767

32,767

Filegroups per database

32,767

32,767

Files per database

32,767

32,767

File size (data)

16 terabytes

16 terabytes

File size (log)

2 terabytes

2 terabytes

Foreign key table references per table4

253

253

Identifier length (in characters)

128

128

Instances per computer

50 instances on a stand-alone server for all SQL Server editions except for Workgroup. Workgroup supports a maximum of 16 instances per computer.

SQL Server supports 25 instances on a failover cluster.

50 instances on a stand-alone server.

25 instances on a failover cluster.

Length of a string containing SQL statements (batch size)1

65,536 * Network packet size

65,536 * Network packet size

Locks per connection

Maximum locks per server

Maximum locks per server

Locks per instance of SQL Server5

Up to 2,147,483,647

Limited only by memory

Nested stored procedure levels6

32

32

Nested subqueries

32

32

Nested trigger levels

32

32

Nonclustered indexes per table

999

999

Number of distinct expressions in the GROUP BY clause when any of the following are present: CUBE, ROLLUP, GROUPING SETS, WITH CUBE, WITH ROLLUP

32

32

Number of grouping sets generated by operators in the GROUP BY clause

4,096

4,096

Parameters per stored procedure

2,100

2,100

Parameters per user-defined function

2,100

2,100

REFERENCES per table

253

253

Rows per table

Limited by available storage

Limited by available storage

Tables per database3

Limited by number of objects in a database

Limited by number of objects in a database

Partitions per partitioned table or index

1,000

1,000

Statistics on non-indexed columns

30,000

30,000

Tables per SELECT statement

Limited only by available resources

Limited only by available resources

Triggers per table3

Limited by number of objects in a database

Limited by number of objects in a database

Columns per UPDATE statement (Wide Tables)

4096

4096

User connections

32,767

32,767

XML indexes

249

249

1 Network Packet Size is the size of the tabular data stream (TDS) packets used to communicate between applications and the relational Database Engine. The default packet size is 4 KB, and is controlled by the network packet size configuration option.

2 The maximum number of bytes in any index key cannot exceed 900 in SQL Server. You can define a key using variable-length columns whose maximum sizes add up to more than 900, provided no row is ever inserted with more than 900 bytes of data in those columns. In SQL Server, you can include nonkey columns in a nonclustered index to avoid the maximum index key size of 900 bytes.

3 Database objects include objects such as tables, views, stored procedures, user-defined functions, triggers, rules, defaults, and constraints. The sum of the number of all objects in a database cannot exceed 2,147,483,647.

4 Although a table can contain an unlimited number of FOREIGN KEY constraints, the recommended maximum is 253. Depending on the hardware configuration hosting SQL Server, specifying additional FOREIGN KEY constraints may be expensive for the query optimizer to process.

5 This value is for static lock allocation. Dynamic locks are limited only by memory.

6 If a stored procedure accesses more than 8 databases, or more than 2 databases in interleaving, you will receive an error.

7 If the table contains one or more XML indexes, the clustering key of the user table is limited to 15 columns because the XML column is added to the clustering key of the primary XML index. In SQL Server, you can include nonkey columns in a nonclustered index to avoid the limitation of a maximum of 16 key columns. For more information, see Index with Included Columns.

8 SQL Server supports row-overflow storage which enables variable length columns to be pushed off-row. Only a 24-byte root is stored in the main record for variable length columns pushed out of row; because of this, the effective row limit is higher than in previous releases of SQL Server. For more information, see the "Row-Overflow Data Exceeding 8 KB" topic in SQL Server Books Online.

Wednesday, May 27, 2009

Microsoft SQL Server 2005 - Maximum Capacity Specifications

Maximum Capacity Specifications for SQL Server 2005

The following tables specify the maximum sizes and numbers of various objects defined in Microsoft SQL Server 2005 components.

Database Engine Objects

The following table specifies the maximum sizes and numbers of various objects defined in SQL Server 2005 databases or referenced in Transact-SQL statements. The table does not include SQL Server Windows CE Edition.

SQL Server 2005 Database Engine object

Maximum sizes/numbers SQL Server 2005 (32-bit)

Maximum sizes/numbers SQL Server 2005 (64-bit)

Batch size1

65,536 * Network Packet Size

65,536 * Network Packet Size

Bytes per short string column

8,000

8,000

Bytes per GROUP BY, ORDER BY

8,060

8,060

Bytes per index key2

900

900

Bytes per foreign key

900

900

Bytes per primary key

900

900

Bytes per row8

8,060

8,060

Bytes per varchar(max), varbinary(max), xml, text, or image column

2^31-1

2^31-1

Characters per ntext or nvarchar(max) column

2^30-1

2^30-1

Clustered indexes per table

1

1

Columns in GROUP BY, ORDER BY

Limited only by number of bytes

Limited only by number of bytes

Columns or expressions in a GROUP BY WITH CUBE or WITH ROLLUP statement

10

10

Columns per index key7

16

16

Columns per foreign key

16

16

Columns per primary key

16

16

Columns per base table

1,024

1,024

Columns per SELECT statement

4,096

4,096

Columns per INSERT statement

1,024

1,024

Connections per client

Maximum value of configured connections

Maximum value of configured connections

Database size

524,258 terabytes

524,258 terabytes

Databases per instance of SQL Server

32,767

32,767

Filegroups per database

32,767

32,767

Files per database

32,767

32,767

File size (data)

16 terabytes

16 terabytes

File size (log)

2 terabytes

2 terabytes

Foreign key table references per table4

253

253

Identifier length (in characters)

128

128

Instances per computer

50 instances on a stand-alone server for all SQL Server 2005 editions except for Workgroup Edition. Workgroup Edition supports a maximum of 16 instances.

SQL Server 2005 supports 25 instances on a failover cluster.

50 instances on a stand-alone server.

25 instances on a failover cluster.

Length of a string containing SQL statements (batch size)1

65,536 * Network packet size

65,536 * Network packet size

Locks per connection

Maximum locks per server

Maximum locks per server

Locks per instance of SQL Server5

Up to 2,147,483,647

Limited only by memory

Nested stored procedure levels6

32

32

Nested subqueries

32

32

Nested trigger levels

32

32

Nonclustered indexes per table

249

249

Parameters per stored procedure

2,100

2,100

Parameters per user-defined function

2,100

2,100

REFERENCES per table

253

253

Rows per table

Limited by available storage

Limited by available storage

Tables per database3

Limited by number of objects in a database

Limited by number of objects in a database

Partitions per partitioned table or index

1,000

1,000

Statistics on non-indexed columns

2,000

2,000

Tables per SELECT statement

256

256

Triggers per table3

Limited by number of objects in a database

Limited by number of objects in a database

UNIQUE indexes or constraints per table

249 nonclustered and 1 clustered

249 nonclustered and 1 clustered

User connections

32,767

32,767

XML indexes

249

249

1 Network Packet Size is the size of the tabular data stream (TDS) packets used to communicate between applications and the relational Database Engine. The default packet size is 4 kilobytes (KB), and is controlled by the network packet size configuration option.

2 The maximum number of bytes in any index key cannot exceed 900 in SQL Server 2005. You can define a key using variable-length columns whose maximum sizes add up to more than 900, provided no row is ever inserted with more than 900 bytes of data in those columns. In SQL Server 2005, you can include nonkey columns in a nonclustered index to avoid the maximum index key size of 900 bytes. For more information, see Index with Included Columns.

3 Database objects include objects such as tables, views, stored procedures, user-defined functions, triggers, rules, defaults, and constraints. The sum of the number of all objects in a database cannot exceed 2,147,483,647.

4 Although a table can contain an unlimited number of FOREIGN KEY constraints, the recommended maximum is 253. Depending on the hardware configuration hosting SQL Server, specifying additional foreign key constraints may be expensive for the query optimizer to process.

5 This value is for static lock allocation. Dynamic locks are limited only by memory.

6 If a stored procedure accesses more than 8 databases, or more than 2 databases in interleaving, you will receive an error.

7 If the table contains one or more XML indexes, the clustering key of the user table is limited to 15 columns because the XML column is added to the clustering key of the primary XML index. In SQL Server 2005, you can include nonkey columns in a nonclustered index to avoid the limitation of a maximum of 16 key columns. For more information, see Index with Included Columns.

8 SQL Server 2005 supports row-overflow storage which enables variable length columns to be pushed off-row. Only a 24-byte root is stored in the main record for variable length columns pushed out of row; because of this, the effective row limit is higher than in previous releases of SQL Server. For more information, see the "Row-Overflow Data Exceeding 8 KB" topic in SQL Server 2005 Books Online.

Sunday, May 3, 2009

Using Missing Index Information to Write CREATE INDEX Statements

SELECT 'CREATE NONCLUSTERED INDEX NewNameHere ON ' + sys.schemas.name
+ '.' + sys.objects.name + ' ( ' + mid.equality_columns + CASE WHEN mid.inequality_columns IS NULL
THEN '' ELSE CASE WHEN mid.equality_columns IS NULL
THEN '' ELSE ',' END + mid.inequality_columns END + ' ) ' +
CASE WHEN mid.included_columns IS NULL
THEN '' ELSE 'INCLUDE (' + mid.included_columns + ')' END + ';' AS CreateIndexStatement,
mid.equality_columns, mid.inequality_columns, mid.included_columns
FROM sys.dm_db_missing_index_group_stats AS migs
INNER JOIN sys.dm_db_missing_index_groups AS mig
ON migs.group_handle = mig.index_group_handle
INNER JOIN sys.dm_db_missing_index_details AS mid
ON mig.index_handle = mid.index_handle
INNER JOIN sys.objects WITH (nolock)
ON mid.object_id = sys.objects.object_id
INNER JOIN sys.schemas
ON sys.objects.schema_id = sys.schemas.schema_id
WHERE (migs.group_handle IN ( SELECT TOP 100 PERCENT group_handle
FROM sys.dm_db_missing_index_group_stats WITH (nolock)
ORDER BY (avg_total_user_cost * avg_user_impact) * (user_seeks + user_scans) DESC
AND sys.objects.type = 'U'



MSDN : Using Missing Index Information to Write CREATE INDEX Statements


Brian Knight's blog on the Missing Index DMV




Reference: http://msdn.microsoft.com/en-us/library/ms345405(SQL.90).aspx

Tuesday, April 7, 2009

How to recover a database marked suspect?


SQL Server 2000/2005/2008
Recover database suspect sql server
The following script resets the status of the database and checks the database for integrity.

USE master;

GO

EXEC sp_resetstatus 'MYDATABASE';

GO

USE MYDATABASE;

DBCC CHECKDB WITH NO_INFOMSGS;

GO

SQL Server 2005/2008
Recover database marked suspect sql serve

USE master;

GO

ALTER DATABASE MYDATABASE SET EMERGENCY

GO

ALTER DATABASE MYDATABASE SET SINGLE_USER

GO

DBCC CHECKDB (MYDATABASE, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS;

GO

USE MYDATABASE;

DBCC CHECKDB WITH NO_INFOMSGS;

GO

Friday, April 3, 2009

SQL Server 2005 - Get Size of Database and Individual Tables

-- Get size of Database
EXEC DATABASENAME.dbo.sp_spaceused

-- Get size of a Table in database
EXEC DATABASENAME.dbo.sp_spaceused 'TABLENAME'

-- Get size of All tables in a database
EXEC DATABASENAME.dbo.sp_spaceused '?'

-- Sql Query
USE DATABASENAME
GO
DECLARE @database_size DECIMAL(15,2)
SELECT @database_size = SUM(((convert (dec (15,2),[size]) * 8192 / 1048576)))
FROM dbo.sysfiles
PRINT @database_size

Wednesday, April 1, 2009

SQL - Update table A from table B

-- SIMPLE UPDATE QUERY FROM TABLE A TO B
UPDATE TABLEA
SET TABLEA.[NAME] = TABLEB.[NAME]
FROM TABLEB
WHERE TABLEB.ID = TABLEA.ID

-- USING JOINS
UPDATE TABLEA
SET TABLEA.[NAME] = TABLEB.[NAME]
FROM TABLEB
INNER JOIN TABLEC
ON TABLEC.FIELD1 = TABLEB.FIELD1
WHERE TABLEB.ID = TABLEA.ID

Sunday, March 1, 2009

Track SQL Dependencies

--PAYROLL.dbo.PAY_GETPAYLIST dependents on

EXEC sp_depends @objname = N'PAY_GETPAYLIST' ;

--dependent on PAYROLL.dbo.PAY_GETPAYLIST

EXEC sp_MSdependencies N'dbo.PAY_GETPAYLIST', null, 1315327

--PAYROLL.dbo.PAY_GETPAYLIST dependents on

--oType =1 (Scalar Function), oType =8 (Table)

EXEC sp_MSdependencies N'dbo.PAY_GETPAYLIST', null, 1053183

-- SYS COMMENTS

SELECT distinct so.name

FROM syscomments sc

INNER JOIN sysobjects so ON sc.id = so.id

WHERE charindex('PAY_GETPAYLIST', text) > 0

--INFORMATION_SCHEMA.ROUTINES

SELECT routine_name, routine_type

FROM INFORMATION_SCHEMA.ROUTINES

WHERE ROUTINE_DEFINITION LIKE '%PAY_GETPAYLIST%'

Friday, December 26, 2008

SQL Connection Pooling

Connection pooling increases the performance of Web applications by reusing active database connections instead of creating a new connection with every request. Connection pool manager maintains a pool of open database connections. When a new connection is requested , pool manager checks if the pool contains any unused connections and returns connection if available.


If all connections in the pool are busy and the maximum pool size has not been reached, then new connection is created and added to the pool. When the pool reaches its maximum size all new connection requests are being queued up until a connection in the pool becomes available or the connection attempt times out.

These are four parameters that control most of the connection pooling behavior

Max Pool Size - the maximum size of your connection pool. Default is 100

Min Pool Size - initial number of connections which will be added to the pool upon its creation. Default is zero

Connect Timeout - controls the wait period in seconds when a new connection is requested, if this timeout expires, an exception will be thrown. Default is 15 seconds.

Pooling - controls if your connection pooling on or off. Default as you may've guessed is true. Read on to see when you may use Pooling=false setting.

eg.

connstring="server=myserver;database;abcdefg;Min pool size=5;Max pool size=100;connection timeout=15;pooling=yes"

Most of the Connection problems are because of Connection Leaks

SqlConnection conn=new SqlConnection(constring);
conn.Open();
//do some thing
conn.Close();
while executing the functionality if Exception occurences, then for sure connection wont be closed , to close connection explicitly .. the simple way is ..

SqlConnection conn=new SqlConnection(constring);

try{
conn.Open();
//do some thing
}
finally()
{
conn.Close();
}

SQL Server 2005 Ranking records

What if we want to show a serial number along side with the list of our records, SQL server 2005 gives a simple and nice way to do that, see following query:

SELECT Row_Number() Over (Order By <column_name>) as SNO, <table_name>.*
FROM <table_name>

This query will list all records of a table with a serial number column at start, the Row_Number() function does the trick for us, it requires one column for sorting.

Result:
SNO...
1...
2...
3...
4...
....
....
....
....
....

Designing Triggers

Microsoft® SQL Server™ 2000 provides two options when designing triggers:
INSTEAD OF triggers are executed in place of the usual triggering action. INSTEAD OF triggers can also be defined on views with one or more base tables, where they can extend the types of updates a view can support.

AFTER triggers are executed after the action of the INSERT, UPDATE, or DELETE statement is performed. Specifying AFTER is the same as specifying FOR, which is the only option available in earlier versions of SQL Server. AFTER triggers can be specified only on tables.


This table compares the functionality of the AFTER and INSTEAD OF triggers.


Function

AFTER trigger

INSTEAD OF trigger

Applicability

Tables

Tables and views

Quantity per table or view

Multiple per triggering action (UPDATE, DELETE, and INSERT)

One per triggering action (UPDATE, DELETE, and INSERT)


Cascading references

No restrictions apply

Are not allowed on tables that are targets of cascaded referential integrity constraints.

Execution

After:

  • Constraint processing
  • Declarative referential actions
  • inserted and deleted tables creation
  • The triggering action

Before:

  • Constraint processing

In place of:

  • The triggering action

After:

  • inserted and deleted tables creation

Order of execution

First and last execution may be specified

Not applicable

text, ntext, and image column references in inserted and deleted tables

Not allowed

Allowed

SQL Triggers Order of Execution

DML Triggers:
There can be only one First and one Last trigger for each statement on a single table.
If a First trigger is already defined on the table, database, or server, you cannot designate a new trigger as First for the same table, database, or server for the same statement_type. This restriction also applies Last triggers.
Replication automatically generates a first trigger for any table that is included in an immediate updating or queued updating subscription. Replication requires that its trigger be the first trigger. Replication raises an error when you try to include a table with a first trigger in an immediate updating or queued updating subscription. If you try to make a trigger a first trigger after a table has been included in a subscription, sp_settriggerorder returns an error. If you use ALTER TRIGGER on the replication trigger, or use sp_settriggerorder to change the replication trigger to a Last or None trigger, the subscription does not function correctly.



DDL Triggers:
If a DDL trigger with database scope and a DDL trigger with server scope exist on the same event, you can specify that both triggers be a First trigger or a Last trigger. However, server-scoped triggers always fire first. In general, the order of execution of DDL triggers that exist on the same event is as follows:
1. The server-level trigger marked First.
2. Other server-level triggers.
3. The server-level trigger marked Last.
4. The database-level trigger marked First.
5. Other database-level triggers.
6. The database-level trigger marked Last.



General Trigger Considerations:
If an ALTER TRIGGER statement changes a first or last trigger, the First or Last attribute originally set on the trigger is dropped, and the value is replaced by None. The order value must be reset by using sp_settriggerorder.
If the same trigger must be designated as the first or last order for more than one statement type, sp_settriggerorder must be executed for each statement type. Also, the trigger must be first defined for a statement type before it can be designated as the First or Last trigger to fire for that statement type.



Example:


See sample script below:


--CONNECTING master DATABASE
USE master
go
--BY DEFAULT TRIGGERS ARE FIRED IN THE ORDER THEY ARE CREATED
set nocount on
go
--CREATED A TEMPORARY TABLE
create table dbo.customer (customerid int identity primary key)
go
--FIRST TRIGGER
create trigger dbo.tr_customer_1 on dbo.customer
for insert
as
set nocount on
print 'firing original trigger 1'
go
--SECOND TRIGGER
create trigger dbo.tr_customer_2 on dbo.customer
for insert
as
set nocount on
print 'firing original trigger 2'
go
--THIRD TRIGGER
create trigger dbo.tr_customer_3 on dbo.customer
for insert
as
set nocount on
print 'firing original trigger 3'
go
print 'Inserting row with default order of triggers'
go
--EXECUTED A SIMPLE INSERT QUERY
insert into dbo.customer default values
go

/*CHANGE TRIGGER ORDER*/
exec sp_settriggerorder @triggername = 'tr_customer_1',
@order = 'first',
@stmttype = 'insert',
@namespace = null

exec sp_settriggerorder @triggername = 'tr_customer_2',
@order = 'last',
@stmttype = 'insert',
@namespace = null

exec sp_settriggerorder @triggername = 'tr_customer_3',
@order = 'none',
@stmttype = 'insert',
@namespace = null
go
print 'Inserting row with modified order of triggers'
go
--AGAIN EXECUTED A SAMPLE QUERY
insert into dbo.customer default values
go
drop table dbo.customer
go