Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all 13329 articles
Browse latest View live

list database and tale in terasata

$
0
0
i nee to lisr all data base and related table in teradata srver with vb6 classic,how to?
example:

db1
- tble1
- tble2
db2
tble7
- tble9
...
ecc

Celko: Best fit query or T-Join

$
0
0
Dr. Codd's T-Join

In the Second Version of the relational model in 1990, Dr. E. F. Codd introduced a set of new theta operators, called T-operators, which were based on the idea of a best-fit or approximate equality (Codd 1990). The algorithm for the operators is easier to understand with an example modified from Dr. Codd.

The problem is to assign the classes to the available classrooms. We want (class_size < or <= room_size) to be true after the assignments are made. The first < will allow us a few empty seats in each room for late students; the <= can have exact matches.

Th naive approaches Codd gave were: (1) sort the tables in ascending order by classroom size and then matched the number of students in a class. (2) sort the tables in descending order by classroom size and then matched the number of students in a class.

We start with the following tables:

CREATE TABLE Rooms
(room_nbr CHAR(2) NOT NULL PRIMARY KEY,
room_size INTEGER NOT NULL
CHECK (room_size > 0));

INSERT INTO Rooms
VALUES
('r1', 70),
('r2', 40),
('r3', 50),
('r4', 85),
('r5', 30),
('r6', 65),
('r7', 55);

CREATE TABLE Classes
(class_nbr CHAR(2) NOT NULL PRIMARY KEY,
class_size INTEGER NOT NULL
CHECK (class_size > 0));

INSERT INTO Classes (class_nbr, class_size)
VALUES
('c1', 80),
('c2', 70),
('c3', 65),
('c4', 55),
('c5', 50),
('c6', 40);

The “best fit” problem is to assign classes to rooms with the fewest empty chairs in the room and nobody standing. The starting point is to find all the rooms that can hold a particular class.

SELECT room_nbr, class_nbr, (room_size - class_size) AS fit
FROM Classes, Rooms
WHERE class_size <= room_size;

Now, let's try to find the best fits:

WITH RC --- all legal pairs
AS
(SELECT *, (room_size - class_size) AS fit
FROM Classes, Rooms
WHERE class_size <= room_size)

SELECT * -- best fit
FROM RC
WHERE fit = (SELECT MIN(fit)
FROM RC AS RCa
WHERE RC.class_nbr = RCa.class_nbr);

Results
==============
c1 80 r4 85 5
c2 70 r1 70 0
c3 65 r6 65 0
c4 55 r7 55 0
c5 50 r3 50 0
c6 40 r2 40 0

This is very good, but it depends on the data! Slight change in the legal pairs CTE or the data, to allow for spare seating, will invalidate the results.

WITH RC --- all legal pairs with spare room
AS
(SELECT *, (room_size - class_size) AS fit
FROM Classes, Rooms
WHERE class_size < room_size)

SELECT * -- best fit
FROM RC
WHERE fit = (SELECT MIN(fit)
FROM RC AS RCa
WHERE RC.class_nbr = RCa.class_nbr);

Results
=================
c1 80 r4 85 5 ◄ Opps!
c2 70 r4 85 15 ◄ Opps! Duplicate room number!
c3 65 r1 70 5
c4 55 r6 65 10
c5 50 r7 55 5
c6 40 r3 50 10

Anyone want to try for general solution?

Celko: Best fit query or T-Join

$
0
0
Dr. Codd's T-Join

In the Second Version of the relational model in 1990, Dr. E. F. Codd introduced a set of new theta operators, called T-operators, which were based on the idea of a best-fit or approximate equality (Codd 1990). The algorithm for the operators is easier to understand with an example modified from Dr. Codd.

The problem is to assign the classes to the available classrooms. We want (class_size < or <= room_size) to be true after the assignments are made. The first < will allow us a few empty seats in each room for late students; the <= can have exact matches.

Th naive approaches Codd gave were: (1) sort the tables in ascending order by classroom size and then matched the number of students in a class. (2) sort the tables in descending order by classroom size and then matched the number of students in a class.

We start with the following tables:

CREATE TABLE Rooms
(room_nbr CHAR(2) NOT NULL PRIMARY KEY,
room_size INTEGER NOT NULL
CHECK (room_size > 0));

INSERT INTO Rooms
VALUES
('r1', 70),
('r2', 40),
('r3', 50),
('r4', 85),
('r5', 30),
('r6', 65),
('r7', 55);

CREATE TABLE Classes
(class_nbr CHAR(2) NOT NULL PRIMARY KEY,
class_size INTEGER NOT NULL
CHECK (class_size > 0));

INSERT INTO Classes (class_nbr, class_size)
VALUES
('c1', 80),
('c2', 70),
('c3', 65),
('c4', 55),
('c5', 50),
('c6', 40);

