[{"data":1,"prerenderedAt":1072},["ShallowReactive",2],{"article-generate-insert-update-delete-trigger-for-table-audit":3},{"article":4,"tags":186,"previous":201,"next":776},{"id":5,"title":6,"author":7,"body":8,"createdAt":177,"description":178,"extension":179,"img":32,"meta":180,"navigation":157,"path":181,"seo":182,"stem":183,"tags":184,"updatedAt":177,"__hash__":185},"articles\u002Farticles\u002Fgenerate-insert-update-delete-trigger-for-table-audit.md","Generate Insert, Update, Delete Trigger for Table Audit","[object Object]",{"type":9,"value":10,"toc":175},"minimark",[11,19,37,40,50,171],[12,13,14,15,18],"p",{}," ",[16,17],"br",{},"\nThe following script will evaluate the table specified @TableName (you provide below), create a new table with {name}_Audit and also create insert, update and delete triggers.  In my example my table was Dave_Test in scheme engis.",[12,20,21,22,24],{},"Here is a screen shot of the end result audit table with the same columns PLUS 2 additional columns to document the action executed against the source table.",[16,23],{},[25,26,28],"a",{"href":27},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-generate-insert-update-delete-trigger-fo_9e1f-image_2.png",[29,30],"img",{"style":31,"src":32,"border":33,"alt":34,"title":34,"width":35,"height":36},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-generate-insert-update-delete-trigger-fo_9e1f-image_thumb.png",0,"image",521,109,[12,38,39],{},"Here you can see the created _Audit table and newly created _Trigger_Delete, _Trigger_Insert and _Trigger_Update",[12,41,42],{},[25,43,45],{"href":44},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-generate-insert-update-delete-trigger-fo_9e1f-image_6.png",[29,46],{"style":31,"src":47,"border":33,"alt":34,"title":34,"width":48,"height":49},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-generate-insert-update-delete-trigger-fo_9e1f-image_thumb_2.png",240,183,[51,52,57],"pre",{"className":53,"code":54,"language":55,"meta":56,"style":56},"language-sql shiki shiki-themes github-light github-dark","SET ANSI_NULLS ON; GO SET QUOTED_IDENTIFIER ON; GO  \nDECLARE @TableName VARCHAR(200); \nSET @TableName = 'dave_test'; \n-- SET NOCOUNT ON added to prevent extra result sets from \n-- interfering with SELECT statements. \nSET NOCOUNT ON; \n--DECLARE @TABLENAME varchar(100) \nDECLARE @SCHEMA VARCHAR(100); \n--SET @TABLENAME = N'Company' SET @SCHEMA = N'engis';\nDECLARE @Done BIT;\nSET @Done = 0 DECLARE @CRLF CHAR(2);\nSET @CRLF = CHAR(10); DECLARE @SQL VARCHAR(2000); \nSET @SQL = 'IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Audit]'') AND type in (N''U'')) DROP TABLE [' + @SCHEMA + '].[' + @TableName + '_Audit] CREATE TABLE [' + @SCHEMA + '].[' + @TableName + '_Audit] (' + @CRLF; DECLARE @COLUMNID INT; SET @COLUMNID = 0; DECLARE @COLUMNNAME VARCHAR(1000); DECLARE @COLUMNTYPE VARCHAR(100); DECLARE @COLUMNSIZE INT; WHILE @Done = 0 BEGIN SELECT TOP 1 @COLUMNID = clmns.column_id , @COLUMNNAME = clmns.name , @COLUMNTYPE = usrt.name , @COLUMNSIZE = CAST(CASE WHEN baset.name IN ( N'nchar', N'nvarchar' ) AND clmns.max_length &lt;&gt; -1 THEN clmns.max_length \u002F 2 ELSE clmns.max_length END AS INT) FROM sys.tables AS tbl INNER JOIN sys.all_columns AS clmns ON clmns.object_id = tbl.object_id LEFT OUTER JOIN sys.types AS usrt ON usrt.user_type_id = clmns.user_type_id LEFT OUTER JOIN sys.types AS baset ON baset.user_type_id = clmns.system_type_id AND baset.user_type_id = baset.system_type_id WHERE ( tbl.name = @TableName AND SCHEMA_NAME(tbl.schema_id) = @SCHEMA ) AND clmns.column_id &gt; @COLUMNID ORDER BY clmns.column_id ASC; IF @@rowcount = 0 BEGIN SET @Done = 1; END; ELSE BEGIN SET @SQL = @SQL + ' [' + @COLUMNNAME + '] [' + @COLUMNTYPE + '] '; IF ( @COLUMNTYPE = 'nchar' OR @COLUMNTYPE = 'nvarchar' OR @COLUMNTYPE = 'varchar' ) SET @SQL = @SQL + '(' + LTRIM(STR(@COLUMNSIZE)) + ') '; \nSET @SQL = @SQL + 'NULL, ' + @CRLF; END; END; SET @SQL = @SQL + ' [' + @TableName + 'UpdateDate] datetime, [' + @TableName + 'UpdateAction] nvarchar(10) ) '; --print @SQL EXEC (@SQL);\nSET @SQL = ' IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Update]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Update] IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete] IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert] '; --print @SQL EXEC(@SQL); SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Update] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER UPDATE AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Update'' FROM inserted END '; EXEC (@SQL); --print @SQL SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER DELETE AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Delete'' FROM deleted END ';\n\nEXEC (@SQL); --print @SQL SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER INSERT AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Insert'' FROM inserted END '; EXEC (@SQL);\n--print @SQL\n","sql","",[58,59,60,68,74,80,86,92,98,104,110,116,122,128,134,140,146,152,159,165],"code",{"__ignoreMap":56},[61,62,65],"span",{"class":63,"line":64},"line",1,[61,66,67],{},"SET ANSI_NULLS ON; GO SET QUOTED_IDENTIFIER ON; GO  \n",[61,69,71],{"class":63,"line":70},2,[61,72,73],{},"DECLARE @TableName VARCHAR(200); \n",[61,75,77],{"class":63,"line":76},3,[61,78,79],{},"SET @TableName = 'dave_test'; \n",[61,81,83],{"class":63,"line":82},4,[61,84,85],{},"-- SET NOCOUNT ON added to prevent extra result sets from \n",[61,87,89],{"class":63,"line":88},5,[61,90,91],{},"-- interfering with SELECT statements. \n",[61,93,95],{"class":63,"line":94},6,[61,96,97],{},"SET NOCOUNT ON; \n",[61,99,101],{"class":63,"line":100},7,[61,102,103],{},"--DECLARE @TABLENAME varchar(100) \n",[61,105,107],{"class":63,"line":106},8,[61,108,109],{},"DECLARE @SCHEMA VARCHAR(100); \n",[61,111,113],{"class":63,"line":112},9,[61,114,115],{},"--SET @TABLENAME = N'Company' SET @SCHEMA = N'engis';\n",[61,117,119],{"class":63,"line":118},10,[61,120,121],{},"DECLARE @Done BIT;\n",[61,123,125],{"class":63,"line":124},11,[61,126,127],{},"SET @Done = 0 DECLARE @CRLF CHAR(2);\n",[61,129,131],{"class":63,"line":130},12,[61,132,133],{},"SET @CRLF = CHAR(10); DECLARE @SQL VARCHAR(2000); \n",[61,135,137],{"class":63,"line":136},13,[61,138,139],{},"SET @SQL = 'IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Audit]'') AND type in (N''U'')) DROP TABLE [' + @SCHEMA + '].[' + @TableName + '_Audit] CREATE TABLE [' + @SCHEMA + '].[' + @TableName + '_Audit] (' + @CRLF; DECLARE @COLUMNID INT; SET @COLUMNID = 0; DECLARE @COLUMNNAME VARCHAR(1000); DECLARE @COLUMNTYPE VARCHAR(100); DECLARE @COLUMNSIZE INT; WHILE @Done = 0 BEGIN SELECT TOP 1 @COLUMNID = clmns.column_id , @COLUMNNAME = clmns.name , @COLUMNTYPE = usrt.name , @COLUMNSIZE = CAST(CASE WHEN baset.name IN ( N'nchar', N'nvarchar' ) AND clmns.max_length &lt;&gt; -1 THEN clmns.max_length \u002F 2 ELSE clmns.max_length END AS INT) FROM sys.tables AS tbl INNER JOIN sys.all_columns AS clmns ON clmns.object_id = tbl.object_id LEFT OUTER JOIN sys.types AS usrt ON usrt.user_type_id = clmns.user_type_id LEFT OUTER JOIN sys.types AS baset ON baset.user_type_id = clmns.system_type_id AND baset.user_type_id = baset.system_type_id WHERE ( tbl.name = @TableName AND SCHEMA_NAME(tbl.schema_id) = @SCHEMA ) AND clmns.column_id &gt; @COLUMNID ORDER BY clmns.column_id ASC; IF @@rowcount = 0 BEGIN SET @Done = 1; END; ELSE BEGIN SET @SQL = @SQL + ' [' + @COLUMNNAME + '] [' + @COLUMNTYPE + '] '; IF ( @COLUMNTYPE = 'nchar' OR @COLUMNTYPE = 'nvarchar' OR @COLUMNTYPE = 'varchar' ) SET @SQL = @SQL + '(' + LTRIM(STR(@COLUMNSIZE)) + ') '; \n",[61,141,143],{"class":63,"line":142},14,[61,144,145],{},"SET @SQL = @SQL + 'NULL, ' + @CRLF; END; END; SET @SQL = @SQL + ' [' + @TableName + 'UpdateDate] datetime, [' + @TableName + 'UpdateAction] nvarchar(10) ) '; --print @SQL EXEC (@SQL);\n",[61,147,149],{"class":63,"line":148},15,[61,150,151],{},"SET @SQL = ' IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Update]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Update] IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete] IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N''[' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert]'')) DROP TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert] '; --print @SQL EXEC(@SQL); SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Update] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER UPDATE AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Update'' FROM inserted END '; EXEC (@SQL); --print @SQL SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Delete] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER DELETE AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Delete'' FROM deleted END ';\n",[61,153,155],{"class":63,"line":154},16,[61,156,158],{"emptyLinePlaceholder":157},true,"\n",[61,160,162],{"class":63,"line":161},17,[61,163,164],{},"EXEC (@SQL); --print @SQL SET @SQL = 'CREATE TRIGGER [' + @SCHEMA + '].[' + @TableName + '_Trigger_Insert] ON [' + @SCHEMA + '].[' + @TableName + '] AFTER INSERT AS BEGIN SET NOCOUNT ON; INSERT INTO ' + @TableName + '_Audit SELECT *,getdate(),''Insert'' FROM inserted END '; EXEC (@SQL);\n",[61,166,168],{"class":63,"line":167},18,[61,169,170],{},"--print @SQL\n",[172,173,174],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":56,"searchDepth":70,"depth":70,"links":176},[],"2016-02-13T07:03:23.3300000-05:00"," \nThe following script will evaluate the table specified @TableName (you provide below), create a new table with {name}_Audit and also create insert, update and delete triggers.  In my example my table was Dave_Test in scheme engis.","md",{},"\u002Farticles\u002Fgenerate-insert-update-delete-trigger-for-table-audit",{"title":6,"description":178},"articles\u002Fgenerate-insert-update-delete-trigger-for-table-audit",[55],"Dt6NMP0mx0GNm-szVZbRfyE2hv-az2OeYHLGEoaDFqU",[187],{"id":188,"title":189,"body":190,"description":194,"extension":179,"img":195,"meta":196,"name":55,"navigation":157,"path":197,"seo":198,"stem":199,"__hash__":200},"tags\u002Ftags\u002Fsql.md","Sql",{"type":9,"value":191,"toc":192},[],{"title":56,"searchDepth":70,"depth":70,"links":193},[],"SQL is a standard language designed for managing data in relational database management system. SQL stands for Structured Query Language. SQL is a standard programming language specifically designed for storing, retrieving, managing or manipulating the data inside a relational database management system (RDBMS).","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Fsql",{"description":194},"tags\u002Fsql","HleFpAIKGUPMxp855dHtmfuv32MNyIbaOTi0ZjW_I1k",{"id":202,"title":203,"author":7,"body":204,"createdAt":768,"description":208,"extension":179,"img":762,"meta":769,"navigation":157,"path":770,"seo":771,"stem":772,"tags":773,"updatedAt":768,"__hash__":775},"articles\u002Farticles\u002Fxamarin-android-fragments-and-orientations-rotation.md","Xamarin Android - Fragments and Orientations\u002FRotation",{"type":9,"value":205,"toc":766},[206,209,212,215,226,229,259,262,371,374,430,433,738,764],[12,207,208],{},"When you rotate\u002Fchange the orientation of your Android application the Activity will be destroyed and recreated.  What this means is that any variables, fragments will be destroyed when the user changes the orientation of their device (say going from portrait to landscape).  Your users will hate you.  For example, If they are filling out a form and by accident the orientation changes all fields entered will be lost.",[12,210,211],{},"How can we avoid this bad experience? There are a few ways.",[12,213,214],{},"Within the OnCreate of the Activity you can force the orientation to one or the other.  A user can rotate the device however the user interface does not change orientation.",[51,216,220],{"className":217,"code":218,"language":219,"meta":56,"style":56},"language-csharp shiki shiki-themes github-light github-dark","RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;\n","csharp",[58,221,222],{"__ignoreMap":56},[61,223,224],{"class":63,"line":64},[61,225,218],{},[12,227,228],{},"Using an attribute on the class will lock the orientation.  The following ignores the orientation and the screen size changes.  This is easy however the difficulty is that your application will not be responsive to size\u002Forientation changes.  Your application will respond to different screen sizes or orientation.  This too can be less than optimum.",[51,230,232],{"className":217,"code":231,"language":219,"meta":56,"style":56},"[Activity(Label = \"AppDave\", MainLauncher = true, Icon = \"@drawable\u002Ficon\", \nTheme = \"@style\u002FMyTheme\", ConfigurationChanges = Android.Content.PM.ConfigChanges.ScreenSize | Android.Content.PM.ConfigChanges.Orientation)]  \npublic class MainActivity : AppCompatActivity  \n{  \n}\n",[58,233,234,239,244,249,254],{"__ignoreMap":56},[61,235,236],{"class":63,"line":64},[61,237,238],{},"[Activity(Label = \"AppDave\", MainLauncher = true, Icon = \"@drawable\u002Ficon\", \n",[61,240,241],{"class":63,"line":70},[61,242,243],{},"Theme = \"@style\u002FMyTheme\", ConfigurationChanges = Android.Content.PM.ConfigChanges.ScreenSize | Android.Content.PM.ConfigChanges.Orientation)]  \n",[61,245,246],{"class":63,"line":76},[61,247,248],{},"public class MainActivity : AppCompatActivity  \n",[61,250,251],{"class":63,"line":82},[61,252,253],{},"{  \n",[61,255,256],{"class":63,"line":88},[61,257,258],{},"}\n",[12,260,261],{},"In the following example I have an application with three fragments.   The first fragment with tag “Fragment1” gets set when the application loads.  I will use this tag as the test to see if the activity has started at least one time.  Within the OnCreate method I check to see if the Activity has run by checking SupportFragmentManager.FindFragmentByTag(“Fragment1”).",[51,263,265],{"className":217,"code":264,"language":219,"meta":56,"style":56},"if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n{  \n    if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n        _fragment1 = SupportFragmentManager.FindFragmentByTag(\"Fragment1\") as Fragment1;  \n  \n    if (SupportFragmentManager.FindFragmentByTag(\"Fragment2\") != null)  \n        _fragment2 = SupportFragmentManager.FindFragmentByTag(\"Fragment2\") as Fragment2;  \n  \n    if (SupportFragmentManager.FindFragmentByTag(\"Fragment3\") != null)  \n        _fragment3 = SupportFragmentManager.FindFragmentByTag(\"Fragment3\") as Fragment3;  \n}  \nelse  \n{  \n    \u002F\u002Fno fragments in the container  \n    _fragment1 = new Fragment1();  \n      \n    var trans = SupportFragmentManager.BeginTransaction();  \n    trans.Add(Resource.Id.fragmentContainer, _fragment1, \"Fragment1\");                  \n    trans.Commit();  \n    _currentFragment = _fragment1;  \n}\n",[58,266,267,272,276,281,286,291,296,301,305,310,315,320,325,329,334,339,344,349,354,360,366],{"__ignoreMap":56},[61,268,269],{"class":63,"line":64},[61,270,271],{},"if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n",[61,273,274],{"class":63,"line":70},[61,275,253],{},[61,277,278],{"class":63,"line":76},[61,279,280],{},"    if (SupportFragmentManager.FindFragmentByTag(\"Fragment1\") != null)  \n",[61,282,283],{"class":63,"line":82},[61,284,285],{},"        _fragment1 = SupportFragmentManager.FindFragmentByTag(\"Fragment1\") as Fragment1;  \n",[61,287,288],{"class":63,"line":88},[61,289,290],{},"  \n",[61,292,293],{"class":63,"line":94},[61,294,295],{},"    if (SupportFragmentManager.FindFragmentByTag(\"Fragment2\") != null)  \n",[61,297,298],{"class":63,"line":100},[61,299,300],{},"        _fragment2 = SupportFragmentManager.FindFragmentByTag(\"Fragment2\") as Fragment2;  \n",[61,302,303],{"class":63,"line":106},[61,304,290],{},[61,306,307],{"class":63,"line":112},[61,308,309],{},"    if (SupportFragmentManager.FindFragmentByTag(\"Fragment3\") != null)  \n",[61,311,312],{"class":63,"line":118},[61,313,314],{},"        _fragment3 = SupportFragmentManager.FindFragmentByTag(\"Fragment3\") as Fragment3;  \n",[61,316,317],{"class":63,"line":124},[61,318,319],{},"}  \n",[61,321,322],{"class":63,"line":130},[61,323,324],{},"else  \n",[61,326,327],{"class":63,"line":136},[61,328,253],{},[61,330,331],{"class":63,"line":142},[61,332,333],{},"    \u002F\u002Fno fragments in the container  \n",[61,335,336],{"class":63,"line":148},[61,337,338],{},"    _fragment1 = new Fragment1();  \n",[61,340,341],{"class":63,"line":154},[61,342,343],{},"      \n",[61,345,346],{"class":63,"line":161},[61,347,348],{},"    var trans = SupportFragmentManager.BeginTransaction();  \n",[61,350,351],{"class":63,"line":167},[61,352,353],{},"    trans.Add(Resource.Id.fragmentContainer, _fragment1, \"Fragment1\");                  \n",[61,355,357],{"class":63,"line":356},19,[61,358,359],{},"    trans.Commit();  \n",[61,361,363],{"class":63,"line":362},20,[61,364,365],{},"    _currentFragment = _fragment1;  \n",[61,367,369],{"class":63,"line":368},21,[61,370,258],{},[12,372,373],{},"I am going through this backwards but this is the method that I am using to replace the current fragment with a new one.  Notice however that I am adding it with a specified tag so that we can recover it later",[51,375,377],{"className":217,"code":376,"language":219,"meta":56,"style":56},"private void ReplaceFragment(SupportFragment fragment, string tag)  \n{  \n    if (fragment.IsVisible)  \n        return;  \n  \n    var trans = SupportFragmentManager.BeginTransaction();             \n    trans.Replace(Resource.Id.fragmentContainer, fragment, tag);  \n    trans.AddToBackStack(null);  \n    trans.Commit();  \n    _currentFragment = fragment;  \n}\n",[58,378,379,384,388,393,398,402,407,412,417,421,426],{"__ignoreMap":56},[61,380,381],{"class":63,"line":64},[61,382,383],{},"private void ReplaceFragment(SupportFragment fragment, string tag)  \n",[61,385,386],{"class":63,"line":70},[61,387,253],{},[61,389,390],{"class":63,"line":76},[61,391,392],{},"    if (fragment.IsVisible)  \n",[61,394,395],{"class":63,"line":82},[61,396,397],{},"        return;  \n",[61,399,400],{"class":63,"line":88},[61,401,290],{},[61,403,404],{"class":63,"line":94},[61,405,406],{},"    var trans = SupportFragmentManager.BeginTransaction();             \n",[61,408,409],{"class":63,"line":100},[61,410,411],{},"    trans.Replace(Resource.Id.fragmentContainer, fragment, tag);  \n",[61,413,414],{"class":63,"line":106},[61,415,416],{},"    trans.AddToBackStack(null);  \n",[61,418,419],{"class":63,"line":112},[61,420,359],{},[61,422,423],{"class":63,"line":118},[61,424,425],{},"    _currentFragment = fragment;  \n",[61,427,428],{"class":63,"line":124},[61,429,258],{},[12,431,432],{},"And finally I will show the method that responds to a menu selection which calls the ReplaceFragment method",[51,434,436],{"className":217,"code":435,"language":219,"meta":56,"style":56},"public override bool OnOptionsItemSelected(IMenuItem item)  \n{      \n    switch (item.ItemId)  \n    {                  \n        case Android.Resource.Id.Home:  \n            \u002F\u002FThe hamburger icon was clicked which means the drawer toggle will handle the event  \n            \u002F\u002Fall we need to do is ensure the right drawer is closed so the don't overlap  \n            _drawerLayout.CloseDrawer(_rightDrawer);  \n            _drawerToggle.OnOptionsItemSelected(item);  \n            return true;  \n  \n        \u002F\u002Fcase Resource.Id.action_refresh:  \n        \u002F\u002F    \u002F\u002FRefresh  \n        \u002F\u002F    return true;  \n  \n        case Resource.Id.action_fragment1:  \n            \u002F\u002FShowFragment(_fragment1);  \n  \n            if (_fragment1 == null)                      \n                _fragment1 = new Fragment1();            \n                  \n                ReplaceFragment(_fragment1, \"Fragment1\");  \n            return true;  \n        case Resource.Id.action_fragment2:  \n            \u002F\u002FShowFragment(_fragment2);  \n            if (_fragment2 == null)   \n                _fragment2 = new Fragment2();  \n                  \n            ReplaceFragment(_fragment2, \"Fragment2\");  \n            return true;  \n        case Resource.Id.action_fragment3:  \n            \u002F\u002FShowFragment(_fragment3);  \n              \n            if (_fragment3 == null)                      \n                _fragment3 = new Fragment3();  \n  \n            ReplaceFragment(_fragment3, \"Fragment3\");  \n            return true;  \n        case Resource.Id.action_help:  \n            if (_drawerLayout.IsDrawerOpen(_rightDrawer))  \n            {  \n                \u002F\u002FRight Drawer is already open, close it  \n                _drawerLayout.CloseDrawer(_rightDrawer);  \n            }  \n            else  \n            {  \n                \u002F\u002FRight Drawer is closed, open it and just in case close left drawer  \n                _drawerLayout.OpenDrawer(_rightDrawer);  \n                _drawerLayout.CloseDrawer(_leftDrawer);  \n            }  \n            return true;  \n        default:  \n            return base.OnOptionsItemSelected(item);  \n    }  \n}\n",[58,437,438,443,448,453,458,463,468,473,478,483,488,492,497,505,510,514,519,524,528,533,538,543,549,554,560,566,572,578,583,589,594,600,606,612,618,624,629,635,640,646,652,658,664,670,676,682,687,693,699,705,710,715,721,727,733],{"__ignoreMap":56},[61,439,440],{"class":63,"line":64},[61,441,442],{},"public override bool OnOptionsItemSelected(IMenuItem item)  \n",[61,444,445],{"class":63,"line":70},[61,446,447],{},"{      \n",[61,449,450],{"class":63,"line":76},[61,451,452],{},"    switch (item.ItemId)  \n",[61,454,455],{"class":63,"line":82},[61,456,457],{},"    {                  \n",[61,459,460],{"class":63,"line":88},[61,461,462],{},"        case Android.Resource.Id.Home:  \n",[61,464,465],{"class":63,"line":94},[61,466,467],{},"            \u002F\u002FThe hamburger icon was clicked which means the drawer toggle will handle the event  \n",[61,469,470],{"class":63,"line":100},[61,471,472],{},"            \u002F\u002Fall we need to do is ensure the right drawer is closed so the don't overlap  \n",[61,474,475],{"class":63,"line":106},[61,476,477],{},"            _drawerLayout.CloseDrawer(_rightDrawer);  \n",[61,479,480],{"class":63,"line":112},[61,481,482],{},"            _drawerToggle.OnOptionsItemSelected(item);  \n",[61,484,485],{"class":63,"line":118},[61,486,487],{},"            return true;  \n",[61,489,490],{"class":63,"line":124},[61,491,290],{},[61,493,494],{"class":63,"line":130},[61,495,496],{},"        \u002F\u002Fcase Resource.Id.action_refresh:  \n",[61,498,499,502],{"class":63,"line":136},[61,500,501],{},"        \u002F\u002F",[61,503,504],{},"    \u002F\u002FRefresh  \n",[61,506,507],{"class":63,"line":142},[61,508,509],{},"        \u002F\u002F    return true;  \n",[61,511,512],{"class":63,"line":148},[61,513,290],{},[61,515,516],{"class":63,"line":154},[61,517,518],{},"        case Resource.Id.action_fragment1:  \n",[61,520,521],{"class":63,"line":161},[61,522,523],{},"            \u002F\u002FShowFragment(_fragment1);  \n",[61,525,526],{"class":63,"line":167},[61,527,290],{},[61,529,530],{"class":63,"line":356},[61,531,532],{},"            if (_fragment1 == null)                      \n",[61,534,535],{"class":63,"line":362},[61,536,537],{},"                _fragment1 = new Fragment1();            \n",[61,539,540],{"class":63,"line":368},[61,541,542],{},"                  \n",[61,544,546],{"class":63,"line":545},22,[61,547,548],{},"                ReplaceFragment(_fragment1, \"Fragment1\");  \n",[61,550,552],{"class":63,"line":551},23,[61,553,487],{},[61,555,557],{"class":63,"line":556},24,[61,558,559],{},"        case Resource.Id.action_fragment2:  \n",[61,561,563],{"class":63,"line":562},25,[61,564,565],{},"            \u002F\u002FShowFragment(_fragment2);  \n",[61,567,569],{"class":63,"line":568},26,[61,570,571],{},"            if (_fragment2 == null)   \n",[61,573,575],{"class":63,"line":574},27,[61,576,577],{},"                _fragment2 = new Fragment2();  \n",[61,579,581],{"class":63,"line":580},28,[61,582,542],{},[61,584,586],{"class":63,"line":585},29,[61,587,588],{},"            ReplaceFragment(_fragment2, \"Fragment2\");  \n",[61,590,592],{"class":63,"line":591},30,[61,593,487],{},[61,595,597],{"class":63,"line":596},31,[61,598,599],{},"        case Resource.Id.action_fragment3:  \n",[61,601,603],{"class":63,"line":602},32,[61,604,605],{},"            \u002F\u002FShowFragment(_fragment3);  \n",[61,607,609],{"class":63,"line":608},33,[61,610,611],{},"              \n",[61,613,615],{"class":63,"line":614},34,[61,616,617],{},"            if (_fragment3 == null)                      \n",[61,619,621],{"class":63,"line":620},35,[61,622,623],{},"                _fragment3 = new Fragment3();  \n",[61,625,627],{"class":63,"line":626},36,[61,628,290],{},[61,630,632],{"class":63,"line":631},37,[61,633,634],{},"            ReplaceFragment(_fragment3, \"Fragment3\");  \n",[61,636,638],{"class":63,"line":637},38,[61,639,487],{},[61,641,643],{"class":63,"line":642},39,[61,644,645],{},"        case Resource.Id.action_help:  \n",[61,647,649],{"class":63,"line":648},40,[61,650,651],{},"            if (_drawerLayout.IsDrawerOpen(_rightDrawer))  \n",[61,653,655],{"class":63,"line":654},41,[61,656,657],{},"            {  \n",[61,659,661],{"class":63,"line":660},42,[61,662,663],{},"                \u002F\u002FRight Drawer is already open, close it  \n",[61,665,667],{"class":63,"line":666},43,[61,668,669],{},"                _drawerLayout.CloseDrawer(_rightDrawer);  \n",[61,671,673],{"class":63,"line":672},44,[61,674,675],{},"            }  \n",[61,677,679],{"class":63,"line":678},45,[61,680,681],{},"            else  \n",[61,683,685],{"class":63,"line":684},46,[61,686,657],{},[61,688,690],{"class":63,"line":689},47,[61,691,692],{},"                \u002F\u002FRight Drawer is closed, open it and just in case close left drawer  \n",[61,694,696],{"class":63,"line":695},48,[61,697,698],{},"                _drawerLayout.OpenDrawer(_rightDrawer);  \n",[61,700,702],{"class":63,"line":701},49,[61,703,704],{},"                _drawerLayout.CloseDrawer(_leftDrawer);  \n",[61,706,708],{"class":63,"line":707},50,[61,709,675],{},[61,711,713],{"class":63,"line":712},51,[61,714,487],{},[61,716,718],{"class":63,"line":717},52,[61,719,720],{},"        default:  \n",[61,722,724],{"class":63,"line":723},53,[61,725,726],{},"            return base.OnOptionsItemSelected(item);  \n",[61,728,730],{"class":63,"line":729},54,[61,731,732],{},"    }  \n",[61,734,736],{"class":63,"line":735},55,[61,737,258],{},[12,739,740,741,743,744,746,747,750,754,756],{},"So finally, why are we using the transaction manager to replace fragments instead of showing and hiding them?  If we load up all fragments upon start up and show\u002Fhide they all are residing in memory which can be problematic if the fragments are large or you have many of them in your application.  Using the replace approach optimizes memory to only work with active fragments.  While a fragment is not in the current layout it is ‘paused’ and the memory footprint is much less.",[16,742],{},"\n ",[16,745],{},"\nReference: ",[25,748],{"href":749,"title":749},"http:\u002F\u002Fdeveloper.android.com\u002Fguide\u002Fcomponents\u002Ffragments.html",[25,751,749],{"href":749,"rel":752},[753],"nofollow",[16,755],{},[25,757,759],{"href":758},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-android-fragments-and-orientat_957a-image_2.png",[29,760],{"style":761,"src":762,"border":33,"alt":34,"title":34,"width":763,"height":48},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;","\u002Farticles\u002Fimages\u002Fwindows-live-writer-xamarin-android-fragments-and-orientat_957a-image_thumb.png",228,[172,765,174],{},{"title":56,"searchDepth":70,"depth":70,"links":767},[],"2016-02-14T04:36:35.5200000-05:00",{},"\u002Farticles\u002Fxamarin-android-fragments-and-orientations-rotation",{"title":203,"description":208},"articles\u002Fxamarin-android-fragments-and-orientations-rotation",[774],"xamarin","ptH_PqAAUCLJDvJogWefd7tmS1dafuuixCi8v4M0HA8",{"id":777,"title":778,"author":7,"body":779,"createdAt":1062,"description":1063,"extension":179,"img":1064,"meta":1065,"navigation":157,"path":1066,"seo":1067,"stem":1068,"tags":1069,"updatedAt":1062,"__hash__":1071},"articles\u002Farticles\u002Fsql-server-triggers-to-mirror-a-table.md","SQL Server Triggers To Mirror a Table",{"type":9,"value":780,"toc":1060},[781,787,847,850,1046,1049,1058],[12,782,783,784,786],{},"I had a need to mirror any changes to one Sql Server table to another Sql Server table of a different name. Both tables had similar columns and types. In this sample my table is called Dave_Test and my mirror table was Dave_Test_Audit.",[16,785],{},"\nI will provide the create table structures in the event you want to replicate my code.",[51,788,790],{"className":53,"code":789,"language":55,"meta":56,"style":56},"CREATE TABLE [Dave_Test]( \n    [Emp_ID] [int] IDENTITY(1,1) NOT NULL, \n    [Emp_name] [varchar](100) NULL, \n    [Emp_Sal] [decimal](10, 2) NULL ) ON [PRIMARY]  \n   \nCREATE TABLE [Dave_Test_Audit](\n    [Emp_ID] [int] NULL,\n    [Emp_name] [varchar](100) NULL,\n    [Emp_Sal] [decimal](18, 0) NULL\n) ON [PRIMARY]  \nGO  \n",[58,791,792,797,802,807,812,817,822,827,832,837,842],{"__ignoreMap":56},[61,793,794],{"class":63,"line":64},[61,795,796],{},"CREATE TABLE [Dave_Test]( \n",[61,798,799],{"class":63,"line":70},[61,800,801],{},"    [Emp_ID] [int] IDENTITY(1,1) NOT NULL, \n",[61,803,804],{"class":63,"line":76},[61,805,806],{},"    [Emp_name] [varchar](100) NULL, \n",[61,808,809],{"class":63,"line":82},[61,810,811],{},"    [Emp_Sal] [decimal](10, 2) NULL ) ON [PRIMARY]  \n",[61,813,814],{"class":63,"line":88},[61,815,816],{},"   \n",[61,818,819],{"class":63,"line":94},[61,820,821],{},"CREATE TABLE [Dave_Test_Audit](\n",[61,823,824],{"class":63,"line":100},[61,825,826],{},"    [Emp_ID] [int] NULL,\n",[61,828,829],{"class":63,"line":106},[61,830,831],{},"    [Emp_name] [varchar](100) NULL,\n",[61,833,834],{"class":63,"line":112},[61,835,836],{},"    [Emp_Sal] [decimal](18, 0) NULL\n",[61,838,839],{"class":63,"line":118},[61,840,841],{},") ON [PRIMARY]  \n",[61,843,844],{"class":63,"line":124},[61,845,846],{},"GO\n",[12,848,849],{},"Here are my insert, update and delete triggers.",[51,851,853],{"className":53,"code":852,"language":55,"meta":56,"style":56},"Create TRIGGER [Dave_Test_Trigger_Delete]   \n   ON  [Dave_Test]   \n   AFTER DELETE  \nAS  \nBEGIN  \n     SET NOCOUNT ON;  \n     DELETE FROM Dave_Test_Audit   \n            WHERE emp_id IN (SELECT emp_id FROM deleted)  \nEND  \n  \nCreate TRIGGER [Dave_Test_Trigger_Insert]   \n   ON  [Dave_Test]   \n   AFTER INSERT  \nAS  \nBEGIN     SET NOCOUNT ON;  \n        INSERT INTO Dave_Test_Audit   \n         SELECT * FROM inserted END  \nEND  \n  \nCREATE TRIGGER [[Dave_Test_Trigger_Update]   \n   ON  [Dave_Test]   \n   AFTER UPDATE  \nAS  \nBEGIN  \n        SET NOCOUNT ON;  \n        IF EXISTS(SELECT * FROM Dave_Test_Audit a JOIN inserted AS i ON a.emp_id=i.emp_id)          \n        BEGIN  \n              UPDATE  Dave_Test_Audit   \n                SET emp_id = i.emp_id,  \n                emp_name = i.emp_name,  \n                emp_sal =  i.emp_sal  \n                FROM inserted i WHERE Dave_Test_Audit.emp_id=i.emp_id           \n              \n        END  \n        ELSE  \n             BEGIN  \n             INSERT INTO Dave_Test_Audit   \n                SELECT * FROM inserted   \n        END        \nEND\n",[58,854,855,860,865,870,875,880,885,890,895,900,904,909,913,918,922,927,932,937,941,945,950,954,959,963,967,972,977,982,987,992,997,1002,1007,1011,1016,1021,1026,1031,1036,1041],{"__ignoreMap":56},[61,856,857],{"class":63,"line":64},[61,858,859],{},"Create TRIGGER [Dave_Test_Trigger_Delete]   \n",[61,861,862],{"class":63,"line":70},[61,863,864],{},"   ON  [Dave_Test]   \n",[61,866,867],{"class":63,"line":76},[61,868,869],{},"   AFTER DELETE  \n",[61,871,872],{"class":63,"line":82},[61,873,874],{},"AS  \n",[61,876,877],{"class":63,"line":88},[61,878,879],{},"BEGIN  \n",[61,881,882],{"class":63,"line":94},[61,883,884],{},"     SET NOCOUNT ON;  \n",[61,886,887],{"class":63,"line":100},[61,888,889],{},"     DELETE FROM Dave_Test_Audit   \n",[61,891,892],{"class":63,"line":106},[61,893,894],{},"            WHERE emp_id IN (SELECT emp_id FROM deleted)  \n",[61,896,897],{"class":63,"line":112},[61,898,899],{},"END  \n",[61,901,902],{"class":63,"line":118},[61,903,290],{},[61,905,906],{"class":63,"line":124},[61,907,908],{},"Create TRIGGER [Dave_Test_Trigger_Insert]   \n",[61,910,911],{"class":63,"line":130},[61,912,864],{},[61,914,915],{"class":63,"line":136},[61,916,917],{},"   AFTER INSERT  \n",[61,919,920],{"class":63,"line":142},[61,921,874],{},[61,923,924],{"class":63,"line":148},[61,925,926],{},"BEGIN     SET NOCOUNT ON;  \n",[61,928,929],{"class":63,"line":154},[61,930,931],{},"        INSERT INTO Dave_Test_Audit   \n",[61,933,934],{"class":63,"line":161},[61,935,936],{},"         SELECT * FROM inserted END  \n",[61,938,939],{"class":63,"line":167},[61,940,899],{},[61,942,943],{"class":63,"line":356},[61,944,290],{},[61,946,947],{"class":63,"line":362},[61,948,949],{},"CREATE TRIGGER [[Dave_Test_Trigger_Update]   \n",[61,951,952],{"class":63,"line":368},[61,953,864],{},[61,955,956],{"class":63,"line":545},[61,957,958],{},"   AFTER UPDATE  \n",[61,960,961],{"class":63,"line":551},[61,962,874],{},[61,964,965],{"class":63,"line":556},[61,966,879],{},[61,968,969],{"class":63,"line":562},[61,970,971],{},"        SET NOCOUNT ON;  \n",[61,973,974],{"class":63,"line":568},[61,975,976],{},"        IF EXISTS(SELECT * FROM Dave_Test_Audit a JOIN inserted AS i ON a.emp_id=i.emp_id)          \n",[61,978,979],{"class":63,"line":574},[61,980,981],{},"        BEGIN  \n",[61,983,984],{"class":63,"line":580},[61,985,986],{},"              UPDATE  Dave_Test_Audit   \n",[61,988,989],{"class":63,"line":585},[61,990,991],{},"                SET emp_id = i.emp_id,  \n",[61,993,994],{"class":63,"line":591},[61,995,996],{},"                emp_name = i.emp_name,  \n",[61,998,999],{"class":63,"line":596},[61,1000,1001],{},"                emp_sal =  i.emp_sal  \n",[61,1003,1004],{"class":63,"line":602},[61,1005,1006],{},"                FROM inserted i WHERE Dave_Test_Audit.emp_id=i.emp_id           \n",[61,1008,1009],{"class":63,"line":608},[61,1010,611],{},[61,1012,1013],{"class":63,"line":614},[61,1014,1015],{},"        END  \n",[61,1017,1018],{"class":63,"line":620},[61,1019,1020],{},"        ELSE  \n",[61,1022,1023],{"class":63,"line":626},[61,1024,1025],{},"             BEGIN  \n",[61,1027,1028],{"class":63,"line":631},[61,1029,1030],{},"             INSERT INTO Dave_Test_Audit   \n",[61,1032,1033],{"class":63,"line":637},[61,1034,1035],{},"                SELECT * FROM inserted   \n",[61,1037,1038],{"class":63,"line":642},[61,1039,1040],{},"        END        \n",[61,1042,1043],{"class":63,"line":648},[61,1044,1045],{},"END\n",[12,1047,1048],{},"So why does my Update trigger deal with inserts?  The master table (Dave_Test) already had rows existing before the triggers were created.  With the update trigger managing inserting and updating records if the record is updated and does yet belong in the master audit table then the recently updated row will be inserted into the audit table for us.",[12,1050,1051,1052,1057],{},"For those old enough – this is ",[25,1053,1056],{"href":1054,"target":1055},"http:\u002F\u002Fwww.happytrails.org\u002Ftrigger.html","_blank","Trigger"," (the smartest horse in the movies)",[172,1059,174],{},{"title":56,"searchDepth":70,"depth":70,"links":1061},[],"2016-02-13T07:02:53.5100000-05:00","I had a need to mirror any changes to one Sql Server table to another Sql Server table of a different name.  Read on.","\u002Farticles\u002Fimages\u002FXp0SJTsB7n.png",{},"\u002Farticles\u002Fsql-server-triggers-to-mirror-a-table",{"title":778,"description":1063},"articles\u002Fsql-server-triggers-to-mirror-a-table",[55,1070],"sqlserver","oG-qazOpjUVf0yb-VL3IN5WX57TFCezPsA53rRrA00k",1781574767077]