Tag Info

New answers tagged

1

From a purely performance standpoint, using the identity key as a clustered primary key will be most efficient. From there I would do a non clustered key with a unique constraint on datetime, patientid.


0

Consider the [Date] or [Created] column for a clustered, non-unique, index key (especially if they are increasing columns) and keep the [TypeID] column as a non-clustered, unique, key. Clustered index keys don't have to be unique - SQL Server will add a uniquifier to non-unique values. As long as most of the values are distinct, this shouldn't noticably ...


0

Although I don't work in Azure I would certainly suggest, for SQL Server to use a sequentially, incrementing key like newsequentialid but since you say that Azure doesn't support it... following Kimberly Tripp's advice on http://www.sqlskills.com/blogs/kimberly/guids-as-primary-keys-andor-the-clustering-key/ The identity seems to be the better choice to ...


1

Taken from the MSDN article on FOREIGN KEY Constraints A FOREIGN KEY constraint does not have to be linked only to a PRIMARY KEY constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table. I think it is perfectly fine to define a UNIQUE CLUSTERED INDEX on an IDENTITY column and define the ...


0

Yes, I would add a surrogate 4-byte integer key. Your current two columns are 100 bytes, this could then be reduced to 58 bytes by the addition of the new identity column. You could even make the surrogate key a 2-byte smallint if you are sure you will never exceed 32,767 categories (might be still a good idea to leave as INT just in case). The space ...


0

VARCHAR column as Primary Key is not a good choice as normally we create Cluster Index on same column. Cluster Index on VARCHAR columns is a bad choice because of expected high fragmentation rate. Every new inserted key value will try to find its place somewhere between existing keys and normally cause page split and high index fragmentation. As a result ...


0

I think the comment in your linked question is referring to the idea that you could be using natural keys instead of generated keys for everything. But I don't think your use of generated keys in this instance is unwarranted; you want a single unique key that can reference a single row of data. I do have a question about your choice UUID's, though. They ...


4

The id antipattern is having a unique ID column in each table without requiring (or often discouraging) the application of alternate unique keys. The ID is generated for each new record. Why is this an antipattern? Numeric surrogate keys are fine, including when they are singleton primary keys. However, every time I have seen a schema in which EVERY ...


3

Doing a insert .. select max() ... is a bad idea to begin with as it doesn't work correctly in a multi user environment. Plus it would get the sequence behind the serial column out of sync with the already generated values. What you are looking for is: insert into bar (bar_id) values (default); Another option would be explicitly call nextval() when ...


1

I ended up here with very same error, which was occuring rarely, and was hard to track, because I was loking for it not where I should. Fault was JS repetition which was doing the POST to the server twice! So sometimes it is worth to have a look not only on your django (or any other web framework) views and forms but also what happens on very front side.


3

Because the value is incremented outside the scope of the transaction. This is the way you want it to work, so that separate transactions can happily insert rows or roll back without waiting for each other. If you care about gaps or want different behavior, stop using the built in and roll your own...


1

Short version: CREATE TABLE Relation ( stu_id INT NOT NULL REFERENCES Student, par_id INT NOT NULL REFERENCES Parent, PRIMARY KEY (stu_id, par_id) ) ; Long version: Why use short forms for names, like stu_id and par_id? Why not student_id? Saving typing 3-4 characters? How will you differentiate between parent_id and parameter_id? Or school_id and ...



Top 50 recent answers are included