Normal Vs Surrogate/artificial Key?
Jun 10, 2008
Hey All,
I'm trying to decide what's the 'best' to use. I've been designing and creating database for a while and have pretty much always used a surrogate key and not a normal one. I've finally had some free time to start studying more so in my spare time and read up and come accross a lot of guides, articles and stories that tout that normal keys should be used whenever possible as they're a better identifier and that surrogate keys should only be used when there is not a readily available normal key. Now perhaps I'd be open to accepting that but absolutely every database I come across tends to only use surrogate keys. For example I'm doing an authentication system from scratch and am looking at the User table. Now of course the user name has to be unique, should that be the primary key or should I have a seperate column with a guid or an incrementing int or the like as the primary key?
I can certainly see that username could be used. I can also see how it may be easier when looking through the data tables to identify who/what a table is refering to with a surrogate key. However it still seems sort of sloppy, for lack of a better word, to me. Where now I could have somebody's username (or any other piece of data used for this purpose) spread accross a lot of other tables. And while writting this I just thought of the scenario that perhaps somebody needs their username changed, with this method now the ids need to be changed on all the related rows of all the other tables whereas with a surrogate key it wouldn't matter.
Anyways I'm mostly looking for opinions on which way to go (not just with the user sample, but more in general).
Thanks.
View 2 Replies
ADVERTISEMENT
Jul 5, 2006
I'm currently running the following statement that is used in a CrystalReport. Basically, a record is returned when the T_PAYMENT.amounthas a record in the database based on the value of the T_MULTILIST.codefield. Currently, if there is no record returned, there is no listingin the report for the given T_MULTILIST.code.The user now wants a record to be displayed on the report when there isno record in the database - she wants it to display a value of '$0'for the given T_MULTILIST.code record. I tried to explain the fact thatis not possible the way things stand at the moment. Basically I needsome typeof case statement that says 'if there is no record returned, create asingle record and set T_PAYMENT.amount = 0' AFTER each query has beenexecuted.Anyone have any idea how to accomplish this?SELECT DISTINCT'English Language Arts, Grade 1' as Rec_Type, 'English Language Arts(Consumable)' as Super_Type, '' as Other_Type, 'Continuing Contracts'as Proc_Type,T_MULTILIST_GRADE.grade, T_MULTILIST.description, T_MULTILIST.code,T_PAYMENT.amountFROM (T_MULTILIST T_MULTILIST INNER JOIN (T_PAYMENT T_PAYMENTINNER JOIN T_SHIPPING_DETAILT_SHIPPING_DETAIL ONT_PAYMENT.transaction_id=T_SHIPPING_DETAIL.transac tion_id)ON T_MULTILIST.code=T_SHIPPING_DETAIL.multilist_code) INNER JOINT_MULTILIST_GRADE T_MULTILIST_GRADE ONT_MULTILIST.code=T_MULTILIST_GRADE.multilist_code, T_ORDER, T_REQUISITION, T_REQUISITION_DETAILWHERET_ORDER.id = T_SHIPPING_DETAIL.order_id ANDT_REQUISITION.id = T_ORDER.requisition_id ANDT_REQUISITION_DETAIL.requisition_id = T_REQUISITION.id ANDT_REQUISITION_DETAIL.latest_record_flag = 1 ANDT_REQUISITION.latest_record_flag = 1 ANDT_ORDER.latest_record_flag = 1AND (T_MULTILIST.code='1040')AND (T_MULTILIST.expiration_year >= '2006' )AND (T_REQUISITION.requested_shipment_date >= '2006' + '0601'AND T_REQUISITION.requested_shipment_date < dateadd(YY, 1,'2006' + '0601' ) )UNIONSELECT DISTINCT'English Language Arts, Kindergarten' as Rec_Type, 'EnglishLanguage Arts (Consumable)' as Super_Type,'' as Other_Type, 'Continuing Contracts' as Proc_Type,T_MULTILIST_GRADE.grade, T_MULTILIST.description,T_MULTILIST.code, T_PAYMENT.amountFROM (T_MULTILIST T_MULTILIST INNER JOIN (T_PAYMENT T_PAYMENTINNER JOIN T_SHIPPING_DETAIL T_SHIPPING_DETAILON T_PAYMENT.transaction_id=T_SHIPPING_DETAIL.transac tion_id)ON T_MULTILIST.code=T_SHIPPING_DETAIL.multilist_code) INNER JOINT_MULTILIST_GRADE T_MULTILIST_GRADE ONT_MULTILIST.code=T_MULTILIST_GRADE.multilist_code, T_ORDER, T_REQUISITION, T_REQUISITION_DETAILWHERET_ORDER.id = T_SHIPPING_DETAIL.order_id ANDT_REQUISITION.id = T_ORDER.requisition_id ANDT_REQUISITION_DETAIL.requisition_id = T_REQUISITION.id ANDT_REQUISITION_DETAIL.latest_record_flag = 1 ANDT_REQUISITION.latest_record_flag = 1 ANDT_ORDER.latest_record_flag = 1AND (T_MULTILIST.code='0040')and (T_MULTILIST.expiration_year >= '2006' )AND (T_REQUISITION.requested_shipment_date >= '2006' + '0601'AND T_REQUISITION.requested_shipment_date < dateadd(YY, 1,'2006' + '0601' ) )Up to 40 more UNION statements follow the above 2.
View 3 Replies
View Related
May 12, 2008
I have a report that requires SubTotals for each page.
To do this successfully, I had to introduce the following grouping:
Code Snippet=Int((RowNumber(Nothing)-1)/5
This groups every 5 records.
Unfortunately, the length of data in my records is not uniform. For example, certain records have long(over 4 lines) comment field while others are short(1 line).
This means that even though I have an artificial grouping, the group may still be split up over two or more pages.
Is there a way to Group records PER PAGE dynamically?
View 5 Replies
View Related
Oct 5, 2006
It's a dream of human beings to build machines that can think andbehave like human beings. The most important part of of such a machineis an artificial mind that can emulate the cognitive processing ofhuman mind.This book, "Next Generation Artificial Intelligence, Artificial Mind -Part One - Basic Architecture and Cognitive Structure" introduces abasic artificial mind architecture and computational model forcognitive processing. Inside the book, three important cognitiveprocess modeling components, mental objects network (MON),associative-learning mechanisms and a concept formation principle areintroduced. Based on the architecture and the computational model, onecan develop his own model of artificial mind according to his ownspecific requirements.The first edition of Artificial Mind - Part One is now available forpurchase from the author's personal web site. The price of the e-bookis USD7.00 (seven US dollars). An evaluation edition of this e-book isalso available for download from the web site.The author's personal web site:http://www.geocities.com/tomwingmak/
View 1 Replies
View Related
Nov 3, 1999
hi!
when i read some reference books about the SQL7.0, i often met 'surrogate key'. what's the surrogate key? what's its funtion? could you give me a good example?
thanks very much!
View 1 Replies
View Related
Sep 19, 2006
Hi gurus
can any one tell me what is the best way to use surrogate key (except uniqueidentifier datatype)? how can I use with TSQL?
View 5 Replies
View Related
Aug 21, 2004
The orininal design of my db (part of it...) is the following
A JOB has a Number and a Description.
Each JOB can have one or two TASKS (min one, max two). Each TASK is identified by the JOB it belongs to and an Index (unique only for the same JOB).
Each TASK has one an only one set of INFO1, one and only one set of INFO2, one and only one set of INFO3 etc.
A: JOB (JobNum [PK], JobDescription, ...)
B: TASK (JobNum [PK] [FKa], Index [PK], TaskDescription, ...)
C: INFO1 (JobNum [PK] [FKb], Index [PK] [FKb], ...)
D: INFO2 (JobNum [PK] [FKb], Index [PK] [FKb], ...)
(There is a reason to keep INFO1, 2 and 3 separate, because eachof them will be linked to different table. This might influence the answer to my real question.)
First of all, I wouldn't add any surrogate key for TASK, not to loose the logic behind; plus I'd put an ined on JonMum only, being Index equal to 1 or 2 only, so not selective.
The real question is about INFO1 (and 2, 3 etc.) table: should I leave JobNum and Index as PK (consider that the PK of INFo1 will be used as FK for another table), or should I use a surrogate key, like for eaxmple
C: INFO1 (Info1ID [PK], JobNum [FKb], Index [FKb], ...)
I don't really like this solution. Actually I'd prefer the following
C: INFO1 (Info1ID [PK], ...)
where Info1ID = JobNum + Index (+ = string concatenation).
Any suggestion?
Thanks
View 3 Replies
View Related
Dec 5, 2007
Hi,
How to create surrogate key in a dimension table?
What transformations can be used to create it?
View 6 Replies
View Related
Jan 16, 2006
Hi, I'm trying to use the SK script from Donald Farmers book but the code isn't accepted
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
Inherits UserComponent
Dim CurrentKey As Integer
Public Overrides Sub PreExecute()
CurrentKey = CInt(Me.Variables.FILCodesSK)
End Sub
Public Overrides Sub Input_ProcessInputRow(ByVal Row As Input0Buffer)
CurrentKey += 1
Row.SurrogateKey = CurrentKey
End Sub
End Class
There is a problem with the use of the overrides on the Input_ProcessInputRow sub should this be renamed?
Cheers, Al
View 1 Replies
View Related
Jan 22, 2001
Hello
I'm looking for a way of generating the next key value that works in MS and Sybase SQL Servers. Sybase identity columns are a bit dodgy, so...
If I have a separate table NextKey (NextKey int) with one row that I update as follows...
declare @NextKey int
update NextKey set NextKey = NextKey + 1, @NextKey = NextKey + 1
insert into myTable (PrimaryKeyCol, ....) values (@NextKey, ....)
are there any problems with concurrency ? As I see it the update will lock the row so different connections will always come up with a different @NextKey value....
Thanks
John
View 2 Replies
View Related
Aug 23, 2004
My previous post was not really clear, so I'll try again with a (hopefully) better (even if longer) example...
Consider the following...
A JOB describes the processment of a document.
Each document can exist in two versions: English and French.
A JOB can have 1 or 2 TASK, each describing the processement of either the English or French version.
So we have the following:
A: JOB (JobNum [PK], DocReference, StartDate, EndDate, ...)
B: TASK (JobNum [PK] [FKa], Version [PK], Priority, ...)
that is there is an identifying 1:M (where maxium allowed for M is 2) relationship between JOB and TASK; TASK being identified by JobNum and Version (where the domain for Version is {E, F}).
Each TASK may require a TRANSLATION sub_task.
Each TASK may require a TYPING sub_task.
Each TASK may require a DISTRIBUTION sub_task.
For example, for a given doc, the English TASK requires TRANSLATION and DISTRIBUTION, while the French only DISTRIBUTION.
That is, there is a 1:1 not-required relationship between TASK and TRANSLATION, TYPING and DISTRIBUTION.
So we have the following:
A: JOB (JobNum [PK], DocReference, StartDate, EndDate, ...)
B: TASK (JobNum [PK] [FKa], Version [PK], Priority, ...)
C: TRANSLATION (JobNum [PK] [FKb], Version [PK] [FKb], DueDate, ...)
D: TYPING (JobNum [PK] [FKb], Version [PK] [FKb], DueDate, ...)
E: DISTRIBUTION (JobNum [PK] [FKb], Version [PK] [FKb], Copies, ...)
As you can see I am using the PK of TASK as FK and PK for each of the three SUB_TASKs.
To complicate things, each SUB_TASK has one or more assignments. The assignments for each SUB_TASK records different information from the others.
So we have...
A: JOB (JobNum [PK], DocReference, StartDate, EndDate, ...)
B: TASK (JobNum [PK] [FKa], Version [PK], Priority, ...)
C: TRANSLATION (JobNum [PK] [FKb], Version [PK] [FKb], DueDate, ...)
D: TYPING (JobNum [PK] [FKb], Version [PK] [FKb], DueDate, ...)
E: DISTRIBUTION (JobNum [PK] [FKb], Version [PK] [FKb], Copies, ...)
F: TRA_ASSIGN (JobNum [PK] [FKc], Version [PK] [FKc], Index [PK], Translator, ...)
G: TYP_ASSIGN (JobNum [PK] [FKd], Version [PK] [FKd], Index [PK], Typyst, ...)
H: REP_ASSIGN (JobNum [PK] [FKe], Version [PK] [FKe], Index [PK], Pages, ...)
that is there is an identifying 1:M relationship between each SUB_TASK and its ASSIGNMENTs, each ASSIGNMENT being identified by the SUB_TASK it belongs to and an Index.
I wish I could send a pic of the ER diagram...
Maybe there is another and better way to model this: if so, any suggestion?
Given this model, should I use for TRANSLATION, TYPING and DISTRIBUTION a surrogate key, instead of using the composite key, like for example:
C: TRANSLATION (TranslationID [PK], JobNum [FKb], Version [FKb], DueDate, ...)
D: TYPING (TypingID [PK], JobNum [FKb], Version [FKb], DueDate, ...)
E: DISTRIBUTION (DistributionID [PK], JobNum [FKb], Version [FKb], Copies, ...)
this will "improve" the ASSIGNMENTs tables:
F: TRA_ASSIGN (TranslationID [PK] [FKc], Index [PK], Translator, ...)
G: TYP_ASSIGN (TypingID [PK] [FKd], Index [PK], Typyst, ...)
H: REP_ASSIGN (DistributionID [PK] [FKe], Index [PK], Pages, ...)
I could even go further using a surrogate key even for TASK, which leads me to the following:
A: JOB (JobNum [PK], DocReference, StartDate, EndDate, ...)
B: TASK (TaskID [PK], JobNum [FKa], Version , Priority, ...)
C: TRANSLATION (TaskID [PK] [FKb], DueDate, ...)
D: TYPING (TaskID [PK] [FKb], DueDate, ...)
E: DISTRIBUTION (TaskID [PK] [FKb], Copies, ...)
F: TRA_ASSIGN (TaskID [PK] [FKc], Index [PK], Translator, ...)
G: TYP_ASSIGN (TaskID [PK] [FKd], Index [PK], Typyst, ...)
H: REP_ASSIGN (TaskID [PK] [FKe], Index [PK], Pages, ...)
I don't really like this second solution, but I'm still not sure about the first solution, the one with the surrogate key only in the SUB_TASks tables.
View 2 Replies
View Related
May 19, 2008
I am performing a Select Into from a #table into a real table that has a surrogate key. If this is in a transaction (or not in one) am I guaranteed that the records inserted will be sequential surrogate key ids?
Select * into REALTABLE from MYPOUNDTABLE --40 rows
Can I assume that if the first one inserted is id 32 that the last one is 72?
View 5 Replies
View Related
Jul 20, 2005
{CREATE TABLEs and INSERTs follow...}Gents,I have a main table that is in ONE-MANY with many other tables. For example, ifthe main table is named A, there are these realtionships:A-->BA-->CA-->DA-->EWith one field in Common (Person). The tables B, C, D and E are History tables,with Start and End dates. Each person has a Program history (table B, ie), anExperience history (table C, ie), and so on...many differernt types ofhistories, and it may grow from here....table F, G, etc.The included CREATE TABLEs and INSERTs contain tables A, B and C.The problem: Each tblCase (table A) record has a date. When joining all of thehistory tables to tblCase on Person, obviously you get a cross-product of eachhistory unless you specify a WHERE clause that extracts one single record fromeach of the histories (duh...that's the point...to extract a single record fromeach history, because there can only be one value in effect at the time of theCase.)QUESTION: From a performance standpoint, would it behoove me to maintain thesurrogate ***HistoryID from each history table in tblCase, or, assuming theindexes are set up properly, would a WHERE condition for each history besufficient? For example, the following select works as expected:SELECT CasePerson, CaseDate, ProCode, ExpYearFROM tblExperienceHistory INNER JOIN (tblCase INNER JOIN tblProgramHistory ONtblCase.CasePerson = tblProgramHistory.ProPerson) ON tblCase.CasePerson =tblExperienceHistory.ExpPersonWHERE CaseDate BETWEEN ProStartDate and ProEndDateAND CaseDate BETWEEN ExpStartDate and ExpEndDateIt extracts the single record from each history for each person for each case.But I'm afraid of performace with such a scenario.Instead, I could store each ***HistoryID in the table tblCase, and then justjoin on that...no WHERE needed. But the trade-off is that I'd have to buildprocesses to maintain that. ("Hey, when you insert a record into tblCase, makesure to go get each HistoryID from the History tables!" or "If the user changesthe date ranges in one of histories, make sure to update tblCase to match thenew historyID!")Maybe a clustered index on each ***History table on Person/StartDate combinedwith the WHERE clause should perform as well as a real JOIN on surrogateintegers.It seems cheesey to have to resort to surrogate IDs...but the performanceincrease might be worth it. Also, if I go that route, whenever I add a newhistory table, I'd have to change the design of tblCase AND any SPs thatreference it. With the WHERE solution, I'd only have to change the SPs.Comments are welcome! (tblCase grows at 250,000 records per year; the historytables will increase about 1000 records per year)DCMFANCREATE TABLE [dbo].[tblCase] ([CaseID] [char] (5) CONSTRAINT [PK_tblCase] PRIMARY KEY CLUSTERED NOT NULL ,[CaseDate] [smalldatetime] NOT NULL ,[CasePerson] [char] (5) NOT NULL) ON [PRIMARY]GOCREATE TABLE [dbo].[tblExperienceHistory] ([ExperienceHistID] [int] IDENTITY (1, 1) NOT NULL ,[ExpPerson] [char] (5) NOT NULL ,[ExpStartDate] [smalldatetime] NOT NULL ,[ExpEndDate] [smalldatetime] NOT NULL ,[ExpYear] [int] NOT NULL) ON [PRIMARY]GOCREATE TABLE [dbo].[tblProgramHistory] ([ProgramHistID] [int] IDENTITY (1, 1) NOT NULL ,[ProPerson] [char] (5) NOT NULL ,[ProStartDate] [smalldatetime] NOT NULL ,[ProEndDate] [smalldatetime] NOT NULL ,[ProCode] [int] NOT NULL) ON [PRIMARY]GOINSERT INTO [tblCase]([CaseID], [CaseDate], [CasePerson])VALUES('12345', '3/1/03', '00000')INSERT INTO [tblCase]([CaseID], [CaseDate], [CasePerson])VALUES('A1G34', '4/23/03', '00001')INSERT INTO [tblExperienceHistory]([ExpPerson], [ExpStartDate], [ExpEndDate],[ExpYear])VALUES('00000', '1/1/03', '5/19/03', 1)INSERT INTO [tblExperienceHistory]([ExpPerson], [ExpStartDate], [ExpEndDate],[ExpYear])VALUES('00000', '5/20/03', '12/31/03', 2)INSERT INTO [tblExperienceHistory]([ExpPerson], [ExpStartDate], [ExpEndDate],[ExpYear])VALUES('00001', '4/20/03', '11/1/03', 0)INSERT INTO [tblProgramHistory]([ProPerson], [ProStartDate], [ProEndDate],[ProCode])VALUES( '00000', '2/1/03', '9/30/03', '55555')INSERT INTO [tblProgramHistory]([ProPerson], [ProStartDate], [ProEndDate],[ProCode])VALUES( '00000', '10/1/03', '5/1/04', '55555')INSERT INTO [tblProgramHistory]([ProPerson], [ProStartDate], [ProEndDate],[ProCode])VALUES( '00001', '1/1/03', '12/31/03', '55555')
View 4 Replies
View Related
May 19, 2008
I am performing a Select Into from a #table into a real table that has a surrogate key. If this is in a transaction (or not in one) am I guaranteed that the records inserted will be sequential surrogate key ids?
Select * into REALTABLE from MYPOUNDTABLE --40 rows
Can I assume that if the first one inserted is id 32 that the last one is 72?
View 6 Replies
View Related
Jan 23, 2008
I have two tables:
countries(country_id integer, country_name string)
authors(auth_id integer, country_id integer, auth_name string)
...Where "country_id" in the authors table refers to the same country_id in the countries table.
I want a stored procedure to handle the insertion of new rows in the authors table. There are two methods of doing it:
1) CREATE PROCEDURE addAuthor( authorName, countryId )
And
2) CREATE PROCEDURE addAuthor( authorName, countryName )
Now, I like #1 because the implementation is simple -- the calling code simply passes an author name, and a country id and an INSERT INTO statement is called with those parameters
INSERT INTO authors( @authorName, @countryId )
I like #1, because it hides the surrogate "id" key from the application calling code. But on the downside, it has more overhead work, because you have to first a) verify a country with that name exists, and b) select that id into a variable.
DECLARE id INT;
IF EXISTS (select * from countries where country_id = @countryId ) THEN
SELECT country_id INTO id FROM countries WHERE country_name = @countryName;
END IF;
(Sorry I may have the SQL syntax wrong up there, but I was just trying to demonstrate the extra overhead involved).
Which approach do you guys think is better?
View 1 Replies
View Related
May 21, 2008
I am in the process of building a fact table in a staging area. The data in the host system has numerous composite keys, so I have replaced all the composite keys in the dimensions with surrogate keys (integer) which are generated using an identity at load time. When I load the staging (fact) table, I have set the default value of all the foreign keys to 0. What I must do now is update all the foreign key values with the surrogate key values from the dimensions. I'm using an update command and the original gid values from the source system in the where clause...i.e.
UPDATE X
SET x.key_1 = y.key_1
FROM TableA X WITH (NOLOCK)
INNER JOIN TableB Y WITH (NOLOCK)
ON x.org_id = y.org_id
AND x.bus_id = y.bus_id
AND x.prov_gid = y.prov_gid
AND x.log_gid = y.loc_gid;
This seems to work fine for most tables. However, I am now trying to update a table that has over 10 million rows and approximately 30 foreign keys. The script runs for hours. I ususally stop it after about 8 hours when it still hasn't completed. Since the keys are dynamic and they could possibly change during each load process, I can't add them during the load process.
Is there a better way to update these keys. I need to regenerate the fact tables every night and taking this much time to reload a fact table is just not practicle. I've indexed the alternate keys on all the dimensions and have also indexed the gids on the target fact table. Am I doing something wrong? Have I over indexed the target table? Please help! Thanks Jerry
View 1 Replies
View Related
Jul 22, 2007
Hi,
I have a dimension called 'Caller Type' with the following attributes:
CallerTypeKey ---- surrogate key
CallerTypeID
CallerTypeDesc
CreatedByKey ---- foreign surrogate key from User Dimension
I used Script Task to get the last used key and increment it so i can use it for new records in my dimension. however, my dimension is linked to a User Dimension and I need the surrogate key of that once I insert the new record to CallerType Dimension.
How would I do that?
cherriesh
View 3 Replies
View Related
May 2, 2006
This is the code iam using to get the incremental surrogate keys:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
Inherits UserComponent
'Declare a variable scoped to class ScriptMain
Dim counter As Integer
Public Sub New() 'This method gets called only once per execution
'Initialise the variable
counter = 1093
End Sub
'This method gets called for each row in the InputBuffer
Public Overrides Sub Input_ProcessInputRow(ByVal Row As InputBuffer)
'Increment the variable
counter += 1
'Output the value of the variable
Row.instance = counter
End Sub
End Class
--'Instance' is my surrogate feild name
but iam getting an error saying that InputBuffer is not defined ..Any idea?
If I want to add two more incrementive fileds ,where i have to add it?
Sorry if it sounds silly ,iam very new to this scripting.
Thanks
Niru
View 9 Replies
View Related
Jul 18, 2006
I have a database surrogate key that increments so rapidly (+5000 every 30 mins). I need my SSIS package to reset this database surrogate key to avoid reaching an upper limit value for that field.
How can I do that using SSIS package?
thanks,
Aref
View 1 Replies
View Related
Jun 12, 2007
I have several stage to star (i.e. moving data from a staging table through the key lookups into a fact table) ETL transformations in a single SSIS package. Each fact table has a different set of measures but the identical foreign key set, e.g. ConsultantKey, SubsidiaryKey, ContestKey, ContestParamKey and MonthKey.
Currently I have to replicate the key lookup (Surrogate Key Pipeline, or SKP) for each data flow. If I could cache each dimension one time in the package and reuse it for each stage to fact it would be much more efficient.
Is there a way for me to reuse a common data flow?
View 6 Replies
View Related
Oct 2, 2006
I am trying to write a ssis surrogate key data transform, my problem is I can't find an example how to add a column to the incoming columns and add some data to it. If anyone has a sample, can you please post it. I found a script option that works but I would like an actual transform.
Thanks
View 2 Replies
View Related
Jun 3, 2015
I want to change the work table name to work_version2 and later drop the work table. First, I created the table (work_version2) along with the data structure seen below and later inserted data from the work table. As I tried to make workID a surrogate key in work_version2 using SSMS, I got the below error message when I try to save the changes. Is there a way to do this?
Saving changes is not permitted. The changes you have make requires the following tables to be dropped and re-created. You have either make changes to a table that cant't be recreated or enabled the option that prevent saving changes that requires the table to be recreated. Work_version2.
CREATE
TABLE WORK(
WorkID Int NOT
NULL IDENTITY (500,1),
Title Char(35) NOT
NULL,
Copy Char(12) NOT
[Code] ....
View 2 Replies
View Related
Nov 23, 2005
Hi. Sorry if I am asking a stupid question since I am an absolutely beginnerin SQL Server. Here is the question . . .About 13 hours ago, I got my SQL Server 2000 to index a table which has 104million records. At first the CPU usage was high. But after an hour or two,the process has seemed dead and the Enterprise Manager has had no response.The CPU usuage dropped to zero and has been jumping between 0 to 5%. Theharddisk indicator has been blinking at a rate of roughly three times pertwo seconds.Is this normal? Has anyone got any idea how long the process would take? Ihave assigned 1.8GB of RAM to the SQL service and is currently taking upabout 1GB.
View 7 Replies
View Related
Jun 21, 2015
So, I have some questions about best practice in SQL Server.
1.) I have PK like this (company TINYINT, store TINYINT, action TINYINT, invoice INT, sn SMALLINT). I know JOINS will work faster with surrogate key but I have only couple of JOINS on that table. I use members of PK in WHERE clause mainly, alone and combined for reporting purpose. Is it always better to have surrogate key because they don't have any meaning and context of data laying in current PK.
2.) In my PK from above I have two candidates for using Sequence object. Invoice start with 1 for every (company,store,action) combination. Sn start with 1 for every (company,store,action,invoice) combination. I would like to know can I implement Sequence object here knowing that Sequence don't support PARTITION BY in OVER clause. From what I red it cannot be done via Sequence but I have to ask.Here is data sample for this PK
company store action invoice sn
----------- ----------- ----------- ----------- -----------
1 1 1 2017 1
1 1 1 2018 1
1 1 1 2019 1
1 1 1 2019 2
1 1 1 2019 3
1 1 2 1 1
1 1 2 2 1
1 1 2 2 2
1 1 2 2 3
1 1 2 3 1
1 1 2 3 2
1 1 2 3 3
1 1 2 3 4
1 1 2 3 5
View 7 Replies
View Related
Jul 19, 2007
Hi,
I have tables like the one below for my Stage and dimension tables:
Stage Table
accountid
name
address
Dimension Table
accountkey ---- surrogate key (DW key)
accountid ---- business key (transaction's primary key)
name
address
I used slowly changing dimension to detect the changes for the records inside my Dimension table. But I had a problem when a new record exists in the stage table. The accountkey is set as the primary key and it gets its value from a different table which stores the last account key that was created. I cannot load all the changes unless i have a business key. Is there a way that i can get the "last key" from a different table in the data flow area and then supply it together with the other fields in the new output branch of the slowly changing dimension?
cherriesh
thanks!
View 7 Replies
View Related
Apr 30, 2015
I want to create an import table for daily rows with an integer column like 20150430 for the date, called DayKey. This table would do one date per day. It would then be imported into a STAGE table which would have the same columns and would have all of the import rows for every day.My question would be this: I want to be able to have an integer Primary Key unless there is a better idea. I could make the STAGE table use an auto-incremented value for the key. Then, when I load the import table which is truncated every day, I could take the NEXT value of the key from the STAGE table and increment by 1.
Let's say the last value in STAGE is 1000, then the next value that would be in IMPORT would be 1001 and incrementing up. Then these would be added to the STAGE table with the associated keys. There is no chance of anyone or anything else adding to the STAGE table any other way.
View 3 Replies
View Related
Dec 7, 2003
Impossible to connect to my mssql 2000 database
web.config connexion string >>>
<add key="DataSourceSql" value="Initial Catalog=angiras;Data Source=localhost;Uid=sa;Pwd=;" />
or
<add key="DataSourceSql" value="Initial Catalog=angiras;Data Source=localhost;" />
connexion code >>>
Private ConnexionSQL As SqlConnection
Public Sub OpenConnexionSQL()
ConnexionSQL = New SqlConnection(ConfigurationSettings.AppSettings("DataSourceSql").ToString)
ConnexionSQL.Open()
End Sub
when I try >>>
OpenConnexionSQL
I get an error
any idea ?
thank you
View 1 Replies
View Related
Feb 1, 2008
Hi guys, I've been thinking about this problem now for some time but somehow I don't know if my "solution" for it is right. I'd like to read your opinion.
There is a Capital table with Capital_Nr, Capital_Name, Capital_Population, Country_Nr and Country_Name as attributes.
I know the table is chaotic so I brought it to 3NF :
Capital table : Capital_Nr, Capital_Name, Capital_Population, Country_Nr(foreign key)
Country table : Country_Nr and Country_Name
Ok so I guess the table should be now in 3NF, but what intrigues me is in what NF the table originally was. I tried then to use Codd's definition of 2NF : "a 1NF table is in 2NF if and only if none of its non-prime attributes are functionally dependent on a part (proper subset) of a candidate key". In my opinion the original candidate keys could only be {Capital_Nr},{Country_Nr} and {Country_Name}, each one of them single, i.e. separate from each other. So, as there is no composite candidate key, I can affirm that the original table was in 2NF. Am I right ?
Thanks !
View 3 Replies
View Related
Apr 15, 2008
I am wondering what normal disk I/O should be.
i know it verys depending on use but im looking for an average.
here is an idea of what we have
there is about 10 centers doing replication to our primary server.
we have about 80 users connecting directoy to our primary server using MS Dynamics through CITRIX.
we have a few other apps use the database as well however i am fairly certin its Dynamics generating our disk IO
Hardware wise we have a powerful blade connected to a raid 5 SAN with 15000 rpm disks.
normaly the disk IO stays fairly low but every so often it goes crazy and im thinking it shouldn't
Below is a sample of our disk IO from perfmon over 2 minutes or so. as you can see everything looks ok untill 04/15/2008 10:12:49.470 when the Disk I/O % goes above 100%
"04/15/2008 10:12:23.470","2.8300181121159178"
"04/15/2008 10:12:24.470","0"
"04/15/2008 10:12:25.470","3.950025280161793"
"04/15/2008 10:12:26.470","0"
"04/15/2008 10:12:27.470","0"
"04/15/2008 10:12:28.470","5.9800382722449426"
"04/15/2008 10:12:29.470","7.7400495363170325"
"04/15/2008 10:12:30.470","3.4500220801413128"
"04/15/2008 10:12:31.470","0"
"04/15/2008 10:12:32.470","4.180026752171214"
"04/15/2008 10:12:33.470","3.8600247041581071"
"04/15/2008 10:12:34.470","0"
"04/15/2008 10:12:35.470","142.71091334984544"
"04/15/2008 10:12:36.470","0"
"04/15/2008 10:12:37.470","1.1500073600471041"
"04/15/2008 10:12:38.470","0.81000518403317789"
"04/15/2008 10:12:39.470","0"
"04/15/2008 10:12:40.470","2.1400136960876548"
"04/15/2008 10:12:41.470","10.230065472419025"
"04/15/2008 10:12:42.470","4.5800293121875981"
"04/15/2008 10:12:43.470","0"
"04/15/2008 10:12:44.470","0"
"04/15/2008 10:12:45.470","14.500092800593926"
"04/15/2008 10:12:46.470","6.730043072275663"
"04/15/2008 10:12:47.470","1.6300104320667652"
"04/15/2008 10:12:48.470","7.3500470403010585"
"04/15/2008 10:12:49.470","264.66169383484055"
"04/15/2008 10:12:50.470","324.18207476527851"
"04/15/2008 10:12:51.470","536.17343150996169"
"04/15/2008 10:12:52.470","270.31172999507197"
"04/15/2008 10:12:53.470","331.97212462159757"
"04/15/2008 10:12:54.470","333.84213658967417"
"04/15/2008 10:12:55.470","435.57278766584108"
"04/15/2008 10:12:56.470","442.31283080211716"
"04/15/2008 10:12:57.470","685.92438991609549"
"04/15/2008 10:12:58.470","295.1618890360898"
"04/15/2008 10:12:59.470","61.470393410517829"
"04/15/2008 10:13:00.470","56.360360706308519"
"04/15/2008 10:13:01.470","45.260289665853861"
"04/15/2008 10:13:02.470","224.58143732119885"
"04/15/2008 10:13:03.470","1022.0365410338626"
"04/15/2008 10:13:04.470","1114.6271336136551"
"04/15/2008 10:13:05.470","241.52154573789269"
"04/15/2008 10:13:06.470","506.79324347675828"
"04/15/2008 10:13:07.470","374.88239924735518"
"04/15/2008 10:13:08.470","359.5723012627281"
"04/15/2008 10:13:09.485","427.62119831413077"
"04/15/2008 10:13:10.485","400.15256097639025"
"04/15/2008 10:13:11.485","1076.2868882360847"
"04/15/2008 10:13:12.485","325.94208602935055"
"04/15/2008 10:13:13.485","449.36287592240592"
"04/15/2008 10:13:14.485","344.28220340610181"
"04/15/2008 10:13:15.485","569.57364527132972"
"04/15/2008 10:13:16.485","775.02496015974498"
"04/15/2008 10:13:17.485","729.54466908588222"
"04/15/2008 10:13:18.485","778.70498371189581"
"04/15/2008 10:13:19.485","1080.1269128122422"
"04/15/2008 10:13:20.485","754.56482921490704"
"04/15/2008 10:13:21.485","999.11639434492372"
"04/15/2008 10:13:22.485","701.36448873272786"
"04/15/2008 10:13:23.485","276.26176807531567"
"04/15/2008 10:13:24.485","252.13161364232732"
"04/15/2008 10:13:25.485","533.27341294984296"
"04/15/2008 10:13:26.485","759.54486108711092"
"04/15/2008 10:13:27.485","817.11522953746908"
"04/15/2008 10:13:28.485","129.41082822930068"
"04/15/2008 10:13:29.485","158.94101722251023"
"04/15/2008 10:13:30.485","160.55102752657618"
"04/15/2008 10:13:31.485","655.87419759486454"
"04/15/2008 10:13:32.485","444.49284475420637"
"04/15/2008 10:13:33.485","272.47174381916045"
"04/15/2008 10:13:34.485","94.730606275880163"
"04/15/2008 10:13:35.485","355.28227380655238"
"04/15/2008 10:13:36.485","898.29574909279427"
"04/15/2008 10:13:37.485","1309.3783800216322"
"04/15/2008 10:13:38.485","88.200564483612695"
"04/15/2008 10:13:39.485","1.2300078720503811"
"04/15/2008 10:13:40.485","4.9400316162023437"
"04/15/2008 10:13:41.485","217.90139456892524"
"04/15/2008 10:13:42.485","373.26238887928884"
"04/15/2008 10:13:43.485","73.760472067021226"
"04/15/2008 10:13:44.485","1.4100090240577541"
"04/15/2008 10:13:45.485","34.960223745431975"
"04/15/2008 10:13:46.485","15.990102336654955"
"04/15/2008 10:13:47.485","63.580406914604247"
"04/15/2008 10:13:48.485","26.560169985087906"
"04/15/2008 10:13:49.485","11.150071360456707"
"04/15/2008 10:13:50.485","15.250097600624644"
"04/15/2008 10:13:51.485","17.010108864696736"
"04/15/2008 10:13:52.485","12.210078144500125"
"04/15/2008 10:13:53.485","95.650612163917842"
"04/15/2008 10:13:54.485","38.740247937586801"
"04/15/2008 10:13:55.485","5.6000358402293777"
"04/15/2008 10:13:56.485","1.6600106240679942"
"04/15/2008 10:13:57.485","19.590125376802412"
"04/15/2008 10:13:58.485","2.8100179841150981"
"04/15/2008 10:13:59.485","631.48404149786563"
"04/15/2008 10:14:00.485","579.14370651972172"
"04/15/2008 10:14:01.485","1.0600067840434177"
"04/15/2008 10:14:02.485","15.870101568650039"
"04/15/2008 10:14:03.485","112.28071859659903"
"04/15/2008 10:14:04.485","15.660100224641438"
"04/15/2008 10:14:05.485","4.9800318722039822"
"04/15/2008 10:14:06.485","25.44016281704203"
"04/15/2008 10:14:07.485","16.130103232660691"
"04/15/2008 10:14:08.485","5.9300379522428939"
"04/15/2008 10:14:09.485","4.8400309761982481"
"04/15/2008 10:14:10.485","2.6400168961081349"
"04/15/2008 10:14:11.485","19.430124352795858"
"04/15/2008 10:14:12.485","42.55027232174286"
"04/15/2008 10:14:13.485","37.550240321538055"
"04/15/2008 10:14:14.485","1.210007744049562"
"04/15/2008 10:14:15.485","15.930101952652498"
"04/15/2008 10:14:16.485","20.550131520841735"
"04/15/2008 10:14:17.485","4.0900261761675267"
"04/15/2008 10:14:18.485","8.0100512643280908"
"04/15/2008 10:14:19.485","1.6000102400655365"
"04/15/2008 10:14:20.485","2.3300149120954372"
"04/15/2008 10:14:21.485","1.6200103680663558"
"04/15/2008 10:14:22.485","10.730068672439504"
"04/15/2008 10:14:23.485","4.4600285441826832"
"04/15/2008 10:14:24.485","9.0300577923698704"
"04/15/2008 10:14:25.485","0"
"04/15/2008 10:14:26.485","15.550099520636932"
"04/15/2008 10:14:27.485","2.970019008121652"
"04/15/2008 10:14:28.485","64.580413314645213"
"04/15/2008 10:14:29.485","71.850459842942996"
"04/15/2008 10:14:30.485","53.220340610179903"
"04/15/2008 10:14:31.485","32.620208769336124"
"04/15/2008 10:14:32.485","1.0000064000409603"
"04/15/2008 10:14:33.485","4.8400309761982481"
"04/15/2008 10:14:34.485","8.2700529283387425"
"04/15/2008 10:14:35.485","11.160071424457115"
View 1 Replies
View Related
May 9, 2001
Hi all,
I've been running a long query which takes almost 39 seconds in Query Analyzer. After creating a Stored Procedure (with the same query) I expected to run it faster bcoz I heared that SP has a cache, and its a faster technique. But I didnt gain any performance improvments.
Can somebody clear my confusion, what I'm doing wrong.
Thanks!
View 1 Replies
View Related
Jan 12, 2000
We have a payroll database that needs to be backed up just before completing the payroll for that period. I need to create a batch file that a normal user can run that will tell the database to back up and then tell the user when it is done so they can continue working. Is there an easy way to do this without giving the users special permissions? I don't want to give them backup op status. Any help would be appreciated.
View 4 Replies
View Related
Jun 19, 2000
I will be taking over a database that has almost no pk's or relations(this is not my choice, but a vendors)
Management is looking at stored procs to improve performance, but I am wondering
if the db is in this state will there really be a gain. I am pushing for normalization
first, but if anybody has any ideas or opinions I would appreciate
View 2 Replies
View Related
Jul 20, 2007
hi friends the below query is actually what type of join whether inner join or normal query..?????
if not exists(select 'x'
from cobi_invoice_hdr h(nolock),
fin_quick_code_met q(nolock) ,
ci_adjustment_drdoc_vw z (nolock)
where h.tran_ou = @ctxt_ouinstance
and h.invoce_cat = @category_tmp
and d.so_no between @sonumberfrom and @sonumberto
and isnull(h.tran_amount,0) between @totalinvoiceamountfrom and @totalinvoiceamountto
and h.tran_date between convert(varchar(10),@invoicedatefrom,120)and convert(varchar(10),@fininvoicedateto,120)
and h.tran_no between @invoicenumberfrom and @invoicenumberto
and h.bill_to_cust between @billtocodefrom and @customerto
and h.fb_id = isnull(@fb,h.fb_id)
and h.tran_currency = isnull(@currency,h.tran_currency)
and h.createdby = isnull(@useridentity,h.createdby)
and EXISTS (select '*' from cobi_cust_custinfo_vw c(nolock)
where h.bill_to_cust = c.custcode
andc.ouid = @ou_tmp )
and z.status = q.parameter_text
and q.parameter_type = 'STATUS'
and q.parameter_category = 'STATUS'
and q.component_id = 'COBI'
and q.parameter_code = @status_tmp
and h.tran_no = z.documentno
and q.language_id = @ctxt_language
and z.language_id = @ctxt_language)
begin
'No matching invoices found.'
select @m_errorid = 514 -- Porselvi.J - COBIDMS412AT_000255
return
end
End
View 2 Replies
View Related