Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Auto increment is a no-no?

Name: Anonymous 2010-07-21 13:45

Hello. I must confess that I am rather new at this. During my courses, I was taught to place an auto increment as an id field in my tables, when in need to.

However, recently, I heard someone comment that this is to be completely avoided. But I do not understand why. Perhaps anon could point me in the right direction?

Name: Anonymous 2010-07-21 13:47

Perhaps anon could point me in the right direction?
How about /b/? We don't "anon" here.

Name: Anonymous 2010-07-21 13:49

の_の

Name: Anonymous 2010-07-21 13:49

Cargo cult programming.

Name: Anonymous 2010-07-21 13:49

>>2
Fuck off, ``faggot''.

Name: Anonymous 2010-07-21 13:56

>>4
I know. Thus, I ask. Auto increment gives me an unique id for my rows, but for some reason I do not know this is an incorrect approach.

Why?

Name: Anonymous 2010-07-21 13:57

>>6
Surrogate keys are a symptom of bad design.

Name: Anonymous 2010-07-21 13:58

>>6
We don't know either. Most /prog/lodytes don't really know SQL very well.

Name: Anonymous 2010-07-21 14:01

>>7
Ah, I found an article about it.

Thanks for your help.

Name: Anonymous 2010-07-21 14:01

>>8
MySQL doesn't really have much to do with SQL.

Name: Anonymous 2010-07-21 14:02

>>10
Conversely: SQL doesn't really have much to do with programming.

Name: Anonymous 2010-07-21 14:06

>>11
Surely, you jest! You can't walk one step without having someone need an application with DB access.

Name: >>8 2010-07-21 14:13

>>10,11
No shit. (Warning: suspicious use of specifier 'conversely'.)

>>12
I could circuit the Earth without having someone need an SQL database. 99.98% might think they need one until they see the DBA rates, then they will listen to reason when you offer a better alternative solution. (Example: No one using MySQL needs SQL. If they did, they wouldn't be using MySQL.)

Name: Anonymous 2010-07-21 14:16

>>13
Now listen here, jerkface.

Name: Anonymous 2010-07-21 14:17

>>14
I'm all ears.

Name: Anonymous 2010-07-21 14:44

I'M ALL ANII

Name: Anonymous 2010-07-21 14:44

>>15
Now ear hear, earface.

Name: Anonymous 2010-07-21 14:48

>>17
I'm omnipresent ears.

Name: Anonymous 2010-07-21 15:05

>>13
There's nothing you can do with a DB that you can't do faster with flat files and grep.

Name: Anonymous 2010-07-21 15:09

>>19
Too bad that >>1 doesn't have idea what a grep is and writes SQL queries using a fucking wizard.

Name: Anonymous 2010-07-21 15:41

>>19
I lol'd

Name: Anonymous 2010-07-21 15:45

>>7
Natural keys are elegant solutions only on homework assignments.
In real life the requirements change halfway through the project, and they end up causing you more work while providing no actual benefit.
As a bonus the insertion order is very often useful.

Name: Anonymous 2010-07-21 16:07

>>7
Back to your college SQL class, please.

Name: Anonymous 2010-07-21 16:29

>>7
Surrogate keys are a symptom of bad design.
Really?  Because I can't think of any better solutions for implementing Enterprise-grade applications such as Shiichan, MOTHERFUCKER.

Name: Anonymous 2010-07-21 16:59

>>22-24
To tell the truth, I don't know shit about database design. I'm surprised that my answer was apparently helpful.

Name: Anonymous 2010-07-21 17:01

I haven't heard of auto increment being bad design.

In general, if someone tells you not to do something without being able to explain why, you should treat their input with a whole lot of skepticism.

Name: Anonymous 2010-07-21 18:20

Auto increment is a no-no because there is a better alternative: sequences.
MySQL implements auto increment.

Use a better database.

Name: Anonymous 2010-07-21 18:37

>>27
Like Berkeley DB.

Name: Anonymous 2010-07-21 19:24

At work we had a very difficult time because the databases were modelled in an elegant relational way. Basically, the primary key to our most important table lost its semantical value (due to unpredictable circumstances). We had millions of records. Changing it was nearly impossible. We had to add an extra column and change the way hundreds of applications worked.

There's something SQL people have a hard time to understand: data changes.

Fuck you, data modelling faggots.

Name: Anonymous 2010-07-21 19:33

>>29
I've only worked on a few databases, but each one gave me the impression that the best primary key is a semantically empty primary key. When you've got to maintain this database for over 10 years, three managers, two application changes, etc., every single decision you make wrt semantics will be invalidated eventually.

Name: Anonymous 2010-07-21 19:45

>>30
Indeed. If only DBAs were aware of that.

Name: Anonymous 2010-07-21 19:53

As I said: flat files and grep.

Name: Anonymous 2010-07-21 20:18

>>32
What's the matter, afraid to learn awk?

Name: Anonymous 2010-07-21 20:25

>>33
I'm going easy on the nubs, gimme a break. Besides I kinda like the grep -P ...

Name: Anonymous 2010-07-21 20:46

>>34
Doing awk things with grep -P. Shouldn't you be using Perl?

Name: Anonymous 2010-07-21 20:49

ut ut ut no one says the "p" word !!
(usually i do)

Name: Anonymous 2010-07-21 20:51

You've already stunk up the place with your flat files. You might as well come all the way out of the closet.

Name: Anonymous 2010-07-21 21:00

>>37
In 12 years of doing what ever it is they pay me for I've noticed that people try to stuff everything into a DB even when it clearly violates the K.I.S.S. principle.

DBs are overly complex and generally a cluster fuck to implement and maintain.

Like the old saying if all you have is a hammer (DB in this case) the whole world looks like a nail.

Mind you there are perfectly valid implementations, like myspace and facebook's over 9000 million users, but unless you there is no possible other solution a DB is major overkill.

Name: Anonymous 2010-07-21 21:03

>>38
K.I.S.S. MY ASS

Name: Anonymous 2010-07-21 21:04

>>39
TROLL MY ANUS

Name: Anonymous 2010-07-21 21:18

there are perfectly valid implementations . . . but unless you there is no possible other solution a DB is major overkill.
but unless you there is no other solution

OH GOD WHAT'S THE ANSWER

Name: Anonymous 2010-07-21 22:44

%DEAR Anonymous:  I hope this program helps you better understand your quandry.  I programmed it myself, and hope you enjoy using it.  I can personally explain any questions you have with it.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
home;
 
% Input Nodal Coordinates

NODES = [

    [0.0 0.0]
    [0.5 0.0]
    [1.0 0.0]
    [0.0 0.5]
    [0.7 0.7]
    [1.0 0.5]
    [0.0 1.0]
    [0.5 1.0]
    [1.0 1.0]];

YM = 29000;
PR = 0.3;
thick = 0.1;

ELEMS = [

    [1 2 5 4 YM PR thick]
    [2 3 6 5 YM PR thick]
    [4 5 8 7 YM PR thick]
    [5 6 9 8 YM PR thick]];

%TRACS = [
 %   [3 6 1 0]
%    [6 9 1 0];

%1 for x-direction, 0 for the y direction
%[nnumber direction value]

PLOADS = [
    [3 1 0.025]
    [6 1 .05]
    [9 1 0.025]];

%1 for x-direction, 0 for the y direction
%[nnumber direction value]

DBCS = [
    [1 1 0]
    [1 0 0]
    [2 0 0 ]
[3 0 0]
[4 1 0]
[7 1 0]];

% Define number of nodes & number of elements

nnodes = length(NODES(:,1));

nelems = length(ELEMS(:,1));

 

% Assemble the global stiffness matrix

KG = zeros(2*nnodes,2*nnodes);

 

% Define the integration points

npts = 2;

gpts = [-1/sqrt(3) 1/sqrt(3)];

gwts = [1 1];

 

AREA = 0;

IX   = 0;

IY   = 0;

   

for ielem = 1:nelems

   

    % Get the nodes for this element

    ns = ELEMS(ielem,1:4);

   

    % Get the x and y coordinates of the element nodes

    xs = NODES(ns,1);

    ys = NODES(ns,2);

   

    % Compute the element stiffness matrix

    KE = zeros(8,8);

    earea = 0;

   

    for ig = 1:npts

       for jg = 1:npts

           xci = gpts(ig);

           eta = gpts(jg);

          

           % Compute shape functions & derivatives

           N(1)  = (1-xci)*(1-eta)/4;

           Nx(1) = -(1-eta)/4;

           Ne(1) = -(1-xci)/4;

          

           N(2) = (1+xci)*(1-eta)/4;

           Nx(2) =  (1-eta)/4;

           Ne(2) = -(1+xci)/4;

          

           N(3) = (1+xci)*(1+eta)/4;

           Nx(3) =  (1+eta)/4;

           Ne(3) =  (1+xci)/4;

          

           N(4) = (1-xci)*(1+eta)/4;

           Nx(4) = -(1+eta)/4;

           Ne(4) =  (1-xci)/4;

          

           % Compute the jacobian matrix

           J = [

               [Nx*xs Nx*ys]

               [Ne*xs Ne*ys]];

           detJ = det(J);

          

           % Get the y value at the current integration point

           yy = N*ys;

           xx = N*xs;

          

           % Get element info

           E  = ELEMS(ielem,5);

           nu = ELEMS(ielem,6);

           t   = ELEMS(ielem,7)

          

           % Get this points contribution to element stiffness

           EMAT = E/(1-nu^2)*[1 nu 0; nu 1 0;0 0 (1-nu)/2];

          

           H = [1 0 0 0;0 0 0 1;0 1 1 0];

          

           G = zeros(4,4);

           G(1:2,1:2) = inv(J);

           G(3:4,3:4) = inv(J);

          

           DN = zeros(4,8);

           DN(1,[1 3 5 7]) = Nx;

           DN(2,[1 3 5 7]) = Ne;

           DN(3,[2 4 6 8]) = Nx;

           DN(4,[2 4 6 8]) = Ne;

          

           B = H*G*DN;

           integrand = B'*EMAT*B*detJ*t;

          

           % Update element stiffness matrix

           KE = KE + integrand*gwts(ig)*gwts(jg);

          

           % Update area and moment of inertias

           earea = earea + detJ*gwts(ig)*gwts(jg);

           IX = IX + yy^2*detJ*gwts(ig)*gwts(jg);

           IY = IY + xx^2*detJ*gwts(ig)*gwts(jg);

       end

    end

   

    % Define the local destination array for this element

    LDA = [(2*ns(1)-1) 2*ns(1) (2*ns(2)-1) 2*ns(2) ...
           (2*ns(3)-1) 2*ns(3) (2*ns(4)-1) 2*ns(4)];

          

    % Assemble element stiffness to the global stiffness

    KG(LDA,LDA) = KG(LDA,LDA) + KE;

   

    % As a check, print the element area

    AREA = AREA + earea;

    fprintf('The result for element %d is %f\n',ielem,earea);

   

   

end

FG=zeros(2*nnodes,1);

%ASSEMBLE THE GLOBAL FORCE VECTOR FROM GIVEN POINT LOADS
npl=length(PLOADS(:,1));
for iload=1:npl
    nd=PLOADS(iload,1);
    dir=PLOADS(iload,2);
    val=PLOADS(iload,3);
   
FG(nd*2-dir,1)=FG(nd*2-dir,1)+val;

end

%take care of the displacement boundary conditions
nbc=length(DBCS(:,1));
for iload=1:nbc
    nd=DBCS(iload,1);
    dir=DBCS(iload,2);
    val=DBCS(iload,3);
   
FG=FG-KG(:,2*nd-dir)*val;

KG(:,2*nd-dir)=0;

KG(2*nd-dir,2*nd-dir) = -1;
   
   
end

%solve for the degrees of freedom

sol = inv(KG)*FG;

fprintf('AREA %f  IX %f  IY %f\n',AREA,IX,IY);

Name: Anonymous 2010-07-21 23:39

>>41
Please OPTIMIZE your quotes!

Don't change these.
Name: Email:
Entire Thread Thread List