Showing posts with label tables. Show all posts
Showing posts with label tables. Show all posts

Friday, March 30, 2012

how to control the distance between the two matrix? or (matirx and table )

hi everyone:

the report show two tables two matrixs

how can i control the distance between them

I want to set the same distance between the table and matrix

or (table and table )

Younger,

You could possible place your tables and Matrix each inside of a rectangle and then maintain the distance between your rectangle should get you to your desired results.

Ham

|||

Ham

Thank you very much

Your idea is good, that is worked well.

Younger

How to construct table with unique PK

Let say I have 6 tables. I want to autogenerate the PK for each table and that is unique for each table and cant be duplicated on other tables. Let say I have table with PK of 1, so table2 to table6 wouldnt have a PK of 1. If table2 have a PK of 2, table1, table3 to table6 wouldnt have a PK of 2. Same for others. Identity will not be appropriate. Will 'uniqueidentifier' data type suffice? How bout guid? Or what must be my datatype? Or what will I do to implement this? Any links? Thanks

What you describe isn't really applicable to a 'normal' primary key.
In the 'normal' case, a PK doesn't care about the values of other PK's in other tables.

There are cases where one would want to distribute PK values like you describe, though I don't know if that's your reason.
(eg some replication / distribution strategies)

However, if you want to read some about keys, here's a link that mayshed some light.
http://www.datamodel.org/DataModelKeys.html

=;o)

/Kenneth

|||

have a composite primary key

key1 and key2

have key1 to have a default value of "A" for the first table, "b" for the second and "c" for the third

key2 would be an identity

your pk would be a combination of key1 and key2

and that would definitely be unique across the enterprise

|||

hi KeWin,

its implemented in a CRM thats why we're try to do the same. Any ideas how?

joeydj,

How would I get the latest PK, for example A3456 is the most recent. So the next generated PK is A3457. Can you show a sprocs that would do that. Thanks. :)

|||

Well, personally I'm not too keen on keys like 'A3457' - where 'A' has some significant meaning.
This is what's called an 'intelligent key' or 'concatenated key' (because the key itself is made up of several parts that has independent meaning), and is ususally something you want to avoid.

What a certain key should look like - well, it depends.
It's a desginer's choice, and it's part of the datamodel.

There may be a number of reasons behind any PK's design, the most important thing about it (imo) is that the designer really understands what a primary key is, and why he/she want it implemented in a certain way. Be it natural or a surrogate, it should be deliberate with some thought behind it.

This leads to the next question, how to decide?
There's no simple answer to that question, unfortunately, it's one of those 'it depends' things....

Your best tool is understanding, both of the database in question, the business it should support, and the concept of primary keys etc.
(I don't have any good links handy, but google usually manages to come up with something =;o)

/Kenneth

|||

portect wrote:

hi KeWin,

its implemented in a CRM thats why we're try to do the same. Any ideas how?

joeydj,

How would I get the latest PK, for example A3456 is the most recent. So the next generated PK is A3457. Can you show a sprocs that would do that. Thanks. :)

try this. this is called a composite pk solution. the advantage is that you dont need to worry whats

the next number in sequence. the problem is joining with other table.

CREATE TABLE [mytable] (
[key1] [char] (1) NOT NULL CONSTRAINT [DF_mytable_key1] DEFAULT ('A'),
[key2] [int] IDENTITY (1, 1) NOT NULL ,
[data1] [char] (10) NULL ,
[data2] [char] (10) NULL ,
CONSTRAINT [PK_mytable] PRIMARY KEY CLUSTERED
(
[key1],
[key2]
) ON [PRIMARY]
) ON [PRIMARY]
GO

insert into mytable(data1,data2)values('mydata1a','mydata2a')
insert into mytable(data1,data2)values('mydata1b','mydata2b')
select * from mytable

|||

an alternative solution here.

remember that an identity has a seed and increment parameter.

seed Is the value that is used for the very first row loaded into the table.

this is called an identity seed and contraint solution.

first table shall be between 1 and 10M

pk type bigint, identity on, seed=1

data type bigint

constraint: pk between 1 and 10,000,000

second table shall be between 10M+1 and 20M

pk type bigint, identity on, seed=10,000,0001

data type bigint

constraint: pk between 10,000,001 and 20,000,000

third table shall be between 20M+1 and

pk type bigint, identity on, seed=20,000,0001

data type bigint

constraint: pk between 20,000,001 and 30,000,000

if your not happy with 10M difference make it 100M.

this solution seems better to me.

|||Thanks all. I think surrogate keys will be appropriate.|||

follow up question:

http://forums.microsoft.com/MSDN/showpost.aspx?postid=857019&siteid=1

thanks.

sql

Wednesday, March 28, 2012