The “best fit” problem is to assign classes to rooms with the fewest empty chairs in the room and nobody standing. The starting point is to find all the rooms that can hold a particular class.

SELECT room_nbr, class_nbr, (room_size - class_size) AS fit
FROM Classes, Rooms
WHERE class_size <= room_size;

Now, let's try to find the best fits:

WITH RC --- all legal pairs
AS
(SELECT *, (room_size - class_size) AS fit
FROM Classes, Rooms
WHERE class_size <= room_size)

SELECT * -- best fit
FROM RC
WHERE fit = (SELECT MIN(fit)
FROM RC AS RCa
WHERE RC.class_nbr = RCa.class_nbr);

Results
==============
c1 80 r4 85 5
c2 70 r1 70 0
c3 65 r6 65 0
c4 55 r7 55 0
c5 50 r3 50 0
c6 40 r2 40 0

This is very good, but it depends on the data! Slight change in the legal pairs CTE or the data, to allow for spare seating, will invalidate the results.

WITH RC --- all legal pairs with spare room
AS
(SELECT *, (room_size - class_size) AS fit
FROM Classes, Rooms
WHERE class_size < room_size)

SELECT * -- best fit
FROM RC
WHERE fit = (SELECT MIN(fit)
FROM RC AS RCa
WHERE RC.class_nbr = RCa.class_nbr);

Results
=================
c1 80 r4 85 5 ◄ Opps!
c2 70 r4 85 15 ◄ Opps! Duplicate room number!
c3 65 r1 70 5
c4 55 r6 65 10
c5 50 r7 55 5
c6 40 r3 50 10

Anyone want to try for general solution?

Celko: Best fit query or T-Join

$
0
0
Dr. Codd's T-Join

In the Second Version of the relational model in 1990, Dr. E. F. Codd introduced a set of new theta operators, called T-operators, which were based on the idea of a best-fit or approximate equality (Codd 1990). The algorithm for the operators is easier to understand with an example modified from Dr. Codd.

The problem is to assign the classes to the available classrooms. We want (class_size < or <= room_size) to be true after the assignments are made. The first < will allow us a few empty seats in each room for late students; the <= can have exact matches.

Th naive approaches Codd gave were: (1) sort the tables in ascending order by classroom size and then matched the number of students in a class. (2) sort the tables in descending order by classroom size and then matched the number of students in a class.

We start with the following tables:

CREATE TABLE Rooms
(room_nbr CHAR(2) NOT NULL PRIMARY KEY,
room_size INTEGER NOT NULL
CHECK (room_size > 0));

INSERT INTO Rooms
VALUES
('r1', 70),
('r2', 40),
('r3', 50),
('r4', 85),
('r5', 30),
('r6', 65),
('r7', 55);

CREATE TABLE Classes
(class_nbr CHAR(2) NOT NULL PRIMARY KEY,
class_size INTEGER NOT NULL
CHECK (class_size > 0));

INSERT INTO Classes (class_nbr, class_size)
VALUES
('c1', 80),
('c2', 70),
('c3', 65),
('c4', 55),
('c5', 50),
('c6', 40);

The “best fit” problem is to assign classes to rooms with the fewest empty chairs in the room and nobody standing. The starting point is to find all the rooms that can hold a particular class.

SELECT room_nbr, class_nbr, (room_size - class_size) AS fit
FROM Classes, Rooms
WHERE class_size <= room_size;

Now, let's try to find the best fits:

WITH RC --- all legal pairs
AS
(SELECT *, (room_size - class_size) AS fit
FROM Classes, Rooms
WHERE class_size <= room_size)

SELECT * -- best fit
FROM RC
WHERE fit = (SELECT MIN(fit)
FROM RC AS RCa
WHERE RC.class_nbr = RCa.class_nbr);

Results
==============
c1 80 r4 85 5
c2 70 r1 70 0
c3 65 r6 65 0
c4 55 r7 55 0
c5 50 r3 50 0
c6 40 r2 40 0

This is very good, but it depends on the data! Slight change in the legal pairs CTE or the data, to allow for spare seating, will invalidate the results.

WITH RC --- all legal pairs with spare room
AS
(SELECT *, (room_size - class_size) AS fit
FROM Classes, Rooms
WHERE class_size < room_size)

SELECT * -- best fit
FROM RC
WHERE fit = (SELECT MIN(fit)
FROM RC AS RCa
WHERE RC.class_nbr = RCa.class_nbr);

Results
=================
c1 80 r4 85 5 ◄ Opps!
c2 70 r4 85 15 ◄ Opps! Duplicate room number!
c3 65 r1 70 5
c4 55 r6 65 10
c5 50 r7 55 5
c6 40 r3 50 10

Anyone want to try for general solution?

Problem in my query

$
0
0
I have a problem with my query..
This is my orinal code:

Private Sub Form_Load()
Dim SiteCodeName, SiteLocationName

AccntType = DLookup("Usertype", "User", "UserName= [Forms]![LogIn]![txtUserName]")
SiteCodeName = DLookup("SiteCode", "User", "UserName= [Forms]![LogIn]![txtUserName]")
SiteLocationName = DLookup("SiteLocation", "SiteCode", "SiteCode='" & SiteCodeName & "'")
dfsds = MsgBox(SiteLocationName)

Dim SQLSitecode
Dim extSitecode As String
extSitecode = ""

SQLSitecode = "QEmployeeList"
If SiteLocationName Like "Bacolod" & "*" Then
extSitecode = " WHERE SiteCode='" & 292 & "' And Employee.SiteCode= '" & 353 & "'"
Else
extSitecode = " WHERE SiteCode='" & SiteCodeName & "'"
End If
SQLSitecode = SQLSitecode + extSitecode + ";"
Me.RecordSource = SQLSitecode

End Sub


But i got this kind of error.Please see attach file.
Anyone can help me..Thanx in advance..

Attached Images
File Type: jpg problem.JPG (75.6 KB)

after issuing "by force"cmd,Get confused about HADR

$
0
0
hi!

Imagine such a scenario:
1.My hadr primary server is down and unrecoverable.
2.I issue the "db2 takeover hadr on db sample by force" on the standby server. Now, the standby DB works correctly.
3.I stop the DB on the standby server.

here is the problem, when I try to start the DB again:

[db2inst1@host03 ~]$ db2start
01/20/2013 20:33:28 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
[db2inst1@host03 ~]$ db2 activate db sample
DB20000I The ACTIVATE DATABASE command completed successfully.
[db2inst1@host03 ~]$ db2 start hadr on db sample as primary
SQL1767N Start HADR cannot complete. Reason code = "2". START HADR AS PRIMARY cannot be issued on an HADR standby database.
[db2inst1@host03 ~]$ db2 start hadr on db sample as primary by force
SQL1767N Start HADR cannot complete. Reason code = "2".
[db2inst1@host03 ~]$ db2 takeover hadr on db sample by force
SQL1770N Takeover HADR cannot complete. Reason code = "5". Activate the standby database, then issue the takeover command.
[db2inst1@host03 ~]$ db2 activate db sample
DB20000I The ACTIVATE DATABASE command completed successfully.
[db2inst1@host03 ~]$ db2 takeover hadr on db sample by force
SQL1770N Takeover HADR cannot complete. Reason code = "5".


How can I get my DB back??

thanks in advance!

(DB2) select from log file

$
0
0
Hi ,

I came across a DB2 query of the form :
select column1, column2 , column3 from xyz.log
I am confused , how columns can be selected from a log file?
Could DB experts help me please...

if this is possible , could you please give/show me a simple example explaining this...

I tried searching a lot on net for the same but couldn't get any clue...

so, experts pls help... :(

thanks..

Query not Working as Intended

$
0
0
I am trying to make an easy way for users unfamiliar with Access to filter the account transactions in an Access 2010 database to show entries made between two dates. The query (SQL below) is supposed to show the form “FrmEntryDateRange” (picture attached) for the user to enter the dates. Instead it shows the “Enter Parameter Value” form (picture attached). The query is run by clicking a button on the main form. It works the same way when it is run using he Access Run button. The query itself is identical to the query that correctly displays the account transactions unfiltered, except for the WHERE clause. How can I make this work as intended?



SELECT [Account Transactions].*, Categories.*, IIf([Categories].[Income/Expense]="Expense",-([Account Transactions]![Transaction Amount]),[Account Transactions]![Transaction Amount]) AS [Actual Amount], [Account Transactions].[Entry Date]

FROM [Account Transactions] LEFT JOIN Categories ON [Account Transactions].Category = Categories.ID

WHERE ((([Account Transactions].[Entry Date]) Between [Forms]![FrmEntryDateRange]![TextFromDate] And [Forms]![FrmEntryDateRange]![TextToDate]))

ORDER BY [Account Transactions].[Entry Date];

Attached Images
File Type: png entry date form.png (4.6 KB)
File Type: png Parameter Value Form.png (9.4 KB)

Two text boxes in a form to query values in Between X to Y

$
0
0
Hi. I am trying to set up a form with two text boxes so I can run a query that searches for records with values between a two numbers. I have set up 2 text boxes in the form design, they are named AvgAmt0 and AvgAmt2.

In the query design view I was able to produce the desired results by placing the following in the criteria statement of the field titled "Amount":

Between 10 And 50

Because this worked I tried to use the following to have the query reference the two text boxes on my form:

Between [Forms]![Search]![AvgAmtO] And [Forms]![Search]![AvgAmt2]

but this doesn't work, when I run the query I got the whole range from the Amount field from 1 to 10,000. Does anyone know how to do this?

Encryption in db2

$
0
0
Hi,
Few doubts on column encryption.

How do I alter an existing column with varchar data type to take encrypted data values. Waht I understand is we need to change the column data type to 'varchar(***) for bit data'

Encrypting varchar

$
0
0
Hi,
I am on DB2 Version 9.7. I create a table with below definition:

db2 "create table tvar2(name varchar(10))"

and then I try to insert into the above table using below command:

db2 "insert into tvar2 values(encrypt('a'))"

which throws below error:
SQL0433N Value " ~" is too long. SQLSTATE=22001

Why is it not allowing me to insert data into encrypted form?

Is it feasible to restart mssql server 2008 service periodically???

$
0
0
Hello all,

Is it feasible to restart mssql server 2008 service periodically every 10min???
what will be the effect on database, If it is heavy loaded environment.
Please suggest your views.

Thanks in advance. :)

