Loading

复制表结构

sql server中

Code

若想同时拷贝某些数据,则只要在where子句中写上对应的条件即可。

 

----------

以下内容来自联机丛书

Creating tables with SELECT INTO

The following first example creates a temporary table named #Bicycles in tempdb. To use this table, always refer to it with the exact name that is shown. This includes the number sign (#).

Copy Code
USE AdventureWorks ;
            GO
            DROP TABLE #Bicycles ;
            GO
            SET NOCOUNT ON
            SELECT *
            INTO #Bicycles
            FROM Production.Product
            WHERE ProductNumber LIKE 'BK%'
            SET NOCOUNT OFF
            SELECT name
            FROM tempdb..sysobjects
            WHERE name LIKE '#Bicycles%' ;
            GO

Here is the result set. 

Copy Code
name
            ------------------------------
            #Bicycles_____________________

This second example creates the permanent table NewProducts.

Copy Code
USE AdventureWorks ;
            GO
            IF OBJECT_ID ('dbo.NewProducts', 'U') IS NOT NULL
            DROP TABLE dbo.NewProducts ;
            GO
            ALTER DATABASE AdventureWorks SET RECOVERY BULK_LOGGED ;
            GO
            SELECT * INTO dbo.NewProducts
            FROM Production.Product
            WHERE ListPrice > $25
            AND ListPrice < $100
            SELECT name
            FROM sysobjects
            WHERE name LIKE 'New%'
            USE master ;
            GO
            ALTER DATABASE AdventureWorks SET RECOVERY FULL ;
            GO

Here is the result set. 

Copy Code
name
            ------------------------------
            NewProducts
            (1 row(s) affected)
posted @ 2008-12-04 10:36  .net's  阅读(542)  评论(0)    收藏  举报