How to Connect VB and Visual Foxpro

I have some tables in .dbf format, I want to connect VB
and Visual Foxpro 6.0. How to connect VB with .dbf in
Visual Foxpro.Via ADO using the FoxPro ODBC or OLEDB driver.
If you need more help, post to one of the Fox groups such as
microsoft.public.fox.programmer.exchange.
--
David Portas
--
Please reply only to the newsgroup
--
"K.G.Palanisamy" <sendprasath@.yahoo.com> wrote in message
news:04cf01c3460d$605c3280$a001280a@.phx.gbl...
> I have some tables in .dbf format, I want to connect VB
> and Visual Foxpro 6.0. How to connect VB with .dbf in
> Visual Foxpro.

Monday, March 26, 2012

How to connect to SQL Database, Create tables

Hi All, 1st of all happy New Year to all asp.net forum members
I am new at asp.net. I want to design a websiteusing asp.net as frontend and sql database as backend. I am able toconnect and add,update as well delete records when I use MsAcess andAsp.net using the following connection strings...
**********
sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("/database/northwind.mdb"))
dbconn.Open()
sql="SELECT * FROM customers where city LIKE 'Berlin' order by city ASC"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
customers.DataSource=dbread
customers.DataBind()
dbread.Close()
dbconn.Close()
end sub
**********

But when I try to connect to sql database using the following connection strings I am unable to do so...

**************
SqlConnection myConnection = new SqlConnection("server=PLATINUM\VSdotNET;database=pubs;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter(" * from Authors", myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");

MyDataGrid.DataSource=ds.Tables["Authors"].DefaultView;
MyDataGrid.DataBind();

**************
I have written the servername as "PLATINUM\VSdotNET" because when Iinstalled SQL SERVER 2000 I found a tray icon where the server name wasdisplaying the same (my computer name is PLATINUM).
When I used webmatrix I enterd the same server name and windowsauthentication I was able to create a database but How to createtable...

Please help me out
Thanks in advance...Please explain "I am unable to do so". Are you receiving an error message?|||Actually I don't know whether the connection string I am using is correct or not...
Because I am unable to create tables using the connection strigns what I told before...

when I try running this page I get the error message like
Compiler Error Message:CS1009: Unrecognized escape sequence
and the compiler shows a error in the connection string , So as far I guess there is problem with the connection string only.

If I get a sample page for what I am trying to do i.e connecting to SQLdatabase, Creating tables as well as accessing table my problem will besolved.
Thanks for your time.


|||Well, I always use this resource for building connection strings:http://www.connectionstrings.com/ Check out the SqlConnection (.NET) options under SQL Server. Yourproblem *might* be that you should use True, not Yes, forTrusted_Connection. In any case, I would try to stick as closelyas possible to the advice listed there.|||* from Authors is not a valid SQL Statement. Try SELECT * FROM Authors

Friday, March 23, 2012

How to connect Oracle Database in Microsoft Analysis Services

Hi All,

I am not able to connect oracle database from MS-Analysis Services.


All my Fact tables and Dimension tables are residing on Oracle
database.Both the Oracle database and MS Analysis Services are on the
same server.


I am working on the node and I was able to create the datasource using
"Microsoft OLE DB Provider for Oracle " and the test connection also
succedded but while creating the cubes using the cube wizard it throws
error saying " Connection to the data source Failed".

Any one could help me in this regards.

What are the ways to connect the oracle DB from MS Analysis Services.

Is this problem becoz of any permission settings, how do I give permissions for the users.

Regards
Saravanavel

What users are you talking about?

Are you going to let someone else to design cubes using your data source? In this case anyone trying to run cube wizard should have permissions to access Oracle database. Cube wizard requires access to relational database.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Friday, March 9, 2012

How to CONCATENATE >50 fields in Excel table into SQL Insert State