Command inside parameter

$
0
0
Hi colleagues !

Quick question:
How can I run a command inside a parameter ?

I want to use dd and the following formula in the count parameter :
df -m . |awk '{s+=$2} END {print s}'

like:

dd if=/dev/zero of=dummy.file bs=1m count= df -m . |awk '{s+=$2} END {print s}'

Thank you for all support !

Alter table

$
0
0
Hi,
I have already created a table and forgot to add in the first row.
This row should auto-increment, be unique and of type int.

I have tried using the following statements but i keep getting a syntax error.


Code:

alter table 'comp_table'
add column 'comp_id' int not null auto_increment unique first;

Code:

ALTER TABLE 'comp_table' ADD COLUMN 'comp_id' int NOT null
AUTO_INCREMENT FIRST



Can anyone tell me what i am doing wrong?

Thanks.

DB2 backup after license expired

$
0
0
Hi,

I recently discovered that it is not possible to update a db2 trial license on linux 32 bit. The problem is that the license has expired and I can't use db2 anymore. I really need the data in the db! Is it somehow possible to get that data e.g. by copying /home/db2inst1/db2inst1/NODE0000/ or in another way?

JSP class files

$
0
0
Hi,
I have some class files that when I open them with jad, I get some errors like the ones bellow:
"Couldn't fully decompile method ...
Couldn't resolve all exception handlers in method ...
Overlapped try statements detected. Not all exception handlers will be resolved in the method ..."

Does anyone have any idea why this happens?

Thanks,

How to execute files from a single file

$
0
0
Hi All,

I am new in DB2 and want to call many files from one file.

Suppose i am having 1.sql,2.sql,3.sql in a folder.
How can i call these 3 files from a single file ??

Kindly revert me back with the solution.

Thanks In Advance.

Regards
Amal

Basic Join with Rowid

$
0
0
Hi,

I have got a basic question but in my database it will not work.

I have two tables. Both have the similar amount of rows. I want to add one column of the first table into the second table. Here, the values should be in the same order as before. Table1.row1 = Table2.row1; Table1.row2 = Table2.row2 ; Table1.row3 = Table2.row3....Table1.row(n) = Table2.row(n).

The issue is, there is no really connector for a join. I tried with rowid, but no selected row is presented. (permanently is the column I will add)

Code:

SElECT tab.rowid rid
nvl(permanently2, permanently) permanently,
tab2.rowid bum
    from  tab,
            tab2
                where tab.rowid= tab1.rowid;

Thanks

Issues with default Ribbon and Backstage options

$
0
0
I am trying to hide some of the Backstage options (ie.: FILE items) and am running into the following issue:
To use the BACKSTAGE option the ribbon MUST be selected as the default ribbon for the database, otherwise the changes will not be applied. However, when a default ribbon is selected I'm finding that my other custom ribbons (on forms, etc.) are not working. This means I cannot use the BACKSTAGE options to remove/hide any FILE options in conjunction with other custom ribbons. Has anybody else run into this problem?
:S

query returning duplicates

$
0
0
I have written this query which searches the table and return all owners whose surnames are like 'BLACK'. It runs fine but it is returning duplicate rows. I think this may be a problem with my joins. Does anyone have any suggestions?

Code:

SELECT p.person_id FROM person p, owner o, buliding b, person_status ps
WHERE o.owner_id = p.owner_id AND b.building_id = h.building_id
AND p.person_id=ps.status_id AND ps.status_type='H'
and  o.surname LIKE '%BLACK';

Viewing all 13329 articles
Browse latest View live