|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
copy tuples from table tsql?Hi all,
I'm trying to write a TSQL procedure that takes as an argument a tablename in a database and then it copies the first 100 tuples of the given table in the same table (it actually duplicates them). The table doesn't have a standard schema and the query should be able to deal with different kinds of schemas. Any help on this? Thanks in advance, Peter Where to start! Why would you ever want to copy a row* in the same table?
That's undesirable and unnecessary in SQL. Every table should have a key that prevents duplicate rows. Maybe you mean you want to copy rows to another table? But then you go on to say you want to copy the "first 100 tuples". Tables in SQL have no inherent logical order. What do you mean by "first 100"? Finally, parameterizing table names is generally a very bad idea in a production system. Sometimes DBAs need to do that for admin tasks and the way to do it is to use dynamic SQL. The following article has the gory details and all the caveats that go with dynamic code: http://www.sommarskog.se/dynamic_sql.html I do recommend you study some relational database theory and practice and then reconsider your requirements. [ * In relational theory tuples by definition are not duplicated in a relation. Rows are not tuples and your use of that term is incorrect. ] -- Show quoteDavid Portas SQL Server MVP -- "pnp" <pnpNOSPAM@softlab.ntua.gr> wrote in message news:OcHFgFUxFHA.2232@TK2MSFTNGP11.phx.gbl... > Hi all, > I'm trying to write a TSQL procedure that takes as an argument a tablename > in a database and then it copies the first 100 tuples of the given table > in the same table (it actually duplicates them). The table doesn't have a > standard schema and the query should be able to deal with different kinds > of schemas. > > Any help on this? > > Thanks in advance, > Peter |
|||||||||||||||||||||||