SQL query: have results into a table named the results name -


so have large db split tables. make when run distinct, make table every distinct name. name of table data in 1 of fields.

ex:

a    ---------   data 1    ---------   data 2 b    ---------   data 3 b    ---------   data 4  

would result in 2 tables, 1 named , named b. entire row of data copied field.

select distinct [name] [maintable] -make table each name -select [name] [maintable] -copy table name -drop row [maintable] 

any great!

i advise against this.

one solution create indexes, can access data quickly. if have handful of names, though, might not particularly effective because index values have select records.

another solution called partitioning. exact mechanism differs database database, underlying idea same. different portions of table (as defined name in case) stored in different places. when query looking values particular name, data gets read.

generally, bad design have multiple tables same data columns. here reasons:

  • adding column, changing type, or adding index has done times instead of 1 time.
  • it hard enforce primary key constraint on column across tables -- lose primary key.
  • queries touch more 1 name become more complicated.
  • insertions , updates more complex, because have first identify right table. results in overuse of dynamic sql otherwise basic operations.

although there may simplifications (security comes mind), databases have other mechanisms superior splitting data separate tables.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -