Home
%3CLINGO-SUB%20id%3D%22lingo-sub-718187%22%20slang%3D%22en-US%22%3ECommon%20Data%20Warehouse%20Functionality%20Redefined%20By%20CTAS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-718187%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22WordSection1%22%3E%0A%3CP%20class%3D%22MsoNormal%22%3EIf%20you%20are%20new%20to%20Azure%20SQL%20DW%2C%20you%20may%20not%20be%20aware%20of%20some%20syntax%20that%20is%20unique%20to%20Microsoft%20MPP%20platforms.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EOne%20specific%20syntactic%20feature%20is%3A%20%E2%80%9C%3CI%3ECreate%20Table%20%3CSPAN%20class%3D%22GramE%22%3EAs%3C%2FSPAN%3ESelect%E2%80%9D%3C%2FI%3E(CTAS).This%20might%20seem%20like%20it%20is%20the%20same%20as%20our%20old%20friend%20%E2%80%9C%3CI%3ESelect%20Into%3C%2FI%3E%E2%80%9D%20but%20the%20new%20syntax%20coupled%20with%20DW%20architecture%20offers%20a%20new%20world%20of%20possibilities%20when%20managing%20large%20quantities%20of%20data.%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3EFirst%2C%20lets%20talk%20about%20the%20syntax.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EYou%20can%20see%20right%20away%20from%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fstatements%2Fcreate-table-as-select-azure-sql-data-warehouse%3Fview%3Daps-pdw-2016-au7%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Et-%3CSPAN%20class%3D%22SpellE%22%3Esql%3C%2FSPAN%3Edocumentation%3C%2FA%3Ethat%20there%20is%20a%20little%20more%20to%20this%20functionality%20than%20the%20simple%20%E2%80%9C%3CI%3ESelect%20Into%3C%2FI%3E%E2%80%9D.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EYou%20can%20easily%20add%20indexes%2C%20partitions%2C%20and%20change%20your%20table%20distribution%20in%20a%20single%20statement.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3EThe%20real%20power%20of%20CTAS%20is%20realized%20in%20context%20of%20the%20data%20warehouse%20architecture%20and%20in%20loading%2Fprocessing%20strategies.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EAzure%20SQL%20Data%20Warehouse%20offers%20neither%20explicit%20primary%20nor%20foreign%20key%20constraints.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EFor%20users%20coming%20from%20a%20traditional%20RDB%20platform%20this%20is%20seen%20a%20limitation%20of%20the%20platform%3B%20however%2C%20this%20is%20a%20strength%20for%20the%20DW%20environment.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EApplication%20databases%20are%20typically%20in%203NF%20where%20foreign%20and%20primary%20constraints%20are%20needed%20for%20integrity.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EIn%20a%20DW%20environment%2C%20the%20integrity%20of%20the%20data%20is%20inherited%20from%20the%20source%20systems%20and%20denormalization%20demands%20that%20constraints%20are%20implied%20(rather%20than%20explicitly%20applied)%20to%20provide%20further%20performance%20gains%20on%20the%20platform.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3ETraditional%20waterfall%20approaches%20to%20database%20development%20where%20DDL%20is%20deployed%20and%20only%20DML%20is%20performed%20in%20production.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3ENew%20demands%20for%20performant%20big%20data%20environments%20call%20for%20new%20architectures.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EWe%20can%E2%80%99t%20just%20deploy%20database%20structures%20that%20never%20change%3B%20instead%2C%20the%20data%20must%20be%20deployed%20and%20the%20structures%2Fmodels%20that%20define%20the%20data%20must%20be%20fluid%20and%20change%20as%20business%20requirements%20change.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EIn%20Azure%20SQL%20Data%20Warehouse%2C%20CTAS%20is%20the%20most%20powerful%20and%20efficient%20method%20to%20change%20the%20database%20structure%20to%20meet%20the%20needs%20of%20the%20business.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EIn%20addition%20to%20changing%20database%20structures%20for%20business%20needs%2C%20data%20loading%20methodologies%20demand%20higher%20performance%20than%20traditional%20merge%20commands%20(which%20are%20not%20available%20in%20Azure%20DW).%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3EBefore%20digging%20into%20some%20examples%20of%20CTAS%20functionality%2C%20I%20need%20to%20mention%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fstatements%2Frename-transact-sql%3Fview%3Dsqlallproducts-allversions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERENAME%20functionality%3C%2FA%3E.%20RENAME%20is%20the%20second%20half%20of%20the%20solution%20to%20fast%20data%20loading%20in%20Azure%20SQL%20Data%20Warehouse.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3ERENAME%20eliminates%20the%20need%20for%20large%20amounts%20of%20code%2C%20ensures%20appropriate%20locking%20of%20objects%20and%20limits%20the%20impact%20that%20object%20locks%20can%20have%20on%20end%20users.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3ECTAS%20plus%20RENAME%20become%20a%20very%20powerful%20combination%20in%20loading%2C%20managing%2C%20and%20administering%20your%20Azure%20SQL%20DW%20environment.%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3ECTAS%20is%20highly%20optimized%20for%20Azure%20SQL%20Data%20Warehouse%20and%20a%20is%20full%20parallelized%20allowing%20for%20maximum%20throughput%20between%20compute%20nodes%20internal%20to%20the%20DW%20environment.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EWhen%20CTAS%20completes%2C%20the%20table%20level%20statistics%20are%20updated%20and%20accurate%20and%20clustered%20columnstore%20indexes%20have%20optimal%20compression.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EWith%20that%20said%2C%20there%20are%20two%20important%20attributes%20to%20be%20aware%20of%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%20class%3D%22MsoNormal%22%3EColumnstore%20index%20compression%20is%20based%20upon%20the%20resource%20class%20of%20the%20login%20performing%20the%20CTAS.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EGenerally%2C%20it%20is%20a%20best%20practice%20to%20run%20CTAS%20statements%20under%20a%20medium%20or%20large%20resource%20class%20to%20provide%20enough%20memory%20for%20records%20to%20fit%20into%20the%20buffer%20prior%20to%20being%20compressed.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EThis%20is%20especially%20important%20for%20wide%20tables.%3C%2FLI%3E%0A%3CLI%20class%3D%22MsoNormal%22%3ECTAS%20does%20not%20copy%20statistics%20(other%20than%20the%20table%20level%20statistic).%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EAny%20user%20or%20auto%20created%20statistics%20may%20need%20to%20be%20recreated%20manually%20as%20secondary%20steps%20of%20the%20CTAS%20prior%20to%20a%20RENAME%20operation.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3EBelow%20are%20some%20examples%20of%20everyday%20tasks%20that%20can%20be%20done%20using%20a%20combination%20of%20CTAS%20and%20RENAME%3A%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3EDelete%20Data%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3E(This%20example%20deletes%20data%20with%20an%20expiration%20date%20older%20than%2001%2F01%2F2000.)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECREATE%20TABLE%20XYZ%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWITH%20(DISTRIBUTION%3DROUND_ROBIN%2C%20CLUSTERED%20COLUMNSTORE%20INDEX)%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EAS%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20*%20FROM%20ABC%20WHERE%20%5BExpirationDate%5D%20%26gt%3B%3D%20%E2%80%9801%2F01%2F2000%E2%80%99%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20ABC%20TO%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20XYZ%20TO%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EDROP%20TABLE%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3EUpdate%20Data%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3E(This%20example%20updates%20a%20field%20call%20%3CSPAN%20class%3D%22SpellE%22%3EExpirationFlag%3C%2FSPAN%3Ewhere%20that%20record%E2%80%99s%20expiration%20date%20is%20older%20than%2001%2F01%2F2000)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECREATE%20TABLE%20XYZ%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWITH%20(DISTRIBUTION%3DROUND_ROBIN%2C%20CLUSTERED%20COLUMNSTORE%20INDEX)%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EAS%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%5Bcol1%5D%2C%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%5Bcol2%5D%2C%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E1%20as%20%3CSPAN%20class%3D%22SpellE%22%3EExpiredFlag%3C%2FSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EFROM%20ABC%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWHERE%20ExpirationDate%20%26lt%3B%20%E2%80%9801%2F01%2F2000%E2%80%99%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EUNION%20ALL%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%5Bcol1%5D%2C%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%5Bcol2%5D%2C%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%5B%3CSPAN%20class%3D%22SpellE%22%3EExpiredFlag%3C%2FSPAN%3E%5D%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EFROM%20ABC%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWHERE%20ExpirationDate%20%26gt%3B%3D%20%E2%80%9801%2F01%2F2000%E2%80%99%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20ABC%20TO%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20XYZ%20TO%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EDROP%20TABLE%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3EInsert%20Data%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3E(This%20example%20inserts%20records%20from%20a%20stage%20table%20into%20a%20production%20table.)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECREATE%20TABLE%20XYZ%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWITH%20(DISTRIBUTION%3DROUND_ROBIN%2C%20CLUSTERED%20COLUMNSTORE%20INDEX)%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EAS%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20*%20FROM%20ABC%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EUNION%20ALL%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20*%20FROM%20%3CSPAN%20class%3D%22SpellE%22%3EABC_Stage%3C%2FSPAN%3E%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20ABC%20TO%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20XYZ%20TO%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EDROP%20TABLE%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3EChange%20Partitions%2Fdistribution%2Findex%20on%20a%20table%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3E(This%20example%20takes%20the%20existing%20table%3A%20ABC%2C%20and%20partitions%20it%20based%20upon%20the%20new%20partition%20definition.)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECREATE%20TABLE%20XYZ%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWITH%20(DISTRIBUTION%3D%3CSPAN%20class%3D%22GramE%22%3EHASH(%3C%2FSPAN%3Ecol1)%2C%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECLUSTERED%20INDEX%20(col1)%2C%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EPARTITION%20(COL2%20RANGE%20LEFT%20FOR%20VALUES%20(10%2C20%2C30%2C40)))%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EAS%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20*%20FROM%20ABC%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20ABC%20TO%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20XYZ%20TO%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EDROP%20TABLE%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3EConcatenate%20fields%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3E(This%20is%20a%20great%20example%20of%20how%20to%20create%20new%20fields%20in%20your%20table%20based%20upon%20existing%20fields%20or%20data.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EHere%2C%20we%20are%20creating%20a%20new%20field%20out%20of%20several%20fields%20and%20using%20the%20%3CSPAN%20class%3D%22SpellE%22%3ENewField%3C%2FSPAN%3Eas%20the%20distribution%20key.)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECREATE%20TABLE%20XYZ%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWITH%20(DISTRIBUTION%3DHASH(%3CSPAN%20class%3D%22SpellE%22%3ENewField%3C%2FSPAN%3E)%2C%20CLUSTERED%20COLUMNSTORE%20INDEX)%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EAS%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20col1%2Bcol2%2Bcol3%20as%20%3CSPAN%20class%3D%22SpellE%22%3ENewField%3C%2FSPAN%3E%2C%20*%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EFROM%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20ABC%20TO%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20XYZ%20TO%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EDROP%20TABLE%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3EChange%20Datatype%20or%20nullability%20on%20a%20field%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3E(What%20happens%20when%20you%20want%20to%20change%20the%20datatype%20or%20the%20nullability%20of%20a%20field%20in%20your%20table%3F%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EThe%20new%20table%20takes%20the%20field%20datatypes%2Fnullability%2Fsizes%20and%20transfers%20them%20to%20the%20new%20table.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3EBelow%20is%20a%20work%20around%20that%20will%20help%20you%20alter%20a%20table%20definition%20quickly%20when%20the%20field%20attributes%20change.)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20Script%20out%20existing%20table%20and%20create%20a%20new%20blank%20table%20with%20the%20correct%20datatype%20or%20nullability.%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%3E%3CI%3EScripted%20from%20source%3A%3C%2FI%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECREATE%20TABLE%20ABC%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E(%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%3C%2FSPAN%3Ecol1%20integer%20not%20null%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20class%3D%22GramE%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%2Ccol%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E2%20varchar(50)%20not%20null%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20class%3D%22GramE%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%2Ccol%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E3%20varchar(50)%20not%20null%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20class%3D%22GramE%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%2C%3CSPAN%20class%3D%22SpellE%22%3EExpirationFlag%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3Ebit%20not%20null%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpLast%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20class%3D%22GramE%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%2CExpirationDate%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3Edatetime%20null)%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWITH%20(DISTRIBUTION%3DROUND_ROBIN%2C%20clustered%20columnstore%20index)%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpFirst%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%3E%3CI%3EModified%20(in%20bold)%3A%3C%2FI%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECREATE%20TABLE%20%3CSPAN%20class%3D%22SpellE%22%3EABC%3CSTRONG%3E_Blank%3C%2FSTRONG%3E%3C%2FSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E(%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%3C%2FSPAN%3Ecol1%20%3CSTRONG%3EBIGINT%3C%2FSTRONG%3Enot%20null%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20class%3D%22GramE%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%2Ccol%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E2%20varchar(50)%20%3CSTRONG%3Enull%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20class%3D%22GramE%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%2Ccol%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E3%20varchar(50)%20%3CSTRONG%3Enull%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20class%3D%22GramE%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%2C%3CSPAN%20class%3D%22SpellE%22%3EExpirationFlag%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3Ebit%20not%20null%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpLast%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20class%3D%22GramE%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3E%2CExpirationDate%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3Edatetime%20null)%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWITH%20(DISTRIBUTION%3DROUND_ROBIN%2C%20clustered%20columnstore%20index)%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2.%20Use%20a%20union%20statement%20to%20join%20blank%20table%20and%20existing%20table.%20The%20table%20created%20using%20a%20CTAS%20statement%20inherits%20the%20datatypes%20and%20nullability%20from%20the%20first%20table%20in%20the%20union%20statement%3A%20%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%3B%22%3E%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECREATE%20TABLE%20XYZ%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWITH%20(DISTRIBUTION%3DROUND_ROBIN%2C%20CLUSTERED%20COLUMNSTORE%20INDEX)%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EAS%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20*%20FROM%20ABC_BLANK%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpMiddle%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EUNION%20ALL%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpLast%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20*%20FROM%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpLast%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20mso-add-space%3A%20auto%3B%20line-height%3A%20125%25%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpLast%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20ABC%20TO%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpLast%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%20line-height%3A%20125%25%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20XYZ%20TO%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoListParagraphCxSpLast%22%20style%3D%22margin-bottom%3A%20.0001pt%3B%20text-indent%3A%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EDROP%20TABLE%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%3E%3CSTRONG%3ERebuild%20a%20clustered%20columnstore%20index%20with%20minimal%20user%20impact%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ECREATE%20TABLE%20ABC_REBUILT%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EWITH%20(DISTRIBUTION%3DROUND_ROBIN%2C%20CLUSTERED%20COLUMNSTORE%20INDEX)%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EAS%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ESELECT%20*%20FROM%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20ABC%20TO%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3ERENAME%20OBJECT%20ABC_REBUILT%20TO%20ABC%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22MsoNormal%22%20style%3D%22line-height%3A%20125%25%3B%20margin%3A%200in%200in%20.0001pt%20.5in%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2010.0pt%3B%20line-height%3A%20125%25%3B%20font-family%3A%20'Courier%20New'%3B%22%3EDROP%20TABLE%20ABC_OLD%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-718187%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you%20are%20new%20to%20Azure%20SQL%20DW%2C%20you%20may%20not%20be%20aware%20of%20some%20syntax%20that%20is%20unique%20to%20Microsoft%20MPP%20platforms.%20One%20specific%20syntactic%20feature%20is%3A%20%E2%80%9C%3CEM%3ECreate%20Table%20As%20Select%E2%80%9D%20%3C%2FEM%3E(CTAS).%20This%20might%20seem%20like%20it%20is%20the%20same%20as%20our%20old%20friend%20%E2%80%9C%3CEM%3ESelect%20Into%3C%2FEM%3E%E2%80%9D%20but%20the%20new%20syntax%20coupled%20with%20DW%20architecture%20offers%20a%20new%20world%20of%20possibilities%20when%20managing%20large%20quantities%20of%20data.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-718187%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Edata%20loading%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EData%20Warehouse%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFeatures%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPerformance%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETSQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