SQL Server 2005, Excel 2003
I would like to populate some tables in a SQL database from some tables in
Excel.
Previously I have used the Concatenate function in Excel to construct SQL
Insert statement such as example below.
=CONCATENATE("INSERT INTO Product (Field1,Field2,Field3,Field4,Field5)
VALUES ('",B2,"','",C2,"',",D2,",",E2,",",F2,")")
However, there is a limit in using the Concatenate function in Excel and
this dows not work on a larger table (50 fileds). Please could you advice
how I could create the SQL insert statements using this Excel table to
populate the associate SQL table? Is there any better/alternative ways?
Many thanks in advance,
Hi Will,
The bcp utility will import the file into a table for you. You can learn
about it here:
http://technet.microsoft.com/en-us/library/ms162802.aspx
-Susan
"will~" wrote:

> SQL Server 2005, Excel 2003
> I would like to populate some tables in a SQL database from some tables in
> Excel.
> Previously I have used the Concatenate function in Excel to construct SQL
> Insert statement such as example below.
> =CONCATENATE("INSERT INTO Product (Field1,Field2,Field3,Field4,Field5)
> VALUES ('",B2,"','",C2,"',",D2,",",E2,",",F2,")")
> However, there is a limit in using the Concatenate function in Excel and
> this dows not work on a larger table (50 fileds). Please could you advice
> how I could create the SQL insert statements using this Excel table to
> populate the associate SQL table? Is there any better/alternative ways?
> Many thanks in advance,
>
|||On Thu, 28 Feb 2008 07:43:00 -0800, Susan Cooper
<SusanCooper@.discussions.microsoft.com> wrote:

>Hi Will,
>The bcp utility will import the file into a table for you. You can learn
>about it here:
>http://technet.microsoft.com/en-us/library/ms162802.aspx
>-Susan
BCP.EXE is quite particular about the format of an input file. While
you might be able to EXPORT from Excel in a format that can somehow be
made to work with BCP.EXE, it is not a simple process.
I would start by using the data import wizard. This can create a DTS
package (SQL Server 2000) or an SSIS package (SQL Server 2005).
Roy Harvey
Beacon Falls, CT

How to CONCATENATE >50 fields in Excel table into SQL Insert State

SQL Server 2005, Excel 2003
I would like to populate some tables in a SQL database from some tables in
Excel.
Previously I have used the Concatenate function in Excel to construct SQL
Insert statement such as example below.
=CONCATENATE("INSERT INTO Product (Field1,Field2,Field3,Field4,Field5)
VALUES ('",B2,"','",C2,"',",D2,",",E2,",",F2,")")
However, there is a limit in using the Concatenate function in Excel and
this dows not work on a larger table (50 fileds). Please could you advice
how I could create the SQL insert statements using this Excel table to
populate the associate SQL table? Is there any better/alternative ways?
Many thanks in advance,Hi Will,
The bcp utility will import the file into a table for you. You can learn
about it here:
http://technet.microsoft.com/en-us/library/ms162802.aspx
-Susan
"will~" wrote:
> SQL Server 2005, Excel 2003
> I would like to populate some tables in a SQL database from some tables in
> Excel.
> Previously I have used the Concatenate function in Excel to construct SQL
> Insert statement such as example below.
> =CONCATENATE("INSERT INTO Product (Field1,Field2,Field3,Field4,Field5)
> VALUES ('",B2,"','",C2,"',",D2,",",E2,",",F2,")")
> However, there is a limit in using the Concatenate function in Excel and
> this dows not work on a larger table (50 fileds). Please could you advice
> how I could create the SQL insert statements using this Excel table to
> populate the associate SQL table? Is there any better/alternative ways?
> Many thanks in advance,
>|||On Thu, 28 Feb 2008 07:43:00 -0800, Susan Cooper
<SusanCooper@.discussions.microsoft.com> wrote:
>Hi Will,
>The bcp utility will import the file into a table for you. You can learn
>about it here:
>http://technet.microsoft.com/en-us/library/ms162802.aspx
>-Susan
BCP.EXE is quite particular about the format of an input file. While
you might be able to EXPORT from Excel in a format that can somehow be
made to work with BCP.EXE, it is not a simple process.
I would start by using the data import wizard. This can create a DTS
package (SQL Server 2000) or an SSIS package (SQL Server 2005).
Roy Harvey
Beacon Falls, CT

How to Compute Actual Space Used In Datafiles

Has anyone discovered the algorithm and the appropriate system
tables/columns to use to compute the actual amount of space used/remaining
within a database datafile?
I'm trying to hit out to the values displayed in the "Taskpad" view in
Enterprise Manager and want to write a routine around those values.Undocumented DBCC command 'DBCC SHOWFILESTATS' is what drives that display.
You can build some really good stuff around that command.
--
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
"Jack Snow" <mrbrew5510@.hotmail.com> wrote in message
news:HAemc.146252$Gd3.35432608@.news4.srv.hcvlny.cv.net...
> Has anyone discovered the algorithm and the appropriate system
> tables/columns to use to compute the actual amount of space used/remaining
> within a database datafile?
> I'm trying to hit out to the values displayed in the "Taskpad" view in
> Enterprise Manager and want to write a routine around those values.
>|||Have you looked at sp_spaceused ?
"Geoff N. Hiten" <SRDBA@.Careerbuilder.com> wrote in message news:<u#PQovwMEHA.3944@.tk2msftngp13.phx.gbl>...
> Undocumented DBCC command 'DBCC SHOWFILESTATS' is what drives that display.
> You can build some really good stuff around that command.
> --
> Geoff N. Hiten
> Microsoft SQL Server MVP
> Senior Database Administrator
> Careerbuilder.com
>
> "Jack Snow" <mrbrew5510@.hotmail.com> wrote in message
> news:HAemc.146252$Gd3.35432608@.news4.srv.hcvlny.cv.net...
> > Has anyone discovered the algorithm and the appropriate system
> > tables/columns to use to compute the actual amount of space used/remaining
> > within a database datafile?
> > I'm trying to hit out to the values displayed in the "Taskpad" view in
> > Enterprise Manager and want to write a routine around those values.
> >
> >|||Yes. It has one huge glaring weakness. It does not look at space within a
filegroup. Knowing that a database has 70% free space is useless if I have
a filegroup that is full. With DBCCSHOWFILESTATS, I was able to aggregate
data usage within files and filegroups to get a meaningful space used/free
report.
--
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"WangKhar" <Wangkhar@.yahoo.com> wrote in message
news:bb269444.0405060059.20b88b1e@.posting.google.com...
> Have you looked at sp_spaceused ?
>
> "Geoff N. Hiten" <SRDBA@.Careerbuilder.com> wrote in message
news:<u#PQovwMEHA.3944@.tk2msftngp13.phx.gbl>...
> > Undocumented DBCC command 'DBCC SHOWFILESTATS' is what drives that
display.
> > You can build some really good stuff around that command.
> >
> > --
> > Geoff N. Hiten
> > Microsoft SQL Server MVP
> > Senior Database Administrator
> > Careerbuilder.com
> >
> >
> >
> > "Jack Snow" <mrbrew5510@.hotmail.com> wrote in message
> > news:HAemc.146252$Gd3.35432608@.news4.srv.hcvlny.cv.net...
> > > Has anyone discovered the algorithm and the appropriate system
> > > tables/columns to use to compute the actual amount of space
used/remaining
> > > within a database datafile?
> > > I'm trying to hit out to the values displayed in the "Taskpad" view in
> > > Enterprise Manager and want to write a routine around those values.
> > >
> > >

Wednesday, March 7, 2012

How to compare two versions of sqlserver?

HI,
I need to do an installer utility in which I have to install sql tables. In
there, I would need to check the version of sql server and add some
constraints if the sql server version is more than 8 and do alternate action
if its not.
Is there any function like version_compare()?
Thanks & Regards,
Celia
msnews wrote:
> HI,
> I need to do an installer utility in which I have to install sql tables. In
> there, I would need to check the version of sql server and add some
> constraints if the sql server version is more than 8 and do alternate action
> if its not.
> Is there any function like version_compare()?
> Thanks & Regards,
> Celia
>
>
There isn't a "out of the box" version compare function as such. I think
you'll have to use @.@.Version or SERVERPROPERTY and then use the result
you get from here to do your evaluation.
You can look up both options in Books On Line for further info and syntax.
Regards
Steen

How to compare two versions of sqlserver?

HI,
I need to do an installer utility in which I have to install sql tables. In
there, I would need to check the version of sql server and add some
constraints if the sql server version is more than 8 and do alternate action
if its not.
Is there any function like version_compare()?
Thanks & Regards,
Celiamsnews wrote:
> HI,
> I need to do an installer utility in which I have to install sql tables. I
n
> there, I would need to check the version of sql server and add some
> constraints if the sql server version is more than 8 and do alternate acti
on
> if its not.
> Is there any function like version_compare()?
> Thanks & Regards,
> Celia
>
>
There isn't a "out of the box" version compare function as such. I think
you'll have to use @.@.Version or SERVERPROPERTY and then use the result
you get from here to do your evaluation.
You can look up both options in Books On Line for further info and syntax.
Regards
Steen

How to compare two versions of sqlserver?

HI,
I need to do an installer utility in which I have to install sql tables. In
there, I would need to check the version of sql server and add some
constraints if the sql server version is more than 8 and do alternate action
if its not.
Is there any function like version_compare()?
Thanks & Regards,
Celiamsnews wrote:
> HI,
> I need to do an installer utility in which I have to install sql tables. In
> there, I would need to check the version of sql server and add some
> constraints if the sql server version is more than 8 and do alternate action
> if its not.
> Is there any function like version_compare()?
> Thanks & Regards,
> Celia
>
>
There isn't a "out of the box" version compare function as such. I think
you'll have to use @.@.Version or SERVERPROPERTY and then use the result
you get from here to do your evaluation.
You can look up both options in Books On Line for further info and syntax.
Regards
Steen

How to compare two tables

Hello, I don't know how to do this and I'm sure its dead simple.
I have two tables that I'll use on a WHERE condition, and I need to know
that the rows in one are exactly the same rows in the other. I don't want
to return results in my query unless there is an exact match between those
two single column tables...
I've been using a two select ... except two solve my problem, but I know
there must be a simpler way, and obviously I'm stuck and unable to think..
An example:
CREATE TABLE #a(c int)
CREATE TABLE #b(c int)
CREATE TABLE #c(c int)
If I have this:
INSERT INTO #a SELECT 1 UNION ALL SELECT 2
INSERT INTO #b SELECT 1 UNION ALL SELECT 2
INSERT INTO #c SELECT 3
Then I want a condition that will make this (which will return a '3')
simpler:
SELECT *
FROM #c
WHERE
NOT EXISTS (
SELECT c
FROM #a
EXCEPT
SELECT c
FROM #b
)
AND NOT EXISTS (
SELECT c
FROM #b
EXCEPT
SELECT c
FROM #a
)
If instead of the above rows I had this:
INSERT INTO #a SELECT 1
INSERT INTO #b SELECT 1 UNION ALL SELECT 2
I shouldn't have a 3 as an answer...
Please tell me there's a better way!!
Regards,
Pablo
--
:whizzy: adj. (alt. `wizzy') [Sun] Describes a {cuspy} program;
one that is feature-rich and well presented.
-- from The on-line Hacker Jargon File V423
Pablo Montilla
www.odyssey.com.uyThe SQL 2005 operator INTERSECT will compare two result sets and only return
rows that are identical in both sets. NOte that BLOB data types cannot be
compared using UNION, INTERSECT, or EXCEPT.
--
Geoff N. Hiten
Senior SQL Infrastructure Consultant
Microsoft SQL Server MVP
"Pablo Montilla" <melkor@.odyssey.com.uy> wrote in message
news:op.tyyy7xoscj6shk@.chimera.odyssey.com.uy...
> Hello, I don't know how to do this and I'm sure its dead simple.
> I have two tables that I'll use on a WHERE condition, and I need to know
> that the rows in one are exactly the same rows in the other. I don't want
> to return results in my query unless there is an exact match between those
> two single column tables...
> I've been using a two select ... except two solve my problem, but I know
> there must be a simpler way, and obviously I'm stuck and unable to think..
> An example:
> CREATE TABLE #a(c int)
> CREATE TABLE #b(c int)
> CREATE TABLE #c(c int)
> If I have this:
> INSERT INTO #a SELECT 1 UNION ALL SELECT 2
> INSERT INTO #b SELECT 1 UNION ALL SELECT 2
> INSERT INTO #c SELECT 3
> Then I want a condition that will make this (which will return a '3')
> simpler:
>
> SELECT *
> FROM #c
> WHERE
> NOT EXISTS (
> SELECT c
> FROM #a
> EXCEPT
> SELECT c
> FROM #b
> )
> AND NOT EXISTS (
> SELECT c
> FROM #b
> EXCEPT
> SELECT c
> FROM #a
> )
> If instead of the above rows I had this:
> INSERT INTO #a SELECT 1
> INSERT INTO #b SELECT 1 UNION ALL SELECT 2
> I shouldn't have a 3 as an answer...
> Please tell me there's a better way!!
> Regards,
> Pablo
> --
>
> :whizzy: adj. (alt. `wizzy') [Sun] Describes a {cuspy} program;
> one that is feature-rich and well presented.
> -- from The on-line Hacker Jargon File V423
> Pablo Montilla
> www.odyssey.com.uy|||On Thu, 20 Sep 2007 17:36:38 -0300, Geoff N. Hiten
<SQLCraftsman@.gmail.com> wrote:
> The SQL 2005 operator INTERSECT will compare two result sets and only
> return rows that are identical in both sets. NOte that BLOB data types
> cannot be compared using UNION, INTERSECT, or EXCEPT.
>
OK, but I need to know if the two sets of rows are identical. If I
interesct, how do I know if the intersection its formed by all the rows in
both tables?
Thanks,
Pablo
:whizzy: adj. (alt. `wizzy') [Sun] Describes a {cuspy} program;
one that is feature-rich and well presented.
-- from The on-line Hacker Jargon File V423
Pablo Montilla
www.odyssey.com.uy|||OK, use EXCEPT. Think of the three operators this war:
UNION is logical OR
INTERSECT is logical AND
EXCEPT is logical NOT
Applied to sets, not variables.
--
Geoff N. Hiten
Senior SQL Infrastructure Consultant
Microsoft SQL Server MVP
"Pablo Montilla" <melkor@.odyssey.com.uy> wrote in message
news:op.tyy0okgvcj6shk@.chimera.odyssey.com.uy...
> On Thu, 20 Sep 2007 17:36:38 -0300, Geoff N. Hiten
> <SQLCraftsman@.gmail.com> wrote:
>> The SQL 2005 operator INTERSECT will compare two result sets and only
>> return rows that are identical in both sets. NOte that BLOB data types
>> cannot be compared using UNION, INTERSECT, or EXCEPT.
> OK, but I need to know if the two sets of rows are identical. If I
> interesct, how do I know if the intersection its formed by all the rows in
> both tables?
> Thanks,
> Pablo
>
> --
>
> :whizzy: adj. (alt. `wizzy') [Sun] Describes a {cuspy} program;
> one that is feature-rich and well presented.
> -- from The on-line Hacker Jargon File V423
> Pablo Montilla
> www.odyssey.com.uy|||Many thanks for your response. So there is no easier, simpler way than to
do two except checks, to see if any element is on one table but not in the
other?
Pity...;o)
Regards,
Pablo
His mind is so open that the wind whistles through it.
-- Heywood Braun
Pablo Montilla
www.odyssey.com.uy

how to Compare 2 tables using cursors?

I have 2 tables that have the same fields and the same data. However when I counted the records, I found that one table contain more records than the other. Now I need to delete the extra records and make the table identical. How can I do this using cursor?
Please advice it's urgentFirst of all, are you sure you only have extra records in the second (or first, whatever) table ?

Indeed, if table A contains the followings rows
1
2
3

and table B contains
1
2
4
5

then deleting all "extra" rows in table B will end you up with 2 rows in table B, which is not exactly what you want...

Don't bother using a cursor when you can do things directly :

DELETE FROM B WHERE b.pk NOT IN (SELECT a.pk FROM A)

where pk stands for primary key (or some unique key).

Anyway, to make two tables identical, i would just truncate the "bad" one, and re-insert all rows from the "good" one.|||Thank You for your reply ..

The problem that it's not that easy. One table is in Oracle Platform and the other is in as400 (IBM platform) but I took care of that. The other problem is that the oracle table contain around 87000 records and as400 table has 84000 although we are running a batch file to copy the same records to both tables. The normal way of doing this will take at least 1 hour to run the query. So I tought cursors will make it faster.

What do you think?|||I'm still trying to understand. Can you confirm following assumptions ?

1. Your "source" table is the one on the AS400, and it contains all data you need.

2. Your "duplicate" table is the one on Oracle, and it contains too many rows.

3. Now, you would like to "restore" the table on Oracle using data from your table on the AS400.

CVM.|||Yes this is exactly what I need and note that there are 4 PK for the tables. What I found out that sometimes when the user delete a record from the as400 table it's not deleted in oracle. that's why we have more records in oracle.

the system we have is basically like this

as400 master table : store original data

as400 intermediate file : takes the data from the master table and store them

oracle intermediate file: take the information from the as400 intermediate file and store them

oracle master table: takes the information from oracle intermediate table.

so at the end the as400 master table and the oracle master table must be identical however they are not.|||Originally posted by moza
The normal way of doing this will take at least 1 hour to run the query. So I tought cursors will make it faster.

Now that I've got your answers, let's get back to your original problem.

1. Of course you can do it using cursors (read from as400, see if it exists on Oracle, ...). This is quite straightforward to implement, but it will not be faster than copying the data directly (see point 2). Moreover, you need to write code (and we don't like that, do we...)

2. My current project also involves an AS400 (source) and an Oracle database (destination). I cannot imagine that those 87000 rows are giving you a hard time. I don't know the size of a row, nor do I know about the number of indexes, etc. that are linked to the destination table, but I can simply not imagine that it takes about 1 hour. Did you try using the (Sql*Plus) command COPY FROM ?|||I know that there are some simple ways of doing this, but it's not dicision to make. Moreover, these table are so active and users are accessing it every seconds so there should be no chance for any mistake or loss or data. What my boss suggested is to run cursors for both tables and store as oracle record in local variables, search for it in as400, if not exists then delete it. But It's not working.
The tables doesn't use indexes.|||What exactly do you mean by "The tables doesn't use indexes" ?

Anyway, I'm a getting out of ideas here. Knowing a little bit about the AS400, and considering the fact that you don't want to have mistakes/loss or data during your patch, my guess is you need to run your patch using a very high commitment control level (on the AS400) like REPEATABLE READ, which gets your users locked anyway.

How to compare 2 tables ot different DBs in Oracle style

In Oracle this is done this way :
SQL>
1 select ID, NAME from TABLENAME
2* minus select ID,NAME from TABLENAME@.DATABASE2
SQL>

Any ideas ?Yeah...minus is a way to do a non existance checj=k...or a left outer join where the right table key is null...

I don't know what your talking about with @.DATABASE2|||Originally posted by Brett Kaiser
I don't know what your talking about with @.DATABASE2 That's Oracle speak for DATABASE2..TABLENAME in SQL-92.

-PatP|||See...my Oracle naivite' is showing...

Never dealt with more than 1 db in Oracle...|||select ID, NAME from TABLENAME
minus select ID,NAME from TABLENAME@.DATABASE2

This statement compares table TABLENAME in current database and DATABASE2 and shows the lines that are missing in the current database.

If it returns

1 | Test1
2 | Test2

this meanse that these 2 lines exists in TABLENAME in current DB, and doest not exists in TABLENAME in DATABASE2.

In SQL Server it should be something like this :

SELECT ID, NAME FROM TABLENAME
MINUS
SELECT ID,NAME FROM DATABASE2..TABLENAME

but we don't have MINUS in T-SQL|||Might I suggest using a FULL OUTER JOIN to see what was added or deleted, then a compare of the column values to see what keys have different values associated with them?

-PatP|||FYI, http://www.sql-server-performance.com/vg_database_comparison_sp.asp

Originally posted by The-Saint
In Oracle this is done this way :

SQL>
1 select ID, NAME from TABLENAME
2* minus select ID,NAME from TABLENAME@.DATABASE2
SQL>

Any ideas ?

Friday, February 24, 2012

how to combine two different SQL server data instance into one db?

Hi

I'd like to know how I can combine two tables from two different sql instances ito one db?

thanks.

Volkan, can you provide a little more info?

Are you trying move the data from sql instance 1 and sql instance 2 into a new database on sql instance 3?

Are you asking how you can query the data from two different instances?

You can query separate instances by using a four-part qualifier if the instances are defined as linked servers.

select * from [servername].[databasename].[schema].[tablename]

Example: server = MySQL1, database = MyDatabase, schema = dbo, table = MyTable

select * from MySQL1.MyDatabase.dbo.MyTable

|||

If both the DBs are on same Server and the current user have access permission on both database then you can use the following query..

Select SomeColumns From CurrentDBName..TableName
Select SomeColumns From OtherDBName..TableName

If the databases are on different Server then you have to use the Linked Server..

EXEC sp_addlinkedserver @.server = 'SERVER', @.provider = 'SQLOLEDB.1', @.srvproduct = '', @.provstr = 'Privider=SQLOLEDB.1;Data Source=TargetServer;Initial Catalog=Database'

go
Exec sp_addlinkedsrvlogin @.rmtsrvname = 'SERVER', @.useself = true, @.locallogin = null, @.rmtuser = 'Userid', @.rmtpassword = 'Password'


On your SP you can use..

Select * From OpenQuery(MyRemoteServer, 'Select * From Sysobjects')

--OR

Select * From MyRemoteServer.DatabaseName.dbo.Sysobjects

How to comair DB objects in Development server with Production server

I have couple of Stored procedures and UDFs and Tables which I generated an
script from our development server and our database admin has run that
script on the production server.Unfortunately because of some changes I had
to generate the script two more times and now I'd like to make sure that the
objects in the producation are same as development.Is there a way to compaur
tham and to see what the potential differences are?
ThanksThere are many database comparison tools in the market. For example:
redgate.com
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"J-T" <J-T@.nospam.com> wrote in message
news:O3FEPJ8jFHA.1204@.TK2MSFTNGP12.phx.gbl...
>I have couple of Stored procedures and UDFs and Tables which I generated an
>script from our development server and our database admin has run that
>script on the production server.Unfortunately because of some changes I had
>to generate the script two more times and now I'd like to make sure that
>the objects in the producation are same as development.Is there a way to
>compaur tham and to see what the potential differences are?
>
> Thanks
>|||http://www.aspfaq.com/2209
Also, think about WinDiff if you have Visual Studio installed...
"J-T" <J-T@.nospam.com> wrote in message
news:O3FEPJ8jFHA.1204@.TK2MSFTNGP12.phx.gbl...
>I have couple of Stored procedures and UDFs and Tables which I generated an
>script from our development server and our database admin has run that
>script on the production server.Unfortunately because of some changes I had
>to generate the script two more times and now I'd like to make sure that
>the objects in the producation are same as development.Is there a way to
>compaur tham and to see what the potential differences are?

How to comair Database objects

I have couple of Stored procedures and UDFs and Tables which I generated an
script from our development server and our database admin has run that
script on the production server.Unfortunately because of some changes I had
to generate the script two more times and now I'd like to make sure that the
objects in the producation are same as development.Is there a way to compaur
tham and to see what the potential differences are?
Thanks
Hi
Using a version control system should stop this occuring. You can use dmo to
compare objects or possibly a third party application such as dbghost
www.dbghost.com or red gate compare www.red-gate.com .
John
"J-T" <J-T@.nospam.com> wrote in message
news:%23Jr%238I8jFHA.3048@.TK2MSFTNGP10.phx.gbl...
>I have couple of Stored procedures and UDFs and Tables which I generated an
>script from our development server and our database admin has run that
>script on the production server.Unfortunately because of some changes I had
>to generate the script two more times and now I'd like to make sure that
>the objects in the producation are same as development.Is there a way to
>compaur tham and to see what the potential differences are?
>
> Thanks
>
|||The red-gate is awesome.
Thanks a lot
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:u6Z%23yP8jFHA.3144@.TK2MSFTNGP12.phx.gbl...
> Hi
> Using a version control system should stop this occuring. You can use dmo
> to compare objects or possibly a third party application such as dbghost
> www.dbghost.com or red gate compare www.red-gate.com .
> John
> "J-T" <J-T@.nospam.com> wrote in message
> news:%23Jr%238I8jFHA.3048@.TK2MSFTNGP10.phx.gbl...
>

How to comair Database objects

I have couple of Stored procedures and UDFs and Tables which I generated an
script from our development server and our database admin has run that
script on the production server.Unfortunately because of some changes I had
to generate the script two more times and now I'd like to make sure that the
objects in the producation are same as development.Is there a way to compaur
tham and to see what the potential differences are?
ThanksHi
Using a version control system should stop this occuring. You can use dmo to
compare objects or possibly a third party application such as dbghost
www.dbghost.com or red gate compare www.red-gate.com .
John
"J-T" <J-T@.nospam.com> wrote in message
news:%23Jr%238I8jFHA.3048@.TK2MSFTNGP10.phx.gbl...
>I have couple of Stored procedures and UDFs and Tables which I generated an
>script from our development server and our database admin has run that
>script on the production server.Unfortunately because of some changes I had
>to generate the script two more times and now I'd like to make sure that
>the objects in the producation are same as development.Is there a way to
>compaur tham and to see what the potential differences are?
>
> Thanks
>|||The red-gate is awesome.
Thanks a lot
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:u6Z%23yP8jFHA.3144@.TK2MSFTNGP12.phx.gbl...
> Hi
> Using a version control system should stop this occuring. You can use dmo
> to compare objects or possibly a third party application such as dbghost
> www.dbghost.com or red gate compare www.red-gate.com .
> John
> "J-T" <J-T@.nospam.com> wrote in message
> news:%23Jr%238I8jFHA.3048@.TK2MSFTNGP10.phx.gbl...
>

How to comair Database objects

I have couple of Stored procedures and UDFs and Tables which I generated an
script from our development server and our database admin has run that
script on the production server.Unfortunately because of some changes I had
to generate the script two more times and now I'd like to make sure that the
objects in the producation are same as development.Is there a way to compaur
tham and to see what the potential differences are?
ThanksHi
Using a version control system should stop this occuring. You can use dmo to
compare objects or possibly a third party application such as dbghost
www.dbghost.com or red gate compare www.red-gate.com .
John
"J-T" <J-T@.nospam.com> wrote in message
news:%23Jr%238I8jFHA.3048@.TK2MSFTNGP10.phx.gbl...
>I have couple of Stored procedures and UDFs and Tables which I generated an
>script from our development server and our database admin has run that
>script on the production server.Unfortunately because of some changes I had
>to generate the script two more times and now I'd like to make sure that
>the objects in the producation are same as development.Is there a way to
>compaur tham and to see what the potential differences are?
>
> Thanks
>|||The red-gate is awesome.
Thanks a lot
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:u6Z%23yP8jFHA.3144@.TK2MSFTNGP12.phx.gbl...
> Hi
> Using a version control system should stop this occuring. You can use dmo
> to compare objects or possibly a third party application such as dbghost
> www.dbghost.com or red gate compare www.red-gate.com .
> John
> "J-T" <J-T@.nospam.com> wrote in message
> news:%23Jr%238I8jFHA.3048@.TK2MSFTNGP10.phx.gbl...
>>I have couple of Stored procedures and UDFs and Tables which I generated
>>an script from our development server and our database admin has run that
>>script on the production server.Unfortunately because of some changes I
>>had to generate the script two more times and now I'd like to make sure
>>that the objects in the producation are same as development.Is there a way
>>to compaur tham and to see what the potential differences are?
>>
>> Thanks
>

Sunday, February 19, 2012

How to clear the Conflict tables from database

Dear Friends
I have created a Mearge Replication with name TEST for database DBTEST I
have deleted the same Replicaiton but now in my Database DBTEST i see the
tables with name Conflict_TEST_TableName
How i can clean the same.
Your guidance will enable me to solve the problem.
Thanks and best regards
Shailesh.
Shailesh,
you can drop these tables using query analyser.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)