1.复制表(包括数据):
select * into vote.joinvotebak20100628 from vote.JoinVote
2.只复制表结构(不复制数据)
select * into vote.joinvotebak20100630 from vote.JoinVote where 1<>1
3.复制指定数据到另一张表中
declare @startdate varchar(12)
set @startdate = '05/07/2008'
insert into dbo.smsLog(pingcoid,mobile,[content],createtime)
select pingcoid,mobileId,'默认的数据',getdate() from pingco.dbo.TmobileInfo where convert(varchar(12), registerdate ,101) =@startdate
两个服务器导数据:
select * from wushuSVR.dudu837db.dbo.[CMS_WebConfig] --远程
exec sp_addlinkedserver 'wushuSVR', '', 'SQLOLEDB', '113.11.*.*'
exec sp_addlinkedsrvlogin 'wushuSVR', 'false',null, 'dudu', 'dudu837'
--[CMS_WebConfig]
insert into wushuSVR.dudu837db.dbo.[CMS_WebConfig](webtitle,keyword,copyright,memo,extended)
select webtitle,keyword,copyright,memo,extended from cmsdata.[dbo].[CMS_WebConfig]
4.表:
declare @table table(id int identity(1,1),tid int) --创建表变量
select * from @table
create table #table (id int identity(1,1),tid int) --创建临时表
select * from #table
drop table #table --删除临时表
5.增加字段
alter table docdsp add dspcode char(200)
删除字段
ALTER TABLE table_NAME DROP COLUMN column_NAME
修改字段类型
ALTER TABLE table_name ALTER COLUMN column_name new_data_type