If you are new to Azure SQL DW, you may not be aware of some syntax that is unique to Microsoft MPP platforms.  One specific syntactic feature is: “Create Table As Select” (CTAS).This might seem like it is the same as our old friend “Select Into” but the new syntax coupled with DW architecture offers a new world of possibilities when managing large quantities of data.

 

 

First, lets talk about the syntax.  You can see right away from t-sql documentation that there is a little more to this functionality than the simple “Select Into”.  You can easily add indexes, partitions, and change your table distribution in a single statement. 

 

 

The real power of CTAS is realized in context of the data warehouse architecture and in loading/processing strategies.  Azure SQL Data Warehouse offers neither explicit primary nor foreign key constraints.  For users coming from a traditional RDB platform this is seen a limitation of the platform; however, this is a strength for the DW environment.  Application databases are typically in 3NF where foreign and primary constraints are needed for integrity.  In a DW environment, the integrity of the data is inherited from the source systems and denormalization demands that constraints are implied (rather than explicitly applied) to provide further performance gains on the platform. 

 

 

Traditional waterfall approaches to database development where DDL is deployed and only DML is performed in production.  New demands for performant big data environments call for new architectures.  We can’t just deploy database structures that never change; instead, the data must be deployed and the structures/models that define the data must be fluid and change as business requirements change.  In Azure SQL Data Warehouse, CTAS is the most powerful and efficient method to change the database structure to meet the needs of the business.  In addition to changing database structures for business needs, data loading methodologies demand higher performance than traditional merge commands (which are not available in Azure DW). 

 

 

