{"id":265318,"date":"2015-09-10T01:18:02","date_gmt":"2015-09-09T21:18:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=265318"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=265318","title":{"rendered":"\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0441\u0445\u0435\u043c \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445"},"content":{"rendered":"<p>       \u042f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435 \u0441\u0445\u0435\u043c \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 MS SQL Server.<\/p>\n<blockquote><p>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u2014 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f, \u0438\u043c\u0435\u044e\u0449\u0435\u0435 \u0446\u0435\u043b\u044c\u044e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u043d\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f.<\/p><\/blockquote>\n<p><i>\u2014 Martin Fowler<\/i><\/p>\n<p>  \u041e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435 \u043a\u043e\u0434\u0430 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0435\u043c\u0430\u043b\u043e \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b, \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043a\u043e\u0434\u0430.<br \/>  \u0410 \u0432\u043e\u0442 \u043f\u0440\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0441\u0445\u0435\u043c \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u042f \u0440\u0435\u0448\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b \u0438 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h2>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c \u0447\u0442\u043e \u043d\u0430\u0441\u0442\u0430\u043b\u0430 \u043f\u043e\u0440\u0430 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433?<\/h2>\n<p>  <\/p>\n<blockquote><p>\u0414\u0435\u043b\u0430\u044f \u0447\u0442\u043e-\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0435. \u0414\u0435\u043b\u0430\u044f \u0447\u0442\u043e-\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0437, \u0432\u044b \u043c\u043e\u0440\u0449\u0438\u0442\u0435\u0441\u044c \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u044f, \u043d\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435. \u0414\u0435\u043b\u0430\u044f \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u0432 \u0442\u0440\u0435\u0442\u0438\u0439 \u0440\u0430\u0437, \u0432\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0435 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433.  <\/p><\/blockquote>\n<p><i>\u2014 Don Roberts<\/i><\/p>\n<p>  <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A4%D0%B0%D1%83%D0%BB%D0%B5%D1%80,_%D0%9C%D0%B0%D1%80%D1%82%D0%B8%D0%BD\">\u041c\u0430\u0440\u0442\u0438\u043d \u0424\u0430\u0443\u043b\u0435\u0440<\/a> \u0432\u0432\u0435\u043b \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u00ab\u041a\u043e\u0434 \u0441 \u0434\u0443\u0448\u043a\u043e\u043c\u00bb, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0432 \u0442\u0430\u043a \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u043d\u0443\u0442\u044c \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0443. <br \/>  \u0421 \u0434\u0443\u0448\u043a\u043e\u043c \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0434 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c:  <\/p>\n<ul>\n<li>\u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/li>\n<li>\u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b<\/li>\n<li>\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/li>\n<li>\u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <i>switch<\/i><\/li>\n<\/ul>\n<p>  \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u044d\u0442\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0431\u0449\u0438\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0441\u0445\u0435\u043c\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430. \u041a \u044d\u0442\u0438\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435.  <\/p>\n<ul>\n<li><i>\u041c\u043d\u043e\u0433\u043e\u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b (\u0438\u043b\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043d\u0435 \u043f\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e).<\/i> \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u0437\u0430\u043a\u0430\u0437\u0430\u043c. \u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435 <i>InvoiceId<\/i> \u0442\u0438\u043f\u0430 <i>int<\/i>. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0447\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0434\u0430\u0436 \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u043b\u0435 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043d\u043e\u0432\u043e\u0433\u043e \u0433\u043e\u0434\u0430 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430\u043c \u0441\u0442\u0430\u043b\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0443 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u043e\u0446\u0435\u043d\u043a\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 (\u043e\u0442 1 \u0434\u043e 10 \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043e\u0431\u0437\u0432\u043e\u043d\u0430). \u0422\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0435\u0442 \u0438 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0432\u0431\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u043e\u043b\u0435 InvoiceId (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e IT-\u0448\u043d\u0438\u043a\u0438 \u0441\u043a\u0430\u0437\u0430\u043b\u0438 \u0438\u043c \u0447\u0442\u043e \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0443\u0439\u0434\u0435\u0442 \u0446\u0435\u043b\u044b\u0439 \u043c\u0435\u0441\u044f\u0446). \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0435 InvoiceId \u0441\u0442\u0430\u043d\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.  <\/li>\n<li><i>\u041c\u043d\u043e\u0433\u043e\u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/i> \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 Customer \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438 \u044e\u0440\u0438\u0434\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043b\u0438\u0446\u0430\u0445. \u0412 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u043e\u043b\u0431\u044b \u0441 <i>NULL<\/i> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.<\/li>\n<li><i>\u0418\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/i> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u043b\u044f <i>\u0410\u0434\u0440\u0435\u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/i> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0441\u043b\u0443\u0447\u0430\u044e \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430. <\/li>\n<li><i>\u0422\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432.<\/i> \u041d\u0430\u043b\u0438\u0447\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0447\u0442\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u00ab\u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b\u00bb.<\/li>\n<li><i>\u041c\u043d\u043e\u0433\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b.<\/i> \u041c\u043d\u043e\u0433\u043e\u0437\u043d\u0430\u0447\u043d\u044b\u043c\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0437\u0430\u043a\u0430\u0437\u043e\u0432 \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0435 <i>OrderNumber<\/i> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0438\u0434\u0430 XXX20150908000125. \u0413\u0434\u0435 XXX \u2014 \u043a\u043e\u0434 \u0442\u043e\u0432\u0430\u0440\u0430, 20150908 \u2014 \u0434\u0430\u0442\u0430 \u0437\u0430\u043a\u0430\u0437\u0430, 000125 \u2014 \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0437\u0430\u043a\u0430\u0437\u0430. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0447\u0430\u0441\u0442\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u043d\u0430 \u0447\u0430\u0441\u0442\u0438, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0449\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u043e\u043b\u044f \u0432 \u0432\u0438\u0434\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/li>\n<\/ul>\n<h2>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430<\/h2>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0437\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437. \u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u0442\u0435\u043c \u043f\u0440\u043e\u0449\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0431\u043e\u044f. <\/li>\n<li>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438. \u041f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0439\u0442\u0435 \u0442\u0435\u0441\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u043b\u043e\u0441\u044c. <\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b. \u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u043e\u043c \u043d\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0438\u0432\u0435, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043d\u0438\u0447\u0442\u043e\u0436\u043d\u043e \u043c\u0430\u043b\u043e. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0434\u043b\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u043f\u043b\u043e\u0449\u0430\u0434\u043a\u0438. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0435 \u043f\u043e\u043b\u043d\u043e\u0435 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0418 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<\/ol>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/h2>\n<p>  \u042f \u043f\u043e\u043a\u0430\u0436\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 Northwind (<a href=\"https:\/\/northwinddatabase.codeplex.com\/downloads\/get\/269239\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435<\/a>).<br \/>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SQL Server Management Studio (SSMS) \u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u043c <a href=\"http:\/\/sqlrefactorstudio.com\/\">SQL Refactor Studio<\/a>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 SSMS \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430.<\/p>\n<h3>\u0418\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430<\/h3>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/eb2\/42c\/878\/eb242c8788e240a8a51dfe3d8bc78626.png\"\/><\/p>\n<h3>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u0435\u0441\u0442, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e \u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<br \/>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 <i>dbo.RunTests<\/i>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0432 \u0431\u0430\u0437\u0435 (\u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043d\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u043d\u043e\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u0442\u0435\u0441\u0442\u0430\u043c\u0438).<br \/>  \u0415\u0441\u043b\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043d\u0435 \u0431\u044b\u043b\u043e \u043e\u0448\u0438\u0431\u043e\u043a, \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0432\u044b\u0434\u0430\u0435\u0442 OK, \u0438\u043d\u0430\u0447\u0435 Failed.  <\/p>\n<pre><code class=\"sql\">CREATE PROCEDURE dbo.RunTests AS DECLARE \t@Script nvarchar(max) = '', \t@Failed bit = 0  DECLARE crs CURSOR FOR SELECT 'IF OBJECT_ID(''tempdb..#tmp'') IS NOT NULL DROP TABLE #tmp  \t\tSELECT * INTO #tmp FROM [' + object_schema_name(o.object_id) + '].[' + o.name + ']'  FROM sys.objects o WHERE o.type = 'V'  OPEN crs FETCH NEXT FROM crs INTO @Script WHILE @@fetch_status = 0 BEGIN  \tBEGIN TRY \t\tEXEC sp_executesql @Script \tEND TRY \tBEGIN CATCH \t\tSET @Failed = 1  \t\tSELECT 'Failed' AS Status, ERROR_MESSAGE() AS Details, @Script AS [Script] \tEND CATCH \t\t \tFETCH NEXT FROM crs INTO @Script END CLOSE crs DEALLOCATE crs  IF @Failed = 0 \tSELECT 'OK' AS [Status]  RETURN 0  \/* EXEC dbo.RunTests *\/ GO <\/code><\/pre>\n<h3>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u00ab\u041f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u00bb<\/h3>\n<p>  \u041d\u0435 \u0437\u043d\u0430\u044e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043a\u0430\u043a \u0412\u044b, \u043d\u043e \u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u0430\u044e \u0435\u0439 \u0438\u043c\u044f \u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0435 (dbo.Entry \u0430 \u043d\u0435 dbo.Entrie<u>s<\/u>).<br \/>  \u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <i>dbo.Customer<u>s<\/u><\/i> \u0432 <i>dbo.Customer<\/i>. \u0422\u0443\u0442 \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 (\u0438 \u043e\u0447\u0435\u043d\u044c \u0440\u0443\u0442\u0438\u043d\u043d\u044b\u0439) \u043f\u0440\u043e\u0446\u0435\u0441\u0441. \u041d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u043b\u0441\u044f \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u0435\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0438 \u0432\u043d\u0435\u0441\u0442\u0438 \u0432 \u043d\u0435\u0433\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435. \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c <i>View Dependencies<\/i> \u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u0435\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0438 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 <i>dbo.Customers<\/i>.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/de1\/7da\/910\/de17da9100f9485680639fc70ef4c810.png\"\/><br \/>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0432\u043d\u0435\u0441\u0442\u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u043e\u0434\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u2014 \u043f\u043b\u0435\u0432\u043e\u0435 \u0434\u0435\u043b\u043e. <br \/>  \u041d\u0443 \u0447\u0442\u043e \u0436\u0435, \u0432 \u0431\u043e\u0439! \u041f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442 (\u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043b\u043e\u043c\u0430\u0442\u044c\u0441\u044f \u0432\u044c\u044e\u0445\u0430 <i>dbo.Customer and Suppliers by City<\/i>).<br \/>  \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0439 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u0435\u0441\u0442 \u043c\u043d\u0435 \u0432\u044b\u0434\u0430\u043b \u0446\u0435\u043b\u044b\u0445 \u043f\u044f\u0442\u044c.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d2e\/6d7\/231\/d2e6d7231889466199f91d942a55d22e.PNG\"\/><\/p>\n<p>  \u0422\u043e\u0433\u0434\u0430 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 <i><a href=\"http:\/\/sqlrefactorstudio.com\/Features\/Details\/ViewDependencies\">View Dependencies<\/a><\/i> \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 \u043f\u0430\u043a\u0435\u0442\u0430 SQL Refactor Studio. \u041e\u043d \u0443\u0436\u0435 \u043d\u0430\u0441\u0447\u0438\u0442\u0430\u043b \u043f\u044f\u0442\u044c \u0432\u044c\u044e\u0448\u0435\u043a (\u0442\u0435\u0441\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0447\u0442\u043e \u0441\u043b\u043e\u043c\u0430\u043b\u043e\u0441\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u044f\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439) \u0438 \u043d\u0430\u0448\u0435\u043b \u043e\u0434\u043d\u0443 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 (\u043d\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u0430 \u0442\u0435\u0441\u0442\u0430\u043c\u0438).<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/3f6\/748\/02d\/3f674802d22d40d1b391348e04a6c314.png\"\/><br \/>  \u0428\u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u2014 \u044d\u0442\u043e \u0443\u0436\u0435 \u043f\u043e\u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0435\u0435. \u0410 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u0447\u0442\u043e \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 50+ \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445. \u0412\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443? \ud83d\ude42 \u0420\u0443\u0447\u043a\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u0436\u0435 \u0442\u044f\u0436\u0435\u043b\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0435\u043c \u043a \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438.<br \/>  \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <i>Rename<\/i> \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0432 \u043f\u0430\u043a\u0435\u0442 SQL Refactor Studio. \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 Object Explorer (\u0434\u0430\u043b\u0435\u0435 OE), \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0443\u043d\u043a\u0442 <i>SQL Refactor Studio -&gt; Rename<\/i>. \u0412\u0432\u043e\u0434\u0438\u043c \u043d\u043e\u0432\u043e\u0435 \u0438\u043c\u044f (Customer) \u0438 \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443 <i>Genarate rename script<\/i>. \u0422\u0443\u0442 \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0441\u043d\u044f\u0442\u044c \u0433\u0430\u043b\u043e\u0447\u043a\u0438 \u043d\u0430\u043f\u0440\u043e\u0442\u0438\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/1de\/467\/205\/1de467205e794b70872fa2d9dc56b672.png\"\/><br \/>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043e\u0442\u043a\u0440\u044b\u043b\u0430\u0441\u044c \u043d\u043e\u0432\u0430\u044f \u0432\u043a\u043b\u0430\u0434\u043a\u0430 \u0441 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">use northwind go set transaction isolation level serializable set xact_abort on go  if object_id('tempdb..#err') is not null \tdrop table #err go create table #err(flag bit) go begin transaction go  exec sp_rename 'dbo.Customers', 'Customer', 'OBJECT'  go if (@@error &lt;&gt; 0) and (@@trancount &gt; 0) \trollback transaction go if (@@trancount = 0) begin \tinsert into #err(flag) select cast(1 as bit) \tbegin transaction end go ALTER view dbo.[Orders Qry] AS SELECT Orders.OrderID, Orders.CustomerID, Orders.EmployeeID, Orders.OrderDate, Orders.RequiredDate, \tOrders.ShippedDate, Orders.ShipVia, Orders.Freight, Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, \tOrders.ShipRegion, Orders.ShipPostalCode, Orders.ShipCountry, \tCustomer.CompanyName, Customer.Address, Customer.City, Customer.Region, Customer.PostalCode, Customer.Country FROM Customer INNER JOIN Orders ON Customer.CustomerID = Orders.CustomerID go raiserror('update view &lt;dbo.Orders Qry&gt;...', 0, 1) with nowait  go if (@@error &lt;&gt; 0) and (@@trancount &gt; 0) \trollback transaction go if (@@trancount = 0) begin \tinsert into #err(flag) select cast(1 as bit) \tbegin transaction end go ALTER view dbo.[Quarterly Orders] AS SELECT DISTINCT Customer.CustomerID, Customer.CompanyName, Customer.City, Customer.Country FROM Customer RIGHT JOIN Orders ON Customer.CustomerID = Orders.CustomerID WHERE Orders.OrderDate BETWEEN '19970101' And '19971231' go raiserror('update view &lt;dbo.Quarterly Orders&gt;...', 0, 1) with nowait  go if (@@error &lt;&gt; 0) and (@@trancount &gt; 0) \trollback transaction go if (@@trancount = 0) begin \tinsert into #err(flag) select cast(1 as bit) \tbegin transaction end go ALTER view dbo.Invoices AS SELECT Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, Orders.ShipRegion, Orders.ShipPostalCode, \tOrders.ShipCountry, Orders.CustomerID, Customer.CompanyName AS CustomerName, Customer.Address, Customer.City, \tCustomer.Region, Customer.PostalCode, Customer.Country, \t(FirstName + ' ' + LastName) AS Salesperson, \tOrders.OrderID, Orders.OrderDate, Orders.RequiredDate, Orders.ShippedDate, Shippers.CompanyName As ShipperName, \t&quot;Order Details&quot;.ProductID, Products.ProductName, &quot;Order Details&quot;.UnitPrice, &quot;Order Details&quot;.Quantity, \t&quot;Order Details&quot;.Discount, \t(CONVERT(money,(&quot;Order Details&quot;.UnitPrice*Quantity*(1-Discount)\/100))*100) AS ExtendedPrice, Orders.Freight FROM \tShippers INNER JOIN \t\t(Products INNER JOIN \t\t\t( \t\t\t\t(Employees INNER JOIN \t\t\t\t\t(Customer INNER JOIN Orders ON Customer.CustomerID = Orders.CustomerID) \t\t\t\tON Employees.EmployeeID = Orders.EmployeeID) \t\t\tINNER JOIN &quot;Order Details&quot; ON Orders.OrderID = &quot;Order Details&quot;.OrderID) \t\tON Products.ProductID = &quot;Order Details&quot;.ProductID) \tON Shippers.ShipperID = Orders.ShipVia go raiserror('update view &lt;dbo.Invoices&gt;...', 0, 1) with nowait  go if (@@error &lt;&gt; 0) and (@@trancount &gt; 0) \trollback transaction go if (@@trancount = 0) begin \tinsert into #err(flag) select cast(1 as bit) \tbegin transaction end go ALTER PROCEDURE dbo.CustOrderHist @CustomerID nchar(5) AS SELECT ProductName, Total=SUM(Quantity) FROM Products P, [Order Details] OD, Orders O, Customer C WHERE C.CustomerID = @CustomerID AND C.CustomerID = O.CustomerID AND O.OrderID = OD.OrderID AND OD.ProductID = P.ProductID GROUP BY ProductName go raiserror('update storedprocedure &lt;dbo.CustOrderHist&gt;...', 0, 1) with nowait  go if (@@error &lt;&gt; 0) and (@@trancount &gt; 0) \trollback transaction go if (@@trancount = 0) begin \tinsert into #err(flag) select cast(1 as bit) \tbegin transaction end go ALTER view dbo.[Customer and Suppliers by City] AS SELECT City, CompanyName, ContactName, 'Customers' AS Relationship FROM Customer UNION SELECT City, CompanyName, ContactName, 'Suppliers' FROM Suppliers --ORDER BY City, CompanyName go raiserror('update view &lt;dbo.Customer and Suppliers by City&gt;...', 0, 1) with nowait  go if (@@error &lt;&gt; 0) and (@@trancount &gt; 0) \trollback transaction go if (@@trancount = 0) begin \tinsert into #err(flag) select cast(1 as bit) \tbegin transaction end go ALTER view dbo.[Sales Totals by Amount] AS SELECT &quot;Order Subtotals&quot;.Subtotal AS SaleAmount, Orders.OrderID, Customer.CompanyName, Orders.ShippedDate FROM \tCustomer INNER JOIN \t\t(Orders INNER JOIN &quot;Order Subtotals&quot; ON Orders.OrderID = &quot;Order Subtotals&quot;.OrderID) \tON Customer.CustomerID = Orders.CustomerID WHERE (&quot;Order Subtotals&quot;.Subtotal &gt;2500) AND (Orders.ShippedDate BETWEEN '19970101' And '19971231') go raiserror('update view &lt;dbo.Sales Totals by Amount&gt;...', 0, 1) with nowait  go if (@@error &lt;&gt; 0) and (@@trancount &gt; 0) \trollback transaction go if (@@trancount = 0) begin \tinsert into #err(flag) select cast(1 as bit) \tbegin transaction end go if exists (select * from #err) begin \tprint 'the database &lt;northwind&gt; update failed' \trollback transaction end else begin \tprint 'the database &lt;northwind&gt; update succeeded' \tcommit transaction end  go      <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435.<br \/>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442.<br \/>  \u0412\u0443\u0430\u043b\u044f! \u041c\u044b \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.<br \/>  \u041f\u043e\u0441\u0442\u0443\u043f\u0438\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438, \u0438\u043c\u0435\u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 <i>s<\/i>. \u042d\u0442\u043e \u0432\u0435\u0434\u044c \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u0435\u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438?<\/p>\n<h3>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u00ab\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b\u00bb<\/h3>\n<p>  \u042d\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430.<br \/>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c\u0438:  <\/p>\n<ul>\n<li>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445;<\/li>\n<li>\u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u043e\u0439 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u043e\u0432\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442. \u0415\u0441\u043b\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u044d\u0442\u043e\u0439 \u043d\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u2014 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u0442\u043e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0434\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0445\u0435\u043c\u044b. <\/li>\n<\/ul>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u0440\u0430\u0437 \u043d\u0430 \u043d\u0430\u0448\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <i>dbo.Customer<\/i>. \u0412\u0430\u0441 \u043d\u0435 \u0441\u043c\u0443\u0449\u0430\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 City, Region \u0438 Country \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435? \u042d\u0442\u043e \u0432\u0435\u0434\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d99\/61e\/0f6\/d9961e0f679a4b25a7d92e95691bfcfe.PNG\"\/><\/p>\n<p>  \u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <i>dbo.Employees<\/i> \u0442\u0430 \u0436\u0435 \u0431\u0435\u0434\u0430. \u041d\u0430 \u0432\u0438\u0434 \u044f\u0432\u043d\u043e\u0435 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 3-\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0435\u043b\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<br \/>  1. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a dbo.City(CityId, CityName)<br \/>  2. \u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <i>dbo.Customer<\/i> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u043b\u0435 CityId.<br \/>  3. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447.<\/p>\n<p>  \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u0434\u043b\u044f \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <a href=\"http:\/\/sqlrefactorstudio.com\/Features\/Details\/AddLookupTable\">Add Lookup Table<\/a>. \u0412 OE \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043b\u0435 <i>City<\/i> \u0442\u0430\u0431\u043b\u0438\u0446\u044b <i>dbo.Customer<\/i> \u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u043c \u043c\u0435\u043d\u044e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0443\u043d\u043a\u0442 <i>SQL Refactor Studio -&gt; Add Lookup Table<\/i>. <br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c4e\/52e\/1ae\/c4e52e1aeefe4dfa9174e187075bed3f.png\"\/><br \/>  \u0412 \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0435\u043c\u0441\u044f \u043e\u043a\u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u043e\u043b\u044f. \u0416\u043c\u0435\u043c <i>Next<\/i>, \u043f\u043e\u0442\u043e\u043c <i>Finish<\/i> \u0438 \u0432 \u043d\u043e\u0432\u043e\u043c \u043e\u043a\u043d\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043a\u0440\u0438\u043f\u0442. <br \/>  \u0421\u043a\u0440\u0438\u043f\u0442 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 dbo.City, \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0435\u0435 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u0435 <i>CityId<\/i> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <i>dbo.Customer<\/i>, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">use northwind go -- Step 1. Create lookup table. CREATE TABLE dbo.City ( CityId INT NOT NULL identity(1, 1) ,CityName NVARCHAR(15) NULL ,CONSTRAINT PK_City PRIMARY KEY CLUSTERED (CityId) ,CONSTRAINT City_ixCityName UNIQUE (CityName) ) GO  -- Step 2. Fill lookup table. INSERT dbo.City (CityName) SELECT DISTINCT City FROM dbo.Customer GO  -- Step 3. Add column. ALTER TABLE dbo.Customer ADD CityId INT NULL GO  -- Step 4. Update table dbo.Customer. UPDATE s SET s.CityId = t.CityId FROM dbo.Customer s INNER JOIN dbo.City t ON s.City = t.CityName GO  -- Step 5. Create foreign key constraint. ALTER TABLE dbo.Customer ADD CONSTRAINT FK_Customer_City FOREIGN KEY (CityId) REFERENCES dbo.City (CityId) GO      <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u0442\u0435\u0441\u0442\u044b (\u0445\u043e\u0442\u044f \u0442\u0443\u0442 \u043c\u044b \u0432\u0440\u043e\u0434\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0441\u043b\u043e\u043c\u0430\u0442\u044c). <br \/>  \u0412\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e. \u0418\u0434\u0435\u043c \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  <\/p>\n<h3>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u00ab\u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439\u00bb<\/h3>\n<p>  \u0418\u0442\u0430\u043a, \u0441 \u043f\u043e\u043b\u0435\u043c <i>City<\/i> \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u043b\u044f\u043c\u0438 Region \u0438 Country. \u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <i>City<\/i>. \u0422\u0430\u043a \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043c \u0438\u0445 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <i>dbo.Customer<\/i> \u0432 <i>dbo.City<\/i>.<br \/>  \u041e\u043f\u044f\u0442\u044c \u0436\u0435, SQL Refactor Studio \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <a href=\"http:\/\/sqlrefactorstudio.com\/Features\/Details\/MoveColumns\">Move Columns<\/a>. \u0415\u044e \u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f!<br \/>  \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432 OE \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <i>dbo.Customer<\/i>, \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u043c \u043c\u0435\u043d\u044e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0443\u043d\u043a\u0442 <i>\u00abSQL Refactor Studio -&gt; Move columns\u00bb<\/i>. \u0412 \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0435\u043c\u0441\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u0435, \u0432 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0435, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <i>dbo.City<\/i>. \u041f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u043f\u043e\u043b\u044f <i>Region<\/i> \u0438 <i>Country<\/i> \u0432 <i>dbo.City<\/i>.<br \/>  \u0415\u0441\u043b\u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0435 \u043f\u043e\u043b\u044f, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u0438\u043d\u0434\u0435\u043a\u0441 \u2014 \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u044d\u0442\u043e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/f83\/75d\/6c8\/f8375d6c889b46d7b7c3bd76712c45fa.png\"\/><\/p>\n<p>  \u041d\u0430\u0436\u0438\u043c\u0430\u0435\u043c <i>Next<\/i>, \u043f\u043e\u0442\u043e\u043c <i>Finish<\/i>. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 \u043d\u043e\u0432\u043e\u043c \u043e\u043a\u043d\u0435.<br \/>  \u0421\u043a\u0440\u0438\u043f\u0442 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u044f <i>Region<\/i> \u0438 <i>Country<\/i> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <i>dbo.City<\/i> \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. <br \/>  \u0412 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0443\u0434\u0430\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u044f \u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043f\u043e\u043b\u044f, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">USE northwind GO  -- STEP 1. Add new column(s) -- IF NOT EXISTS ( SELECT * FROM syscolumns s WHERE s.NAME = 'Region' AND s.id = object_id(N'dbo.City') ) BEGIN ALTER TABLE dbo.City ADD Region NVARCHAR(15) NULL END GO  IF NOT EXISTS ( SELECT * FROM syscolumns s WHERE s.NAME = 'Country' AND s.id = object_id(N'dbo.City') ) BEGIN ALTER TABLE dbo.City ADD Country NVARCHAR(15) NULL END GO   GO  -- STEP 2. Copy data -- -- (You can modify this query if needed) SET IDENTITY_INSERT dbo.City ON  INSERT INTO dbo.City WITH (TABLOCKX) (CityId) SELECT CityId FROM dbo.Customer src WHERE NOT EXISTS ( SELECT * FROM dbo.City dest WHERE src.CityId = dest.CityId )  SET IDENTITY_INSERT dbo.City OFF  UPDATE dest WITH (TABLOCKX)  SET dest.Region = src.Region ,dest.Country = src.Country FROM dbo.City dest INNER JOIN dbo.Customer src ON (src.CityId = dest.CityId) GO  -- STEP 3. Check and modify this dependent objects -- \/* northwind.dbo.[Orders Qry] \/*View*\/ northwind.dbo.[Quarterly Orders] \/*View*\/ northwind.dbo.Invoices \/*View*\/ northwind.dbo.CustOrderHist \/*StoredProcedure*\/ northwind.dbo.[Customer and Suppliers by City] \/*View*\/ northwind.dbo.[Sales Totals by Amount] \/*View*\/  *\/ -- STEP 4. Drop column(s) -- -- (Uncomment or run separately this query) \/* alter table dbo.Customer drop column Region alter table dbo.Customer drop column Country *\/ GO      <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u0442\u0435\u0441\u0442\u044b.<br \/>  \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443.<\/p>\n<p>  <\/p>\n<h3>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u00ab\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u00bb<\/h3>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0438, \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0443\u0441\u043e\u0440\u0430 (\u043f\u043e\u043b\u044f <i>City, Region, Country<\/i> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <i>dbo.Customer<\/i>).<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0432\u043e\u0434\u0438\u0442\u044c \u0447\u0438\u0441\u0442\u043e\u0442\u0443! \u041d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u0443\u0434\u0430\u043b\u0438\u043c \u043f\u043e\u043b\u044f, \u0443 \u043d\u0430\u0441 \u043e\u043f\u044f\u0442\u044c \u0432\u0441\u0435 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f.<br \/>  \u041c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u043e\u043c <a href=\"http:\/\/databaserefactoring.com\/EncapsulateTableWithView.html\">Encapsulate Table With View<\/a>.<br \/>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <i>dbo.CustomerV<\/i> \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0432\u043e \u0432\u0441\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.  <\/p>\n<pre><code class=\"sql\">CREATE VIEW dbo.CustomerV AS SELECT   c.CustomerID,  c.CompanyName,  c.ContactName,  c.ContactTitle,  c.Address,  ct.CityName City,  ct.Region,  c.PostalCode,  ct.Country,  c.Phone,  c.Fax,  c.CityId FROM dbo.Customer AS c LEFT JOIN dbo.City AS ct \tON c.CityId = ct.CityId  <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 View Dependencies \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b <i>dbo.Customer<\/i>:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/1c2\/ce8\/d78\/1c2ce8d7880e4d28b78a14b459d86ff5.png\"\/><\/p>\n<p>  \u041f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. \u0415\u0441\u043b\u0438 \u0432 \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u0448\u0438 \u043f\u043e\u043b\u044f, \u0441\u043a\u0440\u0438\u043f\u0442\u0443\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 (\u043a\u043d\u043e\u043f\u043a\u0430 <i>Script object<\/i> \u043d\u0430 \u0442\u0443\u043b\u0431\u0430\u0440\u0435) \u0438 \u0432\u043d\u043e\u0441\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f.<br \/>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Encapsulate Table With View<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">ALTER view dbo.[Sales Totals by Amount] AS SELECT st.Subtotal AS SaleAmount, o.OrderID, c.CompanyName, o.ShippedDate FROM dbo.CustomerV c  JOIN ( \tdbo.Orders o \tJOIN &quot;Order Subtotals&quot; st  \t\tON o.OrderID = st.OrderID ) \tON c.CustomerID = o.CustomerID WHERE (st.Subtotal &gt;2500) AND (o.ShippedDate BETWEEN '19970101' And '19971231')  GO  ALTER view dbo.[Quarterly Orders]  AS SELECT DISTINCT c.CustomerID, c.CompanyName, c.City, c.Country FROM dbo.CustomerV c  RIGHT JOIN dbo.Orders o  \tON c.CustomerID = o.CustomerID WHERE \to.OrderDate BETWEEN '19970101' And '19971231'  GO  ALTER view dbo.[Orders Qry]  AS SELECT o.OrderID, o.CustomerID, o.EmployeeID, o.OrderDate, o.RequiredDate, \to.ShippedDate, o.ShipVia, o.Freight, o.ShipName, o.ShipAddress, o.ShipCity, \to.ShipRegion, o.ShipPostalCode, o.ShipCountry, \tc.CompanyName, c.Address, c.City, c.Region, c.PostalCode, c.Country FROM dbo.CustomerV c  INNER JOIN dbo.Orders o  \tON c.CustomerID = o.CustomerID  GO  ALTER view dbo.Invoices AS SELECT Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, Orders.ShipRegion, Orders.ShipPostalCode, \tOrders.ShipCountry, Orders.CustomerID, Customer.CompanyName AS CustomerName, Customer.Address, Customer.City, \tCustomer.Region, Customer.PostalCode, Customer.Country, \t(FirstName + ' ' + LastName) AS Salesperson, \tOrders.OrderID, Orders.OrderDate, Orders.RequiredDate, Orders.ShippedDate, Shippers.CompanyName As ShipperName, \t&quot;Order Details&quot;.ProductID, Products.ProductName, &quot;Order Details&quot;.UnitPrice, &quot;Order Details&quot;.Quantity, \t&quot;Order Details&quot;.Discount, \t(CONVERT(money,(&quot;Order Details&quot;.UnitPrice * Quantity*(1-Discount)\/100))*100) AS ExtendedPrice, Orders.Freight FROM \tShippers INNER JOIN \t\t(Products INNER JOIN \t\t\t( \t\t\t\t(Employees INNER JOIN \t\t\t\t\t(dbo.CustomerV Customer INNER JOIN Orders ON Customer.CustomerID = Orders.CustomerID) \t\t\t\tON Employees.EmployeeID = Orders.EmployeeID) \t\t\tINNER JOIN &quot;Order Details&quot; ON Orders.OrderID = &quot;Order Details&quot;.OrderID) \t\tON Products.ProductID = &quot;Order Details&quot;.ProductID) \tON Shippers.ShipperID = Orders.ShipVia  GO  ALTER view dbo.[Customer and Suppliers by City] AS SELECT City, CompanyName, ContactName, 'Customers' AS Relationship FROM dbo.CustomerV UNION SELECT City, CompanyName, ContactName, 'Suppliers' FROM Suppliers --ORDER BY City, CompanyName  GO      <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u044f \u0438 \u043f\u0440\u043e\u0433\u043e\u043d\u044f\u0435\u043c \u0442\u0435\u0441\u0442\u044b.<br \/>  \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u041e\u041a \u2014 \u0412\u044b \u043c\u043e\u043b\u043e\u0434\u0435\u0446, \u0432\u0441\u0435 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438.<\/p>\n<p>  <\/p>\n<h3>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u00ab\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 CRUD\u00bb<\/h3>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u043c\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0445 \u0434\u043e\u0441\u0442\u0443\u043f (SELECT, INSERT, UPDATE, DELETE) \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>  \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433:  <\/p>\n<ul>\n<li>\u0421\u043a\u0440\u044b\u0442\u044c \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u0412\u043d\u0435\u0448\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043c\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439.  <\/li>\n<li>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a (\u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438, \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438 \u0442.\u0434.);<\/li>\n<li>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0442\u043e\u043c \u043a\u0442\u043e \u0438 \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u043b;<\/li>\n<li>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0440\u0435\u0448\u0430\u0442\u044c \u043a\u043e\u0433\u0434\u0430 SQL-\u043a\u043e\u0434 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<\/ul>\n<p>  \u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u043c\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b <i>dbo.Customer<\/i> \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c <a href=\"http:\/\/sqlrefactorstudio.com\/Features\/Details\/CRUD\">Add CRUD Methods<\/a> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 SQL Refactor Studio. \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432 OE \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0434\u0430\u043b\u0435\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u043c \u043c\u0435\u043d\u044e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0443\u043d\u043a\u0442 <i>SQL Refactor Studio -&gt; Add CRUD Methods<\/i>. <br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/985\/81d\/49b\/98581d49bf4e4b1f9d9bf96f2d39332b.png\"\/><br \/>  \u0412 \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0435\u043c\u0441\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0416\u043c\u0435\u043c <i>Next<\/i>. \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u0440\u043e\u043b\u0438. \u041d\u0430\u0436\u0438\u043c\u0430\u0435\u043c <i>Finish<\/i> \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0441 \u0445\u0440\u0430\u043d\u0438\u043c\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430\u043c\u0438. \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">IF (object_id(N'dbo.Customer_Create') IS NULL) BEGIN \tEXEC ('create procedure dbo.Customer_Create as return 0') END GO -- ============================================= -- -- \tdbo.Customer_Create -- --\tCreate method. -- -- \tDate: 07.09.2015, @HabraUser -- -- ============================================= ALTER PROCEDURE dbo.Customer_Create   @CustomerID NCHAR(5) ,@CompanyName NVARCHAR(40) ,@ContactName NVARCHAR(30) = NULL ,@ContactTitle NVARCHAR(30) = NULL ,@Address NVARCHAR(60) = NULL ,@PostalCode NVARCHAR(10) = NULL ,@Phone NVARCHAR(24) = NULL ,@Fax NVARCHAR(24) = NULL ,@CityId INT = NULL AS BEGIN SET NOCOUNT ON  INSERT INTO dbo.Customer ( \tCustomerID \t,CompanyName \t,ContactName \t,ContactTitle \t,Address \t,PostalCode \t,Phone \t,Fax \t,CityId ) VALUES ( \t@CustomerID \t,@CompanyName \t,@ContactName \t,@ContactTitle \t,@Address \t,@PostalCode \t,@Phone \t,@Fax \t,@CityId )  \tRETURN 0 END \/* declare \t@CustomerID NChar(5),\t \t@CompanyName NVarChar(40),\t \t@ContactName NVarChar(30),\t \t@ContactTitle NVarChar(30),\t \t@Address NVarChar(60),\t \t@PostalCode NVarChar(10),\t \t@Phone NVarChar(24),\t \t@Fax NVarChar(24),\t \t@CityId Int\t  select \t@CustomerID = 'CustomerID',\t \t@CompanyName = 'CompanyName',\t \t@ContactName = 'ContactName',\t \t@ContactTitle = 'ContactTitle',\t \t@Address = 'Address',\t \t@PostalCode = 'PostalCode',\t \t@Phone = 'Phone',\t \t@Fax = 'Fax',\t \t@CityId = null\t  exec  dbo.Customer_Create \t@CustomerID = @CustomerID,\t \t@CompanyName = @CompanyName,\t \t@ContactName = @ContactName,\t \t@ContactTitle = @ContactTitle,\t \t@Address = @Address,\t \t@PostalCode = @PostalCode,\t \t@Phone = @Phone,\t \t@Fax = @Fax,\t \t@CityId = @CityId\t  *\/ GO  IF (object_id(N'dbo.Customer_Get') IS NULL) BEGIN EXEC ('create procedure dbo.Customer_Get as return 0') END GO  -- ============================================= -- -- \tdbo.Customer_Get -- --\tRead method. -- -- \tDate: 07.09.2015, @HabraUser -- -- ============================================= ALTER PROCEDURE dbo.Customer_Get \t@CustomerID NCHAR(5) AS BEGIN SET NOCOUNT ON  SELECT   CustomerID ,CompanyName ,ContactName ,ContactTitle ,Address ,PostalCode ,Phone ,Fax ,CityId FROM dbo.Customer WHERE \tCustomerID = @CustomerID  RETURN 0 END \/* declare \t@CustomerID NChar(5)\t  select \t@CustomerID = ?\t  exec dbo.Customer_Get \t@CustomerID = @CustomerID\t *\/ GO  IF (object_id(N'dbo.Customer_Save') IS NULL) BEGIN EXEC ('create procedure dbo.Customer_Save as return 0') END GO  -- ============================================= -- -- \tdbo.Customer_Save -- --\tUpdate method. -- -- \tDate: 07.09.2015, @HabraUser -- -- ============================================= ALTER PROCEDURE dbo.Customer_Save   @CustomerID NCHAR(5) ,@CompanyName NVARCHAR(40) ,@ContactName NVARCHAR(30) = NULL ,@ContactTitle NVARCHAR(30) = NULL ,@Address NVARCHAR(60) = NULL ,@PostalCode NVARCHAR(10) = NULL ,@Phone NVARCHAR(24) = NULL ,@Fax NVARCHAR(24) = NULL ,@CityId INT = NULL AS BEGIN SET NOCOUNT ON  UPDATE t \tSET t.CompanyName = @CompanyName \t,t.ContactName = @ContactName \t,t.ContactTitle = @ContactTitle \t,t.Address = @Address \t,t.PostalCode = @PostalCode \t,t.Phone = @Phone \t,t.Fax = @Fax \t,t.CityId = @CityId FROM dbo.Customer AS t WHERE \tt.CustomerID = @CustomerID  RETURN 0 END \/* \tset nocount on \tset quoted_identifier, ansi_nulls, ansi_warnings, arithabort, concat_null_yields_null, ansi_padding on \tset numeric_roundabort off \tset transaction isolation level read uncommitted  \tdeclare \t\t@CustomerID NChar(5),\t \t\t@CompanyName NVarChar(40),\t \t\t@ContactName NVarChar(30),\t \t\t@ContactTitle NVarChar(30),\t \t\t@Address NVarChar(60),\t \t\t@PostalCode NVarChar(10),\t \t\t@Phone NVarChar(24),\t \t\t@Fax NVarChar(24),\t \t\t@CityId Int\t  \tselect \t\t@CustomerID = 'CustomerID',\t \t\t@CompanyName = 'CompanyName',\t \t\t@ContactName = 'ContactName',\t \t\t@ContactTitle = 'ContactTitle',\t \t\t@Address = 'Address',\t \t\t@PostalCode = 'PostalCode',\t \t\t@Phone = 'Phone',\t \t\t@Fax = 'Fax',\t \t\t@CityId = null\t   \tbegin try \t\tbegin tran \t\t\texec dbo.Customer_Save \t\t\t\t@CustomerID = @CustomerID,\t \t\t\t\t@CompanyName = @CompanyName,\t \t\t\t\t@ContactName = @ContactName,\t \t\t\t\t@ContactTitle = @ContactTitle,\t \t\t\t\t@Address = @Address,\t \t\t\t\t@PostalCode = @PostalCode,\t \t\t\t\t@Phone = @Phone,\t \t\t\t\t@Fax = @Fax,\t \t\t\t\t@CityId = @CityId\t \t \t\t\tselect t.* \t\t\tfrom dbo.Customer as t \t\t\twhere\t \t\t\t\tt.CustomerID = @CustomerID  \t\t\tif @@trancount &gt; 0 \t\t\t\trollback tran  \tend try \tbegin catch \t\tif @@trancount &gt; 0 \t\t\trollback tran \t \t\tdeclare \t\t\t@err nvarchar(2000) \t\t \t\t  set @err =  \t\t\t  'login: ' + suser_sname() + char(10) \t\t\t+ 'ErrorNumber: ' + cast(isnull(error_number(), 0) as varchar) + char(10) \t\t\t+ 'ErrorProcedure: ' + isnull(error_procedure(), '') + char(10) \t\t\t+ 'ErrorLine: ' + cast(isnull(error_line(), 0) as varchar) + char(10) \t\t\t+ 'ErrorMessage: ' + isnull(error_message(), '') + char(10) \t\t\t+ 'Date: ' + cast(getdate() as varchar) + char(10) \t \t\tprint @err \t\traiserror(@err, 16, 1) \tend catch *\/ GO  IF (object_id(N'dbo.Customer_Del') IS NULL) BEGIN EXEC ('create procedure dbo.Customer_Del as return 0') END GO  -- ============================================= -- -- \tdbo.Customer_Del -- --\tDelete method. -- -- \tDate: 07.09.2015, @HabraUser -- -- ============================================= ALTER PROCEDURE dbo.Customer_Del @CustomerID NCHAR(5) AS BEGIN SET NOCOUNT ON  BEGIN TRY \tBEGIN TRAN  \t\/* uncomment if needed \t\tdelete from dbo.CustomerCustomerDemo where CustomerID = ? \t\tdelete from dbo.Orders where CustomerID = ?   \t*\/ \tDELETE \tFROM dbo.Customer \tWHERE CustomerID = @CustomerID  \tCOMMIT TRAN END TRY  BEGIN CATCH IF @@trancount &gt; 0 \tROLLBACK TRAN  -- catch exception (add you code here) DECLARE @err NVARCHAR(2000)  SET @err = ERROR_MESSAGE()  RAISERROR (@err, 16, 1) END CATCH  RETURN 0 END \/* declare \t@CustomerID NChar(5)\t  select \t@CustomerID = ?\t  exec dbo.Customer_Del \t@CustomerID = @CustomerID\t  *\/ GO  IF (object_id(N'dbo.Customer_List') IS NULL) BEGIN EXEC ('create procedure dbo.Customer_List as return 0') END GO  -- ============================================= -- -- \tdbo.Customer_List -- --\tList method. -- -- \tDate: 07.09.2015, @HabraUser -- -- ============================================= ALTER PROCEDURE dbo.Customer_List AS BEGIN SET NOCOUNT ON  SELECT  \t CustomerID \t,CompanyName \t,ContactName \t,ContactTitle \t,Address \t,PostalCode \t,Phone \t,Fax \t,CityId FROM dbo.Customer \/* uncomment if needed \tleft join dbo.City as t1 on t1.CityId = t.CityId *\/ RETURN 0 END \/* exec dbo.Customer_List *\/ GO      <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0415\u0441\u043b\u0438 \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u043b\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440, \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/65e\/40a\/f1d\/65e40af1dbd544d78c01228d1bd7707e.png\"\/><\/p>\n<p>  \u041a\u0430\u0436\u0434\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d T4. \u041f\u0440\u043e T4 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"http:\/\/www.olegsych.com\/2009\/09\/t4-preprocessed-text-templates\/\">\u0442\u0443\u0442<\/a> \u0438 <a href=\"http:\/\/www.olegsych.com\/2008\/09\/t4-tutorial-creating-reusable-code-generation-templates\/\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>  <\/p>\n<h3>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u00ab\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430 \u0434\u043b\u044f \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445\u00bb<\/h3>\n<p>  \u042d\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0432\u0435\u0441\u0442\u0438 \u043d\u043e\u0432\u044b\u0439 \u0442\u0440\u0438\u0433\u0433\u0435\u0440, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0446\u0435\u043b\u044f\u0445 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0430\u0443\u0434\u0438\u0442\u0430.<br \/>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u00ab\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430 \u0434\u043b\u044f \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445\u00bb \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u0430 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0430\u043c\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432\u0430\u0436\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043b\u044e\u0431\u043e\u043c \u0432\u043d\u0435\u0448\u043d\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0438 \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u043d\u0443\u0442\u044c \u0430\u0443\u0434\u0438\u0442\u0443.<br \/>  \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0442 \u0444\u0430\u043a\u0442 \u0447\u0442\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 DML.<br \/>  \u041a\u0430\u043a \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0443 \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/technet.microsoft.com\/ru-ru\/library\/Bb522489(v=SQL.105).aspx\">Change Data Capture<\/a> (\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043d\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439). <\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b <i>dbo.Customer<\/i> \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433.<br \/>  \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 OE, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u043c \u043c\u0435\u043d\u044e \u043f\u0443\u043d\u043a\u0442 <i>SQL Refactor Studio \u2014 Introduce Trigger for History<\/i>. \u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. <br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c2b\/7f2\/751\/c2b7f275113e4a62b50e8e9d067367f0.png\"\/><br \/>  \u0416\u043c\u0435\u043c <i>Next<\/i>. \u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0430. <br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/732\/72f\/d30\/73272fd30b06463db4a11a1e323030ae.png\"\/><\/p>\n<p>  \u0416\u043c\u0435\u043c <i>Finish<\/i> \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442. \u0421\u043a\u0440\u0438\u043f\u0442 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0442\u0440\u0438\u0433\u0433\u0435\u0440 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">CREATE TABLE [dbo].[CustomerHistory] ( [id] [bigint] IDENTITY NOT NULL ,[action_type] [char](1) NOT NULL ,[modified_date] [datetime] CONSTRAINT [DF_CustomerHistory_modified_date] DEFAULT getdate() ,[modified_login] [sysname] CONSTRAINT [DF_CustomerHistory_modified_login] DEFAULT suser_sname() ,[host_name] [nvarchar](128) CONSTRAINT [DF_CustomerHistory_host_name] DEFAULT host_name() ,[program_name] [nvarchar](128) CONSTRAINT [DF_CustomerHistory_program_name] DEFAULT program_name() ,[CompanyName_old] [nvarchar](40) ,[CompanyName_new] [nvarchar](40) ,[ContactName_old] [nvarchar](30) ,[ContactName_new] [nvarchar](30) ,[ContactTitle_old] [nvarchar](30) ,[ContactTitle_new] [nvarchar](30) ,[Address_old] [nvarchar](60) ,[Address_new] [nvarchar](60) ,[PostalCode_old] [nvarchar](10) ,[PostalCode_new] [nvarchar](10) ,[Phone_old] [nvarchar](24) ,[Phone_new] [nvarchar](24) ,[Fax_old] [nvarchar](24) ,[Fax_new] [nvarchar](24) ,[CityId_old] [int] ,[CityId_new] [int] ,[CustomerID_old] [nchar](5) ,[CustomerID_new] [nchar](5) ,CONSTRAINT [PK_CustomerHistory] PRIMARY KEY ([id]) ) GO  CREATE TRIGGER [dbo].[trg_CustomerHistory] ON [dbo].[Customer] AFTER INSERT, DELETE, UPDATE AS SET NOCOUNT ON  DECLARE @action_type CHAR(1)  IF EXISTS (SELECT *FROM inserted) AND EXISTS (SELECT * FROM deleted) \tSET @action_type = 'U' ELSE IF EXISTS (SELECT * FROM inserted) AND NOT EXISTS (SELECT * FROM deleted) \tSET @action_type = 'I' ELSE IF NOT EXISTS (SELECT * FROM inserted) AND EXISTS (SELECT * FROM deleted) \tSET @action_type = 'D'  INSERT INTO dbo.CustomerHistory ( \t action_type \t,CompanyName_old \t,CompanyName_new \t,ContactName_old \t,ContactName_new \t,ContactTitle_old \t,ContactTitle_new \t,Address_old \t,Address_new \t,PostalCode_old \t,PostalCode_new \t,Phone_old \t,Phone_new \t,Fax_old \t,Fax_new \t,CityId_old \t,CityId_new \t,CustomerID_old \t,CustomerID_new ) SELECT  \t @action_type \t,d.CompanyName \t,i.CompanyName \t,d.ContactName \t,i.ContactName \t,d.ContactTitle \t,i.ContactTitle \t,d.Address \t,i.Address \t,d.PostalCode \t,i.PostalCode \t,d.Phone \t,i.Phone \t,d.Fax \t,i.Fax \t,d.CityId \t,i.CityId \t,d.CustomerID \t,i.CustomerID FROM inserted i FULL OUTER JOIN deleted d  \tON (i.CustomerID = d.CustomerID) GO      <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u043e\u043a\u0430 \u0432\u0441\u0451. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0412\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0438 \u0432 \u0412\u0430\u0448\u0438\u0445 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a.<br \/>  \u0423\u0434\u0430\u0447\u0438!<\/p>\n<p>  <\/p>\n<h2>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b<\/h2>\n<p>  <\/p>\n<ul>\n<li> <a href=\"http:\/\/databaserefactoring.com\/\">http:\/\/databaserefactoring.com<\/a> <\/li>\n<li>\u0421\u043a\u043e\u0442\u0442 \u0410\u043c\u0431\u043b\u0435\u0440, \u041f\u0440\u0430\u043c\u043e\u0434\u043a\u0443\u043c\u0430\u0440 \u0414\u0436. \u0421\u0430\u0434\u0430\u043b\u0430\u0434\u0436 <a href=\"http:\/\/www.ozon.ru\/context\/detail\/id\/3261793\/\">\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0432\u043e\u043b\u044e\u0446\u0438\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><\/li>\n<li>\u041c\u0430\u0440\u0442\u0438\u043d \u0424\u0430\u0443\u043b\u0435\u0440 <a href=\"http:\/\/www.ozon.ru\/context\/detail\/id\/1308678\/\">\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433.\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430<\/a> <\/li>\n<li>\u041f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f SSMS <a href=\"http:\/\/sqlrefactorstudio.com\/\">SQL Refactor Studio<\/a> <\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/258629\/\"> http:\/\/habrahabr.ru\/post\/258629\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u042f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435 \u0441\u0445\u0435\u043c \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 MS SQL Server.<\/p>\n<blockquote><p>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u2014 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f, \u0438\u043c\u0435\u044e\u0449\u0435\u0435 \u0446\u0435\u043b\u044c\u044e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u043d\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f.<\/p><\/blockquote>\n<p><i>\u2014 Martin Fowler<\/i><\/p>\n<p>  \u041e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435 \u043a\u043e\u0434\u0430 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0435\u043c\u0430\u043b\u043e \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b, \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043a\u043e\u0434\u0430.<br \/>  \u0410 \u0432\u043e\u0442 \u043f\u0440\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0441\u0445\u0435\u043c \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u042f \u0440\u0435\u0448\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b \u0438 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-265318","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=265318"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265318\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=265318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=265318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=265318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}