SQL SERVER ÈçºÎÏò±íÖвåÈëÊý¾Ý ÏÂÔر¾ÎÄ

ÏàÐÅ´ó¼Ò¶¼ÖªµÀÔõÑùʹÓÃÊý¾Ý²Ù×÷ÓïÑÔ(DML)¶ÔSQL Server±íµÄÊý¾Ý½øÐвåÈ롢ɾ³ýºÍ¸üеȴ¦Àí¡£ÓÐʱºò£¬ÎÒÃÇÐèÒªÓÃINSERTÓï¾ä½øÐвåÈëµÄÊý¾ÝʵÔÚÊǶàµÃÈÃÈËÍ·ÌÛ£¬Óкܶഫͳµ«·±ËöµÄ·½·¨¿ÉÒÔÓÃÀ´²åÈë´óÅúÁ¿Êý¾Ý£¬²»¹ýSQL Server 2008ÌṩÁËÒ»ÖÖÄܹ»¼ò»¯Êý¾Ý²åÈë¹ý³ÌµÄз½·¨¡£±¾ÎĽ«Îª´ó¼Ò¼òµ¥½éÉÜÕâЩÓÃÀ´²åÈëÊý¾ÝµÄ·½·¨Ö®¼äµÄ²îÒ죬ÆäÖаüÀ¨SQL Server 2008ÌṩµÄз½·¨¡ª¡ªÐÐÖµ¹¹ÔìÆ÷(Row Value Constructor)¡£ ÎÒÃÇÏò±í²åÈëÊý¾ÝµÄ´«Í³·½·¨ÓÐÈý¸ö£¬½éÉÜÈçÏ£º ·½·¨Ò» ¼ÙÉèÎÒÃÇÓÐÒ»¸öÃûΪMyTestDBµÄÊý¾Ý¿â£¬ÆäÖÐÓÐÒ»¸öÃûΪMyTest1µÄ±í£¬Êý¾Ý¿âºÍ±íµÄ´´½¨¹ý³ÌÈçÏ£º USE [master] GO IF EXISTS (SELECT name FROM sys.databases WHERE name = N'MyTestDB') DROP DATABASE [MyTestDB] GO Create database MyTestDB Go Use [MyTestDB] Go IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MyTest1]') AND type in (N'U')) DROP TABLE [dbo].[MyTest1] GO USE [MyTestDB] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[MyTest1]( [Id] [int] NULL, [Fname] [varchar](100) NULL, [Lname] [varchar](100) NULL, [salary] [money] NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO ÏÖÔÚÎÒÃÇÓô«Í³µÄANSI²åÈëÓï¾äÏòÉϱíÌí¼Ó5ÐÐÊý¾Ý£¬ÕâÀïÐèÒªÓõ½´øVALUE´Ó¾äµÄINSERT SQLÓï¾äÀ´²åÈëÊý¾Ý£¬½Å±¾ÈçÏ£º insert into MyTest1 (id ,fname ,lname , salary) values (1 , 'John' , 'Smith' , 150000.00) insert into MyTest1 (id ,fname ,lname , salary) values (2 , 'Hillary' , 'Swank' , 250000.00) insert into MyTest1 (id ,fname ,lname , salary) values (3 , 'Elisa' , 'Smith' , 120000.00) insert into MyTest1 (id ,fname ,lname , salary) values (4 , 'Liz' , 'Carleno' , 151000.00) insert into MyTest1 (id ,fname ,lname , salary) values (5 , 'Tony' , 'Mcnamara' , 150300.00) Ö´Ðнá¹ûÈçÏ£º (1 row(s) affected) (1 row(s) affected) (1 row(s) affected) (1 row(s) affected) (1 row(s) affected) ·½·¨¶þ ¼ÙÉèÎÒÃÇÔÚÉÏÊöµÄMyTestDBÊý¾Ý¿âÖÐÓбíMyTest2£¬ÈçÏ£º USE [MyTestDB] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MyTest2]') AND type in (N'U')) DROP TABLE [dbo].[MyTest2] GO CREATE TABLE [dbo].[MyTest2]( [Id] [int] NULL, [Fname] [varchar](100) NULL, [Lname] [varchar](100) NULL, [salary] [money] NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO ÏÂÃæÎÒÃÇÔÙÓÃÁíÍâÒ»ÖÖ´«Í³µÄ²åÈë·½·¨Í¬ÑùÌí¼Ó5ÐÐÊý¾Ý£¬Ò²¾ÍÊÇʹÓôøSELECT´Ó¾äµÄINSERT SQLÓï¾ä£¬½Å±¾ÈçÏ£º

insert into MyTest2 select 1 , 'John' , 'Smith' , 150000.00 insert into MyTest2 select 2 , 'Hillary' , 'Swank' , 250000.00 insert into MyTest2 select 3 , 'Elisa' , 'Smith' , 120000.00 insert into MyTest2 select 4 , 'Liz' , 'Carleno' , 151000.00 insert into MyTest2 select 5 , 'Tony' , 'Mcnamara' , 150300.00 Ö´Ðнá¹ûÈçÏ£º (1 row(s) affected) (1 row(s) affected) (1 row(s) affected) (1 row(s) affected) (1 row(s) affected) ·½·¨Èý

ͬÑùµÄ£¬ÎÒÃÇÔÙ¼ÙÉèÉÏÊöµÄMyTestDBÊý¾Ý¿âÖÐÓбíMyTest3£¬ÈçÏ£º