Showing posts with label particular. Show all posts
Showing posts with label particular. Show all posts

Tuesday, March 27, 2012

Adding a new Column after a particular column

Hi,
I have a table, and i have say 3 columns, say c1,c2,c3 . Now i want to insert one more column say c2a after the column c2.How to do this, i tried with all possible ways, i cldn do, in mysql, the "AFTER" clause is ther, so i did with that, but in
MS Sql , i cdln make it...
Help me..\

ThanksStrange request, but if you absolutely have to put your new column between 2 others, then you will have to:

1. make a back up of your table
2. select * into a temp table
3. drop your table
4. create new table with cols in order you want
5. select * from temp table into your new table
6. drop temp table

happy SQLing

Thursday, March 22, 2012

adding 2 records

Hello,
I've been converting/normalizing data and inserting it to other tables.
What i would like to do is to create 2 records for a particular value if
it occurs in the denormalized table.
Any idea how i should do this?I assume you mean something like:
CREATE TABLE DenormTable
(
DenormID int PRIMARY KEY
, MainVal int
, Year2005Value int
, Year2004Value int
)
If so, you merely have to create an insert like so:
CREATE TABLE NormTable1
(
Norm1ID int PRIMARY KEY
, MainVal int
)
CREATE TABLE NormTable2
(
Norm2ID int IDENTITY(1,1) PRIMARY KEY
, Norm1ID int NOT NULL
, Val int
, Year int
)
INSERT INTO NormTable1 (Norm1ID, MainVal)
SELECT DenormID, MainVal FROM DenormTable
INSERT INTO NormTable2 (Norm1ID, Val, Year)
SELECT DenormID, Year2005Val, 2005 FROM DenormTable
INSERT INTO NormTable2 (Norm1ID, Val, Year)
SELECT DenormID, Year2004Val, 2002 FROM DenormTable
You can combine the two in a single statement, if necessary, with some CASE
statements or creating a temporary VIEW with a UNION.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
****************************************
*******
Think Outside the Box!
****************************************
*******
"Jason" <jasonlewis@.hotmail.com> wrote in message
news:u$%23PCme6FHA.564@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I've been converting/normalizing data and inserting it to other tables.
> What i would like to do is to create 2 records for a particular value if
> it occurs in the denormalized table.
> Any idea how i should do this?|||In my Delphi app connecting to Sql Server using ODBC.. When 3 or more users
updating the same table at the same time (Not the same record) there is a
delay for approx 10 sec, I tried to use Enterprise manager from another
machine to update the same table and found the same problem so the problem
is not in my program code..
Finally after trying to solve this i noticed that 1 pc is the reason of the
delay, and after changing this Client IP.. it work now great and if i change
the IP back to it's old value the problem raise again!!.
Could i know what is the relation between Sql server or ODBC and client
machine IPs'
any information will appreciated
"Jason" <jasonlewis@.hotmail.com> wrote in message
news:u$%23PCme6FHA.564@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I've been converting/normalizing data and inserting it to other tables.
> What i would like to do is to create 2 records for a particular value if
> it occurs in the denormalized table.
> Any idea how i should do this?

Sunday, February 19, 2012

Add column in middle of table

Hi all,
Is it possible to add a column to a table in a particular position? For
instance, if I had a table with columns A, B, D, E and I want to insert a
new column called 'C' but I want it to be added between columns B and D
instead of at the end of the table, is this possible? Thanks!Sure, use Enterprise Manager. It has this great technique of making a copy
of your table with the new column, copying all the data over, a fancy
rename, and don't forget moving all the constraints and permissions.
Or, stop worrying about ordinal position (there is no "end" of a table,
IMHO). Column order is irrelevant. If you have code that relies on it, fix
the code.
http://www.aspfaq.com/2478
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.

> Is it possible to add a column to a table in a particular position? For
> instance, if I had a table with columns A, B, D, E and I want to insert a
> new column called 'C' but I want it to be added between columns B and D
> instead of at the end of the table, is this possible? Thanks!