SQL Select Into语句
SQL Select Into语句
The SELECT INTO Statement
SELECT INTO 语句
The SELECT INTO statement is most often used to create backup copies of tables or for archiving records.
SELECT INTO语句常用来给数据表建立备份或是历史档案。
Syntax
语法
SELECT column_name(s) INTO newtable [IN externaldatabase] from source
Make a Backup Copy
制作一个备份
The following example makes a backup copy of the "Persons" table:
下面的例子中会为"Persons"表制作一个备份
SELECT * INTO Persons_backupfrom Persons
The IN clause can be used to copy tables into another database:
IN子句可以用来将多个数据表拷贝到另一个数据库上:
SELECT Persons.* INTO Persons IN 'Backup.mdb'from Persons
If you only want to copy a few fields, you can do so by listing them after the SELECT statement:
如果你仅仅想拷贝其中的一部分,可以在SELECT后面列举出它们:
SELECT LastName,FirstName INTO Persons_backupfrom Persons
You can also add a WHERE clause. The following example creates a "Persons_backup" table with two columns (FirstName and LastName) by extracting the persons who lives in "Sandnes" from the "Persons" table:
你还可以加上WHERE子句。在下面的举例中会建立一个"Persons_backup"表,里面包含了在"Persons"表中住在"Sandnes"的个人姓(LastName)与名(FirstName)信息。
SELECT LastName,Firstname INTO Persons_backupfrom PersonsWHERE City='Sandnes'
Selecting data from more than one table is also possible. The following example creates a new table "Empl_Ord_backup" that contains data from the two tables Employees and Orders:
选择多个表进行备份也是可以的。下面的举例就建立了一个新的表"Empl_Ord_backup"里面的数据就有Employees和Orders这两张表的内容:
SELECT Employees.Name,Orders.ProductINTO Empl_Ord_backupfrom EmployeesINNER JOIN OrdersON Employees.Employee_ID=Orders.Employee_ID
相关文档:
1. 可以用脚本备份
manger studio--右键你的数据库--任务--生成脚本
在脚本生成向导的"选择对象类型"步骤中, 将"存储过程"选上, 在接下来的"选择存储过程"的步骤中, 选择所有的存储过程(或者你要复制的存储过程)
完成后, 所有存储过程的脚本会生成在一个新的查询窗口中, 关掉生成脚本向导, 在生成的存储过程 ......
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)
删除表:
Drop table [表 ......
--语 句 功 能
--数据操作
SELECT --从数据库表中检索数据行和列
INSERT --向数据库表添加新数据行
DELETE --从数据库表中删除数据行
UPDATE --更新数据库表中的数据
--数据定义
CREATE TABLE --创建一个数据库表
DROP TABLE --从数据库中删除表
ALTER TABLE --修改数据库表结构
CREATE VIEW --创建一个视图
DRO ......
一、创建一张空表:
Sql="Create TABLE [表名]"
二、创建一张有字段的表:
Sql="Create TABLE [表名]([字段名1] MEMO NOT NULL, [字段名2] MEMO, [字段名3] COUNTER NOT NULL, [字段名4] DATETIME, [字段名5] TEXT(200), [字段名6] TEXT(200))
字段类型:
2 : "SmallInt", // 整型
3 : "Int", ......