Before digging into some examples of CTAS functionality, I need to mention the RENAME functionality. RENAME is the second half of the solution to fast data loading in Azure SQL Data Warehouse.  RENAME eliminates the need for large amounts of code, ensures appropriate locking of objects and limits the impact that object locks can have on end users.  CTAS plus RENAME become a very powerful combination in loading, managing, and administering your Azure SQL DW environment.

 

 

CTAS is highly optimized for Azure SQL Data Warehouse and a is full parallelized allowing for maximum throughput between compute nodes internal to the DW environment.  When CTAS completes, the table level statistics are updated and accurate and clustered columnstore indexes have optimal compression.  With that said, there are two important attributes to be aware of:

  1. Columnstore index compression is based upon the resource class of the login performing the CTAS.  Generally, it is a best practice to run CTAS statements under a medium or large resource class to provide enough memory for records to fit into the buffer prior to being compressed.  This is especially important for wide tables.
  2. CTAS does not copy statistics (other than the table level statistic).  Any user or auto created statistics may need to be recreated manually as secondary steps of the CTAS prior to a RENAME operation.

 

Below are some examples of everyday tasks that can be done using a combination of CTAS and RENAME:

 

 

Delete Data

(This example deletes data with an expiration date older than 01/01/2000.)

 

CREATE TABLE XYZ

WITH (DISTRIBUTION=ROUND_ROBIN, CLUSTERED COLUMNSTORE INDEX)

AS

SELECT * FROM ABC WHERE [ExpirationDate] >= ‘01/01/2000’;

 

RENAME OBJECT ABC TO ABC_OLD;

RENAME OBJECT XYZ TO ABC;

DROP TABLE ABC_OLD;

 

 

Update Data

(This example updates a field call ExpirationFlag where that record’s expiration date is older than 01/01/2000)

 

CREATE TABLE XYZ

WITH (DISTRIBUTION=ROUND_ROBIN, CLUSTERED COLUMNSTORE INDEX)

AS

SELECT

[col1],

[col2],

1 as ExpiredFlag

FROM ABC

WHERE ExpirationDate < ‘01/01/2000’

UNION ALL

SELECT

[col1],

[col2],

[ExpiredFlag]

FROM ABC

WHERE ExpirationDate >= ‘01/01/2000’;

 

RENAME OBJECT ABC TO ABC_OLD;

RENAME OBJECT XYZ TO ABC;

DROP TABLE ABC_OLD;

 

 

Insert Data

(This example inserts records from a stage table into a production table.)

 

CREATE TABLE XYZ

WITH (DISTRIBUTION=ROUND_ROBIN, CLUSTERED COLUMNSTORE INDEX)

AS

SELECT * FROM ABC

UNION ALL

SELECT * FROM ABC_Stage;

 

RENAME OBJECT ABC TO ABC_OLD;

RENAME OBJECT XYZ TO ABC;

DROP TABLE ABC_OLD;

 

 

Change Partitions/distribution/index on a table

(This example takes the existing table: ABC, and partitions it based upon the new partition definition.)

 

CREATE TABLE XYZ

WITH (DISTRIBUTION=HASH(col1),

CLUSTERED INDEX (col1),

PARTITION (COL2 RANGE LEFT FOR VALUES (10,20,30,40)))

AS

SELECT * FROM ABC

 

RENAME OBJECT ABC TO ABC_OLD;

RENAME OBJECT XYZ TO ABC;

DROP TABLE ABC_OLD;

 

 

Concatenate fields

(This is a great example of how to create new fields in your table based upon existing fields or data.  Here, we are creating a new field out of several fields and using the NewField as the distribution key.)

 

CREATE TABLE XYZ

WITH (DISTRIBUTION=HASH(NewField), CLUSTERED COLUMNSTORE INDEX)

AS

SELECT col1+col2+col3 as NewField, *

FROM ABC;

 

RENAME OBJECT ABC TO ABC_OLD;

RENAME OBJECT XYZ TO ABC;

DROP TABLE ABC_OLD;

 

 

Change Datatype or nullability on a field

(What happens when you want to change the datatype or the nullability of a field in your table?  The new table takes the field datatypes/nullability/sizes and transfers them to the new table.  Below is a work around that will help you alter a table definition quickly when the field attributes change.)

 

1. Script out existing table and create a new blank table with the correct datatype or nullability. 

Scripted from source:

CREATE TABLE ABC

(

 col1 integer not null

,col2 varchar(50) not null

,col3 varchar(50) not null

,ExpirationFlag bit not null

,ExpirationDate datetime null)

WITH (DISTRIBUTION=ROUND_ROBIN, clustered columnstore index);

 

Modified (in bold):

CREATE TABLE ABC_Blank

(

 col1 BIGINT not null

,col2 varchar(50) null

,col3 varchar(50) null

,ExpirationFlag bit not null

,ExpirationDate datetime null)

WITH (DISTRIBUTION=ROUND_ROBIN, clustered columnstore index);

 

 

2. Use a union statement to join blank table and existing table. The table created using a CTAS statement inherits the datatypes and nullability from the first table in the union statement:  

 

CREATE TABLE XYZ

WITH (DISTRIBUTION=ROUND_ROBIN, CLUSTERED COLUMNSTORE INDEX)

AS

SELECT * FROM ABC_BLANK

UNION ALL

SELECT * FROM ABC;

 

RENAME OBJECT ABC TO ABC_OLD;

RENAME OBJECT XYZ TO ABC;

DROP TABLE ABC_OLD;

 

 

Rebuild a clustered columnstore index with minimal user impact:

CREATE TABLE ABC_REBUILT

WITH (DISTRIBUTION=ROUND_ROBIN, CLUSTERED COLUMNSTORE INDEX)

AS

SELECT * FROM ABC;

 

RENAME OBJECT ABC TO ABC_OLD;

RENAME OBJECT ABC_REBUILT TO ABC;

DROP TABLE ABC_OLD;