Click here to Skip to main content
15,899,474 members
Home / Discussions / Database
   

Database

 
GeneralRe: How to check for a never populated table on sql server 2005 Pin
Roberto Mazzone3-Aug-09 21:25
Roberto Mazzone3-Aug-09 21:25 
AnswerRe: How to check for a never populated table on sql server 2005 Pin
David Skelly3-Aug-09 22:43
David Skelly3-Aug-09 22:43 
GeneralBuild your own identity value Pin
David Mujica4-Aug-09 2:58
David Mujica4-Aug-09 2:58 
GeneralRe: Build your own identity value [modified] Pin
Roberto Mazzone4-Aug-09 22:48
Roberto Mazzone4-Aug-09 22:48 
GeneralRe: Build your own identity value Pin
David Mujica5-Aug-09 2:59
David Mujica5-Aug-09 2:59 
GeneralRe: Build your own identity value Pin
Roberto Mazzone5-Aug-09 22:11
Roberto Mazzone5-Aug-09 22:11 
AnswerRe: How to check for a never populated table on sql server 2005 Pin
Mike Ellison4-Aug-09 3:13
Mike Ellison4-Aug-09 3:13 
GeneralRe: How to check for a never populated table on sql server 2005 [modified] Pin
Roberto Mazzone4-Aug-09 22:51
Roberto Mazzone4-Aug-09 22:51 
Mike, anyway i'm an sql script beginner.

I know that about IDENT_CURRENT Microsoft report "Be cautious about using IDENT_CURRENT to predict the next generated identity value. The actual generated value may be different from IDENT_CURRENT plus IDENTITY_INCR
because of insertions performed by other sessions."

The job I have to do is to move rows from DB_SRC to DB_DST having the same schema.
DB_DST can be empty or not.

----------------------------
TAB. tA
----------------------------
a_id int identity not null,
b_id int not null
----------------------------
alter table tA
add constraint tB_tA_FK1 foreign key (b_id)
	 references tB (b_id)

----------------------------
TAB. tB
----------------------------
b_id int identity not null
----------------------------

this was my first implementation...
USE [DB_SRC]

CREATE TABLE #corr_id
(
   b_id_src  INT NULL,
   b_id_dst  INT NULL
}

DECLARE @IdNext AS INT
SET @IdNext = IDENT_CURRENT('[DB_DST].dbo.tB')

-- Set the correspondence
INSERT INTO #corr_id (b_id_src, b_id_dst)
	SELECT 	b_id, ROW_NUMBER() OVER (order by b_id) + @IdNext 
		FROM tB WHERE b_id IN .....code depending on user choise

-- Use the correspondence
INSERT INTO [DB_DST].dbo.tA
	SELECT	#corr_id.b_id_src FROM tA INNER JOIN #corr_id ON tA.b_id = #corr_id.b_id_src

but the IDENT_CURRENT bug (explained in previous post) occured and than...
USE [DB_DST]
ALTER TABLE tB	ADD id_src INT NULL
GO

USE [DB_SRC]

-- Set the correspondence
INSERT INTO [DB_DST].dbo.tB (id_src)
	SELECT	b_id FROM tB WHERE b_id IN .....code depending on user choise

-- Use the correspondence
INSERT INTO [DB_DST].dbo.tA
	SELECT	tBDST.b_id FROM tA INNER JOIN [DB_DST].dbo.tB AS tBDST 
			ON tA.b_id = tBDST.id_src

USE [DB_DST]
ALTER TABLE tB	DROP COLUMN id_src
GO

BTW, turning back to the post object, is there a built-in function or sp to know if a table was never populated?

modified on Wednesday, August 5, 2009 8:36 AM

GeneralRe: How to check for a never populated table on sql server 2005 Pin
Mike Ellison5-Aug-09 6:28
Mike Ellison5-Aug-09 6:28 
GeneralRe: How to check for a never populated table on sql server 2005 Pin
Roberto Mazzone5-Aug-09 22:08
Roberto Mazzone5-Aug-09 22:08 
QuestionNDoc to SQL scripts? Pin
devvvy3-Aug-09 5:43
devvvy3-Aug-09 5:43 
AnswerRe: NDoc to SQL scripts? Pin
leckey3-Aug-09 8:51
leckey3-Aug-09 8:51 
GeneralRe: NDoc to SQL scripts? Pin
devvvy3-Aug-09 14:51
devvvy3-Aug-09 14:51 
QuestionStored Procedure Pl/SQL Pin
Civic063-Aug-09 4:35
Civic063-Aug-09 4:35 
AnswerRe: Stored Procedure Pl/SQL Pin
Vimalsoft(Pty) Ltd3-Aug-09 4:47
professionalVimalsoft(Pty) Ltd3-Aug-09 4:47 
GeneralRe: Stored Procedure Pl/SQL Pin
Civic063-Aug-09 4:59
Civic063-Aug-09 4:59 
GeneralRe: Stored Procedure Pl/SQL Pin
Vimalsoft(Pty) Ltd3-Aug-09 5:06
professionalVimalsoft(Pty) Ltd3-Aug-09 5:06 
GeneralRe: Stored Procedure Pl/SQL Pin
Civic063-Aug-09 5:33
Civic063-Aug-09 5:33 
AnswerRe: Stored Procedure Pl/SQL Pin
David Skelly3-Aug-09 6:09
David Skelly3-Aug-09 6:09 
QuestionError in Stored Procedure. Pin
Satish - Developer3-Aug-09 3:29
Satish - Developer3-Aug-09 3:29 
AnswerRe: Error in Stored Procedure. Pin
Vimalsoft(Pty) Ltd3-Aug-09 4:38
professionalVimalsoft(Pty) Ltd3-Aug-09 4:38 
Questiondesigning database tables to store data Pin
uglyeyes2-Aug-09 14:57
uglyeyes2-Aug-09 14:57 
AnswerRe: designing database tables to store data Pin
Henry Minute3-Aug-09 2:09
Henry Minute3-Aug-09 2:09 
QuestionAccessing the file of a T-SQL BACKUP call Pin
Uwe Keim2-Aug-09 5:52
sitebuilderUwe Keim2-Aug-09 5:52 
AnswerRe: Accessing the file of a T-SQL BACKUP call Pin
scottgp2-Aug-09 14:34
professionalscottgp2-Aug-09 14:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.