Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table with_id (
- id int identity(1,1),
- val varchar(30)
- );
- select * into copy_from_with_id_1 from with_id;
- select id, val into copy_from_with_id_2 from with_id;
- create table without_id (
- id int,
- val varchar(30)
- );
- select id, val
- into copy_from_with_id_2
- from with_id
- union all
- select 0, 'test_row'
- where 1 = 0;
- select * into without_id from with_id where 1 = 0
- union all
- select * from with_id where 1 = 0
- ;
- insert into without_id select * from with_id;
- select * into without_id from with_id
- union all
- select * from with_id where 1 = 0
- ;
- SELECT
- t.*
- INTO
- dbo.NewTable
- FROM
- dbo.TableWithIdentity AS t
- LEFT JOIN dbo.TableWithIdentity ON 1 = 0
- ;
- SELECT isnull(Tablename_old.IDENTITYCOL + 0, -1) AS 'New Identity Column'
- INTO dbo.TableName_new
- FROM dbo.TableName_old
- SELECT *
- INTO without_id
- FROM [linked_server].[source_db].dbo.[with_id];
- DECLARE @LocalServer SYSNAME
- SET @LocalServer = @@SERVERNAME;
- EXEC master.dbo.sp_addlinkedserver @server = N'localserver'
- , @srvproduct = ''
- , @provider = 'SQLNCLI'
- , @datasrc = @LocalServer;
- EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'localserver'
- , @useself = N'True'
- , @locallogin = NULL
- , @rmtuser = NULL
- , @rmtpassword = NULL;
- SELECT *
- INTO without_id
- FROM [localserver].[source_db].dbo.[with_id];
- EXEC sp_dropserver @server = 'localserver'
- , @droplogins = 'droplogins';
- SELECT *
- INTO without_id
- FROM OPENQUERY([linked_server], 'SELECT * FROM [source_db].dbo.[with_id]');
- select a.* into without_id from with_id a inner join with_id b on 1 = 0;
- insert into without_id select * from with_id;
- --temp table has IDENTITY
- select ID, Name
- into #t
- from dbo.Employee
- --no IDENTITY
- select ID = ID + 0, Name
- into #t
- from dbo.Employee
Add Comment
Please, Sign In to add comment