tailieunhanh - Hướng dẫn học Microsoft SQL Server 2008 part 43

Tham khảo tài liệu 'hướng dẫn học microsoft sql server 2008 part 43', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Part II Manipulating Data with Select VALUES DEFAULT From Default -- GUID from function INSERT ProductCategorylD ProductCategoryName VALUES NewID From Function -- GUID in variable DECLARE @NewGUID Uniqueldentifier SET @NewGUID NewID INSERT ProductCategoryID ProductCategoryName VALUES @NewGUID From Variable To view the results of the previous three methods of inserting a GUID the following SELECT statement is filtered to those rows that are like From SELECT ProductCategoryID ProductCategoryName FROM WHERE ProductCategoryName like From Result ProductCategoryID ProductCategoryName 25894DA7-B5BB-435D-9540-6B9207C6CF8F From Default 393414DC-8611-4460-8FD3-4657E4B49373 From Function FF868338-DF9A-4B8D-89B6-9C28293CA25F From Variable This INSERT statement uses the NEWID function to insert multiple GUIDs INSERT ProductCategoryID ProductCategoryName Select NewID LastName From The following SELECT statement retrieves the new GUIDs SELECT ProductCategoryID ProductCategoryName FROM Result ProductCategoryID ProductCategoryName 1B2BBE15-B415-43ED-BCA2-293050B7EFE4 Kite 23FC5D45-8B60-4800-A505-D2F556F863C9 Accessory 3889671A-F2CD-4B79-8DCF-19F4F4703693 Video 382 Modification Obstacles 16 5471F896-A414-432B-A579-0880757ED097 Fletcher 428F29B3-111B-4ECE-B6EB-E0913A9D34DC Atlas E4B7D325-8122-48D7-A61B-A83E258D8729 Bistier The final GUID insert example features my recommended method NEWSEQUENTIALID . The function is defined as the default for the primary key column. Three rows are inserted and then selected USE tempdb CREATE TABLE GUIDtable GUIDtableID UNIQUEIDENTIFIER NOT NULL DEFAULT NewSequentialID PRIMARY KEY Col1 CHAR 1 INSERT GUIDtable Col1 VALUES a b c SELECT GUIDtableID Col1 FROM GUIDtable Result GUIDtableID Coll 748040E1-210D-DE11-8196-002170BF2EB9 a 758040E1-210D-DE11-8196-002170BF2EB9 b 768040E1-210D-DE11-8196-002170BF2EB9 c SQL Server .