Showing posts with label system. Show all posts
Showing posts with label system. Show all posts

Thursday, March 29, 2012

creating an existing db schema baseline

What is the best method of creating schema creation scripts that can be
stored into a version control system. The process of using em to
generate a script is not an appealing option. I am still learning the
MS Sql sys tables and have not found a useful list of all the codes &
types to join the tables etc.

mike

--
Posted via http://dbforums.comwukie <member30544@.dbforums.com> wrote in message news:<3242331.1060980041@.dbforums.com>...
> What is the best method of creating schema creation scripts that can be
> stored into a version control system. The process of using em to
> generate a script is not an appealing option. I am still learning the
> MS Sql sys tables and have not found a useful list of all the codes &
> types to join the tables etc.
>
> mike

I don't like the fact that all source code versioning systems are
using proprietary files instead of proven relational databases
(SourceSafe is not exception from this). The reasons for this are
probably RDBMS licensing costs in the past.

Database schema can be exported also as XML file, which can be further
manipulated. If you and your team have serious schema versioning needs
I suggest you to evaluate Meta Data Services in SQL Server 2000 and
XML. One article about this has been published in the MSDN Magazine:
http://msdn.microsoft.com/msdnmag/i...es/default.aspx

Metadata Repository can be created not only through Enterprise Manager
but also programmatically using Meta Data API. Further information
with examples can be found in Meta Data Services SDK 3.0, which can be
downloaded for free.

Sinisa Catic|||found what I was looking for...

in EM > Tools > Generate SQL Scripts. THis will create the total schema
of the existing database.

mike

any known issues with this tool??

--
Posted via http://dbforums.com

Tuesday, March 27, 2012

creating a user stored proc

I'm running mssql 2005. And any stored procedure I create in the master database gets created as system procedures since recently. I have created procs in the master database as user procs previously. As sp_MS_upd_sysobj_category is not supported in mssql 2005, does anyone know why this is happening.. or how I can rectify it?

ThanksCan you post a repro with procedure you are trying to create?|||

there's nothing really special about the proc.. Any proc I create becomes a system proc in the mster db...

e.g.

CREATEPROCEDURE test

AS

BEGIN

print'a'

END

GO

will behave like this.. I don't think this has anything to do with the actual proc I'm trying to use...

Thanks..

|||if you want to create the system stored procedure then use master and create your procedure started with sp_abc other wise create your sp on your desired database.|||There is no supported way to do this in SQL Server 2005. We are considering adding such features that will allow you to deploy SPs in one location and use it in context of multiple databases. For now, you will have to create the SP in each database. For admin type of SPs, you could use dynamic SQL within the SP.|||

I don't actually want to create system procs.. I want to create this proc in the master database and do not want it to be a system proc.. just a normal user proc.. I was able to do so since recently..But I think some thing has gone wrong and now when ever I create a proc, it gets created as a system proc... I did run the sp_MS_upd_sysobj_category with 2 but I understand that it's obsolete now...Any idea how I can turn this off? or atleast how this may have happened?

|||The feature I talked about will allow user SPs to behave like system SPs in terms of resolving object names in context of the db in which the SP is being executed. Anyway, for your problem I am not sure what can be done. The reason why we don't document certain system SPs is because it is for internal use and has severe implications if used incorrectly. I don't know if sp_MS_upd_sysobj_category code has changed in SQL Server 2005 or if it is some other SP call you did. But it looks like you will have to uninstall and install SQL Server or restore master from a last clean backup.

creating a user stored proc

I'm running mssql 2005. And any stored procedure I create in the master database gets created as system procedures since recently. I have created procs in the master database as user procs previously. As sp_MS_upd_sysobj_category is not supported in mssql 2005, does anyone know why this is happening.. or how I can rectify it?

ThanksCan you post a repro with procedure you are trying to create?|||

there's nothing really special about the proc.. Any proc I create becomes a system proc in the mster db...

e.g.

CREATE PROCEDURE test

AS

BEGIN

print 'a'

END

GO

will behave like this.. I don't think this has anything to do with the actual proc I'm trying to use...

Thanks..

|||if you want to create the system stored procedure then use master and create your procedure started with sp_abc other wise create your sp on your desired database.|||There is no supported way to do this in SQL Server 2005. We are considering adding such features that will allow you to deploy SPs in one location and use it in context of multiple databases. For now, you will have to create the SP in each database. For admin type of SPs, you could use dynamic SQL within the SP.|||

I don't actually want to create system procs.. I want to create this proc in the master database and do not want it to be a system proc.. just a normal user proc.. I was able to do so since recently..But I think some thing has gone wrong and now when ever I create a proc, it gets created as a system proc... I did run the sp_MS_upd_sysobj_category with 2 but I understand that it's obsolete now...Any idea how I can turn this off? or atleast how this may have happened?

|||The feature I talked about will allow user SPs to behave like system SPs in terms of resolving object names in context of the db in which the SP is being executed. Anyway, for your problem I am not sure what can be done. The reason why we don't document certain system SPs is because it is for internal use and has severe implications if used incorrectly. I don't know if sp_MS_upd_sysobj_category code has changed in SQL Server 2005 or if it is some other SP call you did. But it looks like you will have to uninstall and install SQL Server or restore master from a last clean backup.

Thursday, March 22, 2012

Creating a Subtotal of select Groups

Hi,

I am working on a new reporting system using reporting services, but I cannot figure out how to create a footer row which will only subtotal select group totals. If anyone has a method to do this please help!

Nathan

If you have a matrix report right click on the group and select the option subtotal.
If you have a tabular report right click on the left side of the table and select table footer. Then in each field you want to summarize put = SUM(Fields!FieldName.Value)
That's all|||

I've been able to do that for individual groups, but what I want to do is make footer subtotal of a select set of groups. So say I have data grouped by Credit card type. I have a group for MC, and another for Visa, and another for American express.

I want a footer total of just the MC and Visa groups, excluding the total for American express.

|||You could use an expression similar to this in the footer (it will add 0 instead of the actual amount if the card was Amex):
=Sum(iif(Fields!CardType.Value = "Amex", 0, Fields!TransactionAmount.Value))

--Robert|||Alright!

Thank you Robert. you made my day Smile|||


When running this selective sum, i get a scope error. I have tried giving it a group name and a dataset. What am i doing wrong? here is my code:

=Sum(iff(Fields!CardType.Value = "Visa/Mc" OR Fields!cardType.Value = "Diner" OR Fields!cardType.Value = "JCB", Fields!amount.Value, 0))
This is my error:

"The value expression for the textbox ‘textbox9’ refers to the field ‘CardType’. Report item expressions can only refer to fields within the current data set scope or, if inside an aggregate, the specified data set scope."

Whats wrong?

|||I have the same problem. I don't want to sum a select number of groups, but all groups within the report. The principle is the same as the above, and I get the same scope error.
In my case I have a bunch of items grouped by customer. Each customer has a subtotal, and I want to have a grand total of all the customers.
Any ideas/workarounds?|||Note: Field names are case-sensitive. In your expression it seems like you have upper-case and lower-case "CardType" fields.
Also, are the cardType field and the amount field in the same dataset?

-- Robert|||If you want to get the grand total, you just need to specify either the data region name (i.e. table, list, or matrix report item name) or the data set name.
E.g.
=Sum(Fields!Amount.Value, "DataSet1")

-- Robert|||Thanks, Robert! I knew it had to be something simple. Smile|||Hi, somehow related with the topic:
Is posible to have something like: the sum of the ValueField from all the rows of DataSet2 that have CompareFiled equal with the current value of ComparedWithField from DataSet1?
In other words: in the expression of the SUM function can be used more then one scope?
=Sum(iff( DS2!Fields!CardType.Value = Fields!CT.Value, DS2!Fields!amount.Value, 0))

Wednesday, March 21, 2012

Creating a SQL MAX command

Hello All,

I'm currently in the process of developing a new PO system for work. What I need to accomplish is a SQL MAX command to find the largest PO number and then add 1 to that number. I'm then saving this in a session state so users can create multiple items for that same PO number. Here's what I have so far:

1protected void Page_Load(object sender, EventArgs e)2 {3// connection string to your database4 SqlConnection mySqlConnection =new SqlConnection("server=(local)\\SQLEXPRESS;database=Purchasing;Integrated Security=SSPI;");56// create command object to execute query7 SqlCommand mySqlCommand = mySqlConnection.CreateCommand();89// set command text to the INSERT sql query10 mySqlCommand.CommandText ="SELECT MAX(PONumber)FROM ItemMaster;";1112// open connection13 mySqlConnection.Open();1415// execute query1617int newPO1 = (int) mySqlCommand.ExecuteScalar();18int newPO = newPO1 + 1;1920// close connection21 mySqlConnection.Close();2223//Response.Write(newPO);24 Session["newPO"] = newPO.ToString();2526 }

I copied and modified the ExecuteScalar() command from another thread in another fourm, but continue to receive this error:

System.InvalidCastException: Specified cast is not valid.

Source Error:

Line 30: // execute queryLine 31:Line 32: int newPO1 = (int) mySqlCommand.ExecuteScalar();Line 33: int newPO = newPO1 + 1;Line 34:

I'm not sure what i'm doing wrong, any help to point me in the right direction would be greatly appreciated.

Thank you in advance

Instead of using (int), try Convert.ToInt32

Convert.ToInt32(mySqlCommand.ExecuteScalar());
|||

That did the trick, only thing is my logic must be incorrect somewhere. For each line item I add its adding another digit to the PO number. What I need it to do is create a new PO number and stick with that one throughout the session...but then when the user finishes the PO and wants to start a new one thats when it adds 1 to the max PO number. Any Ideas? I thought putting the code in the Protected void Page_Load would do the trick but apparently not.

|||

Hi GIZM,

I have some code here..

If u find this is useful mark it as answer

qlConnection con=new SqlConnection();
con.ConnectionString=System.Configuration.ConfigurationManager.AppSettings["strcon"];
con.Open();
SqlCommand cmd = new SqlCommand("select max(fdcatid) from maincate", con);

//SqlDataAdapter ad = new SqlDataAdapter(cmd);
int f0 = (int)cmd.ExecuteScalar();
int f1 = f0 + 1;
con.Close();
Session["f1"] = f1.ToString() ;
Response.Write(f0);

|||

Hey Raja,

That looks to be a lot like what I have in my code, I just cant figure out where to put it. As of right now, I have it on page load, and then later in the page I have a insert statement to add lines to the data table. Every time a user would update a line item I guess the page is reloading causing the PONumber to increase. I only want the number to increase after the page is redirected to my confirmation page and then back, or if the browser is closed and reopened.

|||

I wonder if I could pull this off using the "is post back" thing?

Monday, March 19, 2012

Creating a random password.

I'm new to SQL and have no training. Just trying to learn this on my
own.
I've got a system that grabs new users from 1 table and inserts them
into a user table for a diff. system. I need to be able to assign them
a random password. I've got code that will do this using NEWID() and
RAND() functions and works fine in Query analyser. But if I try to
write a function, I find I can't have NEWID() and RAND() in a UDF. I
can write this as a Procedure, but can't figure out complete syntax of
Proc. or how to call it in my SQL update command.
SQL update command is:
UPDATE clientaccess SET password= dbo.makepassword()
WHERE password = ''
of course, that's calling it as a function. How do I call a Proc in
same UPDATE code?
Here's code as function. How would I change to proc and call?
CREATE function dbo.GenerateRandomString ()
RETURNS char(8)
As
Begin
declare @.password char(8)
declare @.choices varchar(100)
declare @.count int
set @.choices = ''
-- load up numbers 0 - 9
set @.count = 48
while @.count <=57
begin
set @.choices = @.choices + Cast(CHAR(@.count) as char(1))
set @.count = @.count + 1
end
-- load up lowercase letters a - z
set @.count = 97
while @.count <=122
begin
set @.choices = @.choices + Cast(CHAR(@.count) as char(1))
set @.count = @.count + 1
end
set @.count = 0
set @.password = ''
while @.count <= 8
begin
set @.string = @.string +
SUBSTRING(@.choices,CAST(ABS(CHECKSUM(NEW
ID()))*RAND(@.count)
as int)%LEN(@.choices)+1,1)
set @.count = @.count + 1
end
RETURN(@.password)
endTry putting the UPDATE in the proc definition and passing the account and
password as parameters. Note however that the end-user should change the
password (sp_password) ASAP as this approach is not very secure. Also, just
as an added "slight" layer of security , I'd recommend you use WITH
ENCRYPTION for the proc.
HTH
Jerry
<jfeldbruegge@.yahoo.com> wrote in message
news:1129045975.003145.224220@.g44g2000cwa.googlegroups.com...
> I'm new to SQL and have no training. Just trying to learn this on my
> own.
> I've got a system that grabs new users from 1 table and inserts them
> into a user table for a diff. system. I need to be able to assign them
> a random password. I've got code that will do this using NEWID() and
> RAND() functions and works fine in Query analyser. But if I try to
> write a function, I find I can't have NEWID() and RAND() in a UDF. I
> can write this as a Procedure, but can't figure out complete syntax of
> Proc. or how to call it in my SQL update command.
> SQL update command is:
> UPDATE clientaccess SET password= dbo.makepassword()
> WHERE password = ''
> of course, that's calling it as a function. How do I call a Proc in
> same UPDATE code?
> Here's code as function. How would I change to proc and call?
> CREATE function dbo.GenerateRandomString ()
> RETURNS char(8)
> As
> Begin
> declare @.password char(8)
> declare @.choices varchar(100)
> declare @.count int
> set @.choices = ''
> -- load up numbers 0 - 9
> set @.count = 48
> while @.count <=57
> begin
> set @.choices = @.choices + Cast(CHAR(@.count) as char(1))
> set @.count = @.count + 1
> end
> -- load up lowercase letters a - z
> set @.count = 97
> while @.count <=122
> begin
> set @.choices = @.choices + Cast(CHAR(@.count) as char(1))
> set @.count = @.count + 1
> end
> set @.count = 0
> set @.password = ''
> while @.count <= 8
> begin
> set @.string = @.string +
> SUBSTRING(@.choices,CAST(ABS(CHECKSUM(NEW
ID()))*RAND(@.count)
> as int)%LEN(@.choices)+1,1)
> set @.count = @.count + 1
> end
> RETURN(@.password)
> end
>|||Hi
NewID is a nondeterministic function and can't be used in a function, RAND
seems to cause issues even though it has a seed. To overcome this problems
you could pass a NEWID and Random number to the function, but that would be
less secure than using a different one for each character.
One solution when using a procedure is to loop or cursor for each row to
update:
CREATE PROCEdURE dbo.GenerateRandomString (@.password VARCHAR(8) OUTPUT)
AS
BEGIN
declare @.choices varchar(100)
declare @.count int
set @.choices = ''
-- load up numbers 0 - 9
set @.count = 48
while @.count <=57
begin
set @.choices = @.choices + Cast(CHAR(@.count) as char(1))
set @.count = @.count + 1
end
-- load up lowercase letters a - z
set @.count = 97
while @.count <=122
begin
set @.choices = @.choices + Cast(CHAR(@.count) as char(1))
set @.count = @.count + 1
end
set @.count = 0
set @.password = NULL
while @.count <= 8
begin
set @.password = ISNULL(@.password,'') +
SUBSTRING(@.choices,CAST(ABS(CHECKSUM(NEW
ID()))*RAND(@.count)
as int)%LEN(@.choices)+1,1)
set @.count = @.count + 1
end
END
-- Example table
CREATE TABLE clientaccess ( username varchar(40) NOT NULL, password char(8)
NOT NULL DEFAULT ('') )
-- Example data
INSERT INTO clientaccess ( username ) values ( 'john' )
INSERT INTO clientaccess ( username ) values ( 'jim' )
INSERT INTO clientaccess ( username ) values ( 'jack' )
SELECT * FROM clientaccess
DECLARE @.password varchar(8), @.username varchar(40)
DECLARE user_cursor CURSOR FOR
SELECT username
FROM clientaccess
WHERE ISNULL(password,'') = ''
OPEN user_cursor
FETCH NEXT FROM user_cursor INTO @.username
WHILE @.@.FETCH_STATUS = 0
BEGIN
SET @.password = ''
EXEC dbo.GenerateRandomString @.password OUTPUT
UPDATE clientaccess
SET password = @.password
WHERE CURRENT OF user_cursor
FETCH NEXT FROM user_cursor INTO @.username
END
CLOSE user_cursor
DEALLOCATE user_cursor
GO
SELECT * FROM clientaccess
John
"jfeldbruegge@.yahoo.com" wrote:

> I'm new to SQL and have no training. Just trying to learn this on my
> own.
> I've got a system that grabs new users from 1 table and inserts them
> into a user table for a diff. system. I need to be able to assign them
> a random password. I've got code that will do this using NEWID() and
> RAND() functions and works fine in Query analyser. But if I try to
> write a function, I find I can't have NEWID() and RAND() in a UDF. I
> can write this as a Procedure, but can't figure out complete syntax of
> Proc. or how to call it in my SQL update command.
> SQL update command is:
> UPDATE clientaccess SET password= dbo.makepassword()
> WHERE password = ''
> of course, that's calling it as a function. How do I call a Proc in
> same UPDATE code?
> Here's code as function. How would I change to proc and call?
> CREATE function dbo.GenerateRandomString ()
> RETURNS char(8)
> As
> Begin
> declare @.password char(8)
> declare @.choices varchar(100)
> declare @.count int
> set @.choices = ''
> -- load up numbers 0 - 9
> set @.count = 48
> while @.count <=57
> begin
> set @.choices = @.choices + Cast(CHAR(@.count) as char(1))
> set @.count = @.count + 1
> end
> -- load up lowercase letters a - z
> set @.count = 97
> while @.count <=122
> begin
> set @.choices = @.choices + Cast(CHAR(@.count) as char(1))
> set @.count = @.count + 1
> end
> set @.count = 0
> set @.password = ''
> while @.count <= 8
> begin
> set @.string = @.string +
> SUBSTRING(@.choices,CAST(ABS(CHECKSUM(NEW
ID()))*RAND(@.count)
> as int)%LEN(@.choices)+1,1)
> set @.count = @.count + 1
> end
> RETURN(@.password)
> end
>

Sunday, March 11, 2012

Creating a normalized database

Hi. I have a project I need to complete and I really don't know the first step I should take. Basically, we have a case management system that is normalized for the most part except for one major flaw: the clients table. Whenever we add a new case, we have to add the customer's name/address/phone etc. all over again. I would like to redo this current setup so we have one table just for clients and another table just for cases, so we don't have all this double entering all the time. Is there an easy way to do this or could someone point me in the right direction? It's on a SQL Server 2000 database. Thanks for your help!4 easy steps

CREATE the client table (ClientID, ClientName, Address...)

SELECT DISTINCT Client info from the case table into the new Client Table

Build Relationship between the 2 tables (on ClientID)

DELETE the redundant columns from case table|||You can use a ClientCase table with a many to many relationship between your Clients and your Cases tables.


Clients ClientCase Case
------ ------ ------
CliNumber --> CliNumber
CaseNumber <-- CaseNumber
Cliname CaseLeadAtty
CliAddress CaseSecondAtty


etc.|||tomh53,

Just curious...
What would be the need for the intermediate table, unless
one case number can have multiple clients?|||... unless one case number can have multiple clients?if a case only and forever belongs to only one client, then yeah, you don't need the many-to-many relationship table

however, note that you can implement a one-to-many relationship using a many-to-many relationship table -- just make sure (in your app logic) that you never store more than one client per case!!

then, when the day comes, and the case rolls in which requires two clients, you're all set!!

:) :)|||tomh53,

Just curious...
What would be the need for the intermediate table, unless
one case number can have multiple clients?

How about a class-action lawsuit?|||4 easy steps

CREATE the client table (ClientID, ClientName, Address...)

SELECT DISTINCT Client info from the case table into the new Client Table

Build Relationship between the 2 tables (on ClientID)

DELETE the redundant columns from case table
Thank you! That worked like a charm. I still have a few duplicates but it beats going through all of them manually. :)

Thursday, March 8, 2012

Creating a log file

I have a system which has several different dbases involved, and have created an update procedure within it all. It all works fine, but as a refrenence point I want to create a log file,each time the procedure is run.

This file will have useful info such as no of transactions added, no of product row n customer rows, any unmatching entries and any exception records. What I dont know is how do I create such a file?

I was thinking maybe I could save the info into a table, and then somehow transfer this into a txt file? The txt file will be replaced each time the stored procedure is run... Does any1 know any links or ideas that might help me?...I never does anything lik this b4 but I have seen it done....

Thanks in advance!found a perfect article for you
http://www.codeproject.com/useritems/Stored_Procedure_Log_File.asp

:beer: :beer: :beer:|||It might be my paranoia, but I'm not all that happy with the proposed solution. xm_cmdshell is after all among the most severe security risks in SQL Server. Would it not be a better choice to have a log TABLE instead? You could always script a command line tool to transfer the data to a text file on a regular basis.|||Thanks for the replies!!! !

roac, do you have an example site that does something like what you are sayin!!!

I really cant seem to find anything useful on the net?!|||what he meant to say is you have a log table something like

table_log
(logid identity key,
description --description will contain all relevant data you require
)

add a few more relevant columns.....

and each time then, u keep on updating this log table...so instead of having a log file u have a log table and u then need to query this table to get the description as to how many rows were inserted/updated

and his suggestion is the best way out....however if you want a log then u will have to xp_cmdshell :D|||"You could always script a command line tool to transfer the data to a text file on a regular basis."

how do i do this bit??|||"You could always script a command line tool to transfer the data to a text file on a regular basis."

how do i do this bit??
You might look at BCP, which can extract data from a table to a file. It's pretty well documented in Books Online I recall. You can use task scheduler in Windows or a SQL Server Agent Job to schedule it.|||Another alternative would be to use the SQL Server Job Agent to run the job, and include in the stored procedure/code it runs such things as "Print 'whatever data I want to log" and then have the SQL Server agent write the job output to a log.

You can use the "print" statement within the stored procedures OR the job step command window and it will be captured in the output log.

That way you can put the log anywhere on the network you want it to go, name it anything you want to name it, and not have to code anything special to create the log.

This is easily done by entering the code in the job step "command" box, similar to the following, which is a cut and past from one of our maintenance jobs.
DELETE
FROM EventLog
WHERE DATEDIFF(day, [Date], getdate()) > 90

PRINT CONVERT(varchar(10), @.@.ROWCOUNT) + ' old rows were deleted.'

DECLARE @.Count int
SELECT @.Count = (SELECT COUNT(*) FROM EventLog)
PRINT CONVERT(varchar(10), @.Count) + ' rows remain in the table.'
PRINT ' ++ JOB COMPLETE ++'
In the "advanced" tab of the step there is a place where you can enter the path/filename of the "output" file, which then becomes the log you so desperately desire.

This is the output cut and pasted from the generated log file:Job 'DailyProd- Weekly EventLog Cleanup' : Step 1, 'Delete From EventLog Where Older Than 90 Days' : Began Executing 2005-06-09 15:45:06

2244 old rows were deleted. [SQLSTATE 01000]
334 rows remain in the table. [SQLSTATE 01000]
++ JOB COMPLETE ++ [SQLSTATE 01000] and you can set up the job to overwrite the log file each time it runs, or append to the log file each time it runs.|||thanks SO much!!!

I've jsut tested it and its worked fone...
(I used the PRINT command that TallCowboy0614 spoke about)

2 questions:
1) Is there any way of inserting blank lines so that it is easier to read?
2) How do I get it to stop adding '[SQLSTATE 01000]' after each line?

Thanks again|||I think adding a PRINT ' ' (to print a blank line) will allow you that capability.

I don't think there is any way to avoid the [SQLSTATE 01000] at the end of each line, though - using this method, at least. At least if there is, I haven't been bothered by it enough to search for and/or implement it.|||'I think adding a PRINT ' ' (to print a blank line) will allow you that capability.'

I thought thats what it would be, but it didnt wrk...
also tried PRINT char(13) + char(10) but it doesnt wrk either...

:confused:|||Try a couple of them in sequence. I also have noticed sometimes stuff like that (formatting I try to do) doesn't seem to work as expected. I do get mixed results with both methods you describe though. Again, it hasn't been enough of an issue in my applications to put much thought and time into fixing it.

Creating a list of SQL Server Agent Job Status in RealTime

Essentially I want to replicate the functionality of the SQL Agent Job Monitor.

I am trying to find the correct system view or stored procedure to get a list of SQL Agent Jobs that are executing. Similar to what you would see when you use the SQL Agent Job Monitor to oversee SQL Agent Job execution. (I have verified that I have sysadmin permissions.)

There is a stored procedure called msdb.dbo.sp_help_jobactivity however it still does not return information on currently running jobs. There is a system table called 'sysjobactivity' that contains job information but not the runtime status of jobs. In the BOL there is a detailed list of all of the tables that SQL Server Agent uses...but none of them seem to give runtime information.

Do I need to join the sysjobactivity table to some other process table to get realtime status?

...cordell...

This should get you started:
http://www.microsoft.com/technet/abouttn/flash/tips/tips_060804.mspx

...except that the author is wrong. You can't run sp_help_job into a table because it calls a nested stored proc.

This, however, should actually work:

declare @.job_owner_name varchar(100)
set @.job_owner_name = '' -- insert job owner name here, required for extended stored proc

if OBJECT_ID('tempdb..#xp_results') is not null
drop table #xp_results

CREATE TABLE #xp_results
(job_id UNIQUEIDENTIFIER NOT NULL,
last_run_date INT NOT NULL,
last_run_time INT NOT NULL,
next_run_date INT NOT NULL,
next_run_time INT NOT NULL,
next_run_schedule_id INT NOT NULL,
requested_to_run INT NOT NULL,
request_source INT NOT NULL,
request_source_id sysname COLLATE database_default NULL,
running INT NOT NULL,
current_step INT NOT NULL,
current_retry_attempt INT NOT NULL,
job_state INT NOT NULL)

insert into #xp_results
exec master.dbo.xp_sqlagent_enum_jobs 1, @.job_owner_name

select name, * from #xp_results rj
inner join msdb.dbo.sysjobs sj
on sj.job_id = rj.job_id
where rj.running = 1

Creating a list of SQL Server Agent Job Status in RealTime

Essentially I want to replicate the functionality of the SQL Agent Job Monitor.

I am trying to find the correct system view or stored procedure to get a list of SQL Agent Jobs that are executing. Similar to what you would see when you use the SQL Agent Job Monitor to oversee SQL Agent Job execution. (I have verified that I have sysadmin permissions.)

There is a stored procedure called msdb.dbo.sp_help_jobactivity however it still does not return information on currently running jobs. There is a system table called 'sysjobactivity' that contains job information but not the runtime status of jobs. In the BOL there is a detailed list of all of the tables that SQL Server Agent uses...but none of them seem to give runtime information.

Do I need to join the sysjobactivity table to some other process table to get realtime status?

...cordell...

This should get you started:
http://www.microsoft.com/technet/abouttn/flash/tips/tips_060804.mspx

...except that the author is wrong. You can't run sp_help_job into a table because it calls a nested stored proc.

This, however, should actually work:

declare @.job_owner_name varchar(100)
set @.job_owner_name = '' -- insert job owner name here, required for extended stored proc

if OBJECT_ID('tempdb..#xp_results') is not null
drop table #xp_results

CREATE TABLE #xp_results
(job_id UNIQUEIDENTIFIER NOT NULL,
last_run_date INT NOT NULL,
last_run_time INT NOT NULL,
next_run_date INT NOT NULL,
next_run_time INT NOT NULL,
next_run_schedule_id INT NOT NULL,
requested_to_run INT NOT NULL,
request_source INT NOT NULL,
request_source_id sysname COLLATE database_default NULL,
running INT NOT NULL,
current_step INT NOT NULL,
current_retry_attempt INT NOT NULL,
job_state INT NOT NULL)

insert into #xp_results
exec master.dbo.xp_sqlagent_enum_jobs 1, @.job_owner_name

select name, * from #xp_results rj
inner join msdb.dbo.sysjobs sj
on sj.job_id = rj.job_id
where rj.running = 1

Wednesday, March 7, 2012

Creating a double entry book keeping system

Can anyone please tell me how to create a basic double entry book keeping system database using SQL Server or Access. I need to know what tables amd fields I need to create, and what relationships need to be defined. I just need to know the db structure here. Also how should I go about designing the forms ( I use visual Basic 2005 Express and SQL Server 2005 Express, and Access 2002 ), the front end user interface for creating journal entries, how should I display the ledgers, and how do I calculate the totals for the ledgers, because we also need to take into consideration the opening and closing balances as well.

I tried a lot using Access, but I could not get a satisfactory result. I first created a account base type table which has the four account types - assets, liabilities, expenses, and incomes, linked to aother table which stores the actual account types classifications ( which is actually used only for grouping purposes in the reports ), which in turn is linked to the accouts table which has the names of all the accounts. Now I tried to create a journal whose debit a/c name is linked to the accounts table, and the credit a/c name also has to be linked to the same field of the same table ( i.e the accounts table ). Now when I tried to create a ledger (form) which shows all the corresponding transactions for an account, i couldn't proceed further and got stuck, because I don't know what to do here. Also I would like to 'store' all the ledger transations in a separate table, and not just keep it as a display of the collection of queries created from journal entries (as I have attempted up till now).

( If you guys need to take a look at my access db, I could send it over to you. Its barely 550 something kb. I could zip it further. Is there any way we can attach files to threads on this forum ? )

Can someone please help me out here. ( Instructions using the GUI tools would be appreciated )

Also if I get the tables, fields and relations in Access right, I could replicate the same in SQL Server.

You seem to me to be asking for questions relating to your business rules, and not to application development. You should design the tables so that they are normalised, and so that they reflect your business rules. You will probably find that VB.NET is more flexibile in UI design than Access, but again, you would go about designing the forms by making sure that they reflect the data you want to collect and are reasonably self documenting.

You should not create a table to store data which you can derive from existing tables, that would be denormalising your database, creating duplicate data, and potential problems.

|||You're right, I shouldn't be denormalising the database by storing data derived from existing tables. But I'm not asking questions related to business rules. I am asking how should I design the database - what tables, fields and relations should I use ? And how should I design the UI for the journal and ledger ? I ultimately plan to use VB Express for designing the UI. I just asked for help using Access because I'm more familiar with it than with VB (which I'm still learning ) , and I could use it for the time being to understand my queries.|||

How to create a table is a programming question. What your tables look like is definitely a business rule question, one that can only be answered by people who know what data you're trying to store and how you intend to use that data.

How the UI should look is really not something that anyone can answer in words anyhow, and is again dependent entirely on what data you're storing and what you want to do with it. Unless you're asking which to use out of VB and Access, or how to create a UI in Access ( which is such a broad question that I'd start with some online tutorials and then ask specific questions from there ) ?

I'd love to help, but in the first instance, I really have no idea what to tell you. What's a double entry book keeping system ? What data are you storing ? What actions do you want to perform ? What do you want to be told about your UI ? Can you not envisage how it should look based on what you want it to do ? Is Access the best choice for a database here, anyway ? How much data are you likely to store ?

|||

Oh! I see your situation here cgraus. It seems that you are a science grad and I have a comerce background. The double entry book keeping system was invented in France in the 18th century and is the standard method worldwide which is used to store financial information of any entity, business or non business, using 'accounts' in which each financial transaction has two effects - debit and credit. Hence the term 'double entry'. So, as a simple example of the double entry mechanism - if you purchase something, purchase account would be debited, because it is coming into the entity, and cash account would be credited, as cash is going out of the entity.

So, if anyone is familiar with the double entry system, they would know what I am talking about in my first post. Besides, if you guys, as programmers, develop applicaitons for large organisations, you should be familiar with the accounting systems, as they are one of the primary requirements of any organisation.

|||

Rishi Khetan wrote:

Oh! I see your situation here cgraus. It seems that you are a science grad and I have a comerce background. The double entry book keeping system was invented in France in the 18th century and is the standard method worldwide which is used to store financial information of any entity, business or non business, using 'accounts' in which each financial transaction has two effects - debit and credit. Hence the term 'double entry'. So, as a simple example of the double entry mechanism - if you purchase something, purchase account would be debited, because it is coming into the entity, and cash account would be credited, as cash is going out of the entity.

So, if anyone is familiar with the double entry system, they would know what I am talking about in my first post. Besides, if you guys, as programmers, develop applicaitons for large organisations, you should be familiar with the accounting systems, as they are one of the primary requirements of any organisation.

Yeah. . . we use peachtree. @. US$1200 it would certainly take our company many more than 12 manhours to even begin writing anything close to robust.|||

*grin* actually, I'm not a graduate at all, I'm self taught. But yes, you get my point, you're asking about things that don't really relate to programming, but to the system you're trying to create.

It's a bit of a common mistake to assume that all programmers work on accounting systems. In fact, I work on websites, image processing programs, databases, code libraries, but nothing accounting wise, not ever.

The core thing I guess is that you need to use transactions to make sure that your 'double entry' is a single operation that succeeds or fails. Beyond that, if you need help in designing the tables, you'd need to say what you're trying to store.

|||

Yeah, the cost effectiveness of buying an existing tool/class library is often lost on programmers :-)

|||

*grin* actually, I'm not a graduate at all, I'm self taught.

Great, that actually happens to be my philosophy as well . And even I'm not a graduate, I'm still an undergrad.

I think I should go into a bit more detail here, for those who don't know about accounting systems. As I mentioned, there are two effects for every financial transaction - debit and credit. Every transaction is related to an account. An account stores all the financial info of a particular item. For example you have the cash a/c which tells you about all the cash transactions that you have had, bank a/c which gives you details of all your transactions using your actual bank account ( the two are different ), accounts for different assets that you purchase, that keep track of how much of that asset was purchased, how much had to be sold etc. Then you have the various accounts for the heads of incomes and expenses that you have. These give details of which incomes and expenses you incurred at what dates and what amounts. Now whenever a transaction takes place, it has two effects - one account is debited with a certain amount and another account is credited with the equal amount because there are always atleast two accounts related to every transaction. When you buy something, as per my earlier example, you have an asset coming in your hands, and cash ( or a cheque which means the bank a/c ) going out. So the entry would be to debit the asset account with the purchase amount and to credit the cash a/c with the same amount. Now for storing any financial transaction, we have a book, which stores the base transaction, which is called the journal. So you enter the debited and credited accounts along with the amount and the date into this journal. Now, to make a meaningful picture of all the transactions you have entered in the journal, you need to 'post' them into the accounts' respective ledgers. So the ledger of the cash a/c would list on the left hand side ( debit side ) side, all the sales related transactions, and all income related transactions, because in these transactions, in the journal, the cash account is debited. In the right hand side of the cash a/c ( credit side ), all transactions relating to purchase, expenses etc are stored, as the cash a/c is credited here ( as seen in the above example ). Then you need to total the amounts on both the debit and the credit side periodically, to get the cash balance you have If the total of the debit side of the cash account is more than total of the credit side (which should be the case since you cannot have a negative cash balance), then total of debit side minus total of credit side gives you the cash balance. Now, without computers and RDBMSes, people used to actually write down the journal entries first and manually create the accounts in ledgers in large books and post the entries there and then total all the accounts. This would also lead to duplication of effort, you need to write the same thing twice while posting. But with a computerised system, you only need to enter the journal entry and the system automatically posts the transactions to the ledger and totalls all the accounts in real time to tell you the balances you have on hand for each account. Now there are quite a few good accounting software out in the market, and I am even aware of a few designed using access as well, but I am looking to create a larger database system of which the accounting system is only a part and which stores info about a lot of other aspects of a business, so I wouldn't be able to use these other software. I am just stuck on the accounting part of the database.

|||

It seems to me that you have a good understanding of the business rules here, so you seem the best person to design the tables :-)

If you're building a larger system, is Access the best choice for a database ?

|||

Now there are quite a few good accounting software out in the market, and I am even aware of a few designed using access as well, but I am looking to create a larger database system of which the accounting system is only a part and which stores info about a lot of other aspects of a business, so I wouldn't be able to use these other software.

Really? Sounds like your team needs a Systems Engineer with some integration experience.

|||

It seems to me that you have a good understanding of the business rules here, so you seem the best person to design the tables :-)

Actually, as I mentioned Christian, I am still in college, undergoing studies in the commerce field. And I do not have much knowledge of programming, I just know how to use Access and a bit of HTML. I am trying to learn SQL Server Express and VB Express. And, I most certainly do not intend to use Access for creating the entire system, I am going to use SQL Server and VB Express. Its just that creating tables and relationships in Access is faster ( I have a slow system, need to buy a faster one in a couple of weeks time ) and I will understand it better using Access' example, and then I will recreate the whole thing using the GUI tools in SQL Server. Actually I did try to take assistance from the 'Accounts' template in Access, but couldn't make much headway using that either. I couldn't understand many of the fields they put in their tables. I think I will check out that template once more, to see if I can find anything of substance there. Meanwhile, if someone knows the solution to my problem, could you please help me out ?

No team here Blair, I'm the sole team member here, a one man army. Actually I'm just an amateur hobbyist, and I'm trying to build a complete ERP solution for my Dad's business, I've been trying to persuade him to get it computerised for a long time. Don't worry, its not a large project, the business is a proprietory concern with no employees ( not counting peons ) and is limited to a single computer, but has multiple operations and data requirements. No internet connectivity or setting up a web server for accesing the data remotely here, its just for internal access.

|||

So is your question really how to create tables and relationships using SQL in SQL Server ? That would be a programming question. I doubt very much that anyone here is going to design your database for you, and it's still quite frankly impossible to do so based on the information you have provided.

|||

No, my question is not how to create tables and relationships using SQL in SQL Server. My question is ( to anybody who knows both the accounting methods and principles, and SQL and RDBMS theories ) what tables do I create, what fields do I create in them and which relationships should I create, so that I can get the basic journal and ledger functionality of an accounting system.

|||

I think the point is, it is not as simple as you think it is. We could fill up an entire forum just for hashing out this business solution.

What I would suggest is searching sourceforge.net for some freeware to get an idea on how others have approached this particular situation. You might even find a solution you can employ in its entirety or customize to your needs.

We can offer general help, such as how to design/create/use/manipulate databases/tables/relationships/triggers in general, But particular solutions, to seriously complex issues such as a functional accounting system, I believe are beyond the scope of the developer forums.

Creating a double entry book keeping system

Can anyone please tell me how to create a basic double entry book keeping system database using SQL Server or Access. I need to know what tables amd fields I need to create, and what relationships need to be defined. I just need to know the db structure here. Also how should I go about designing the forms ( I use visual Basic 2005 Express and SQL Server 2005 Express, and Access 2002 ), the front end user interface for creating journal entries, how should I display the ledgers, and how do I calculate the totals for the ledgers, because we also need to take into consideration the opening and closing balances as well.

I tried a lot using Access, but I could not get a satisfactory result. I first created a account base type table which has the four account types - assets, liabilities, expenses, and incomes, linked to aother table which stores the actual account types classifications ( which is actually used only for grouping purposes in the reports ), which in turn is linked to the accouts table which has the names of all the accounts. Now I tried to create a journal whose debit a/c name is linked to the accounts table, and the credit a/c name also has to be linked to the same field of the same table ( i.e the accounts table ). Now when I tried to create a ledger (form) which shows all the corresponding transactions for an account, i couldn't proceed further and got stuck, because I don't know what to do here. Also I would like to 'store' all the ledger transations in a separate table, and not just keep it as a display of the collection of queries created from journal entries (as I have attempted up till now).

( If you guys need to take a look at my access db, I could send it over to you. Its barely 550 something kb. I could zip it further. Is there any way we can attach files to threads on this forum ? )

Can someone please help me out here. ( Instructions using the GUI tools would be appreciated )

Also if I get the tables, fields and relations in Access right, I could replicate the same in SQL Server.

You seem to me to be asking for questions relating to your business rules, and not to application development. You should design the tables so that they are normalised, and so that they reflect your business rules. You will probably find that VB.NET is more flexibile in UI design than Access, but again, you would go about designing the forms by making sure that they reflect the data you want to collect and are reasonably self documenting.

You should not create a table to store data which you can derive from existing tables, that would be denormalising your database, creating duplicate data, and potential problems.

|||You're right, I shouldn't be denormalising the database by storing data derived from existing tables. But I'm not asking questions related to business rules. I am asking how should I design the database - what tables, fields and relations should I use ? And how should I design the UI for the journal and ledger ? I ultimately plan to use VB Express for designing the UI. I just asked for help using Access because I'm more familiar with it than with VB (which I'm still learning ) , and I could use it for the time being to understand my queries.|||

How to create a table is a programming question. What your tables look like is definitely a business rule question, one that can only be answered by people who know what data you're trying to store and how you intend to use that data.

How the UI should look is really not something that anyone can answer in words anyhow, and is again dependent entirely on what data you're storing and what you want to do with it. Unless you're asking which to use out of VB and Access, or how to create a UI in Access ( which is such a broad question that I'd start with some online tutorials and then ask specific questions from there ) ?

I'd love to help, but in the first instance, I really have no idea what to tell you. What's a double entry book keeping system ? What data are you storing ? What actions do you want to perform ? What do you want to be told about your UI ? Can you not envisage how it should look based on what you want it to do ? Is Access the best choice for a database here, anyway ? How much data are you likely to store ?

|||

Oh! I see your situation here cgraus. It seems that you are a science grad and I have a comerce background. The double entry book keeping system was invented in France in the 18th century and is the standard method worldwide which is used to store financial information of any entity, business or non business, using 'accounts' in which each financial transaction has two effects - debit and credit. Hence the term 'double entry'. So, as a simple example of the double entry mechanism - if you purchase something, purchase account would be debited, because it is coming into the entity, and cash account would be credited, as cash is going out of the entity.

So, if anyone is familiar with the double entry system, they would know what I am talking about in my first post. Besides, if you guys, as programmers, develop applicaitons for large organisations, you should be familiar with the accounting systems, as they are one of the primary requirements of any organisation.

|||

Rishi Khetan wrote:

Oh! I see your situation here cgraus. It seems that you are a science grad and I have a comerce background. The double entry book keeping system was invented in France in the 18th century and is the standard method worldwide which is used to store financial information of any entity, business or non business, using 'accounts' in which each financial transaction has two effects - debit and credit. Hence the term 'double entry'. So, as a simple example of the double entry mechanism - if you purchase something, purchase account would be debited, because it is coming into the entity, and cash account would be credited, as cash is going out of the entity.

So, if anyone is familiar with the double entry system, they would know what I am talking about in my first post. Besides, if you guys, as programmers, develop applicaitons for large organisations, you should be familiar with the accounting systems, as they are one of the primary requirements of any organisation.

Yeah. . . we use peachtree. @. US$1200 it would certainly take our company many more than 12 manhours to even begin writing anything close to robust.|||

*grin* actually, I'm not a graduate at all, I'm self taught. But yes, you get my point, you're asking about things that don't really relate to programming, but to the system you're trying to create.

It's a bit of a common mistake to assume that all programmers work on accounting systems. In fact, I work on websites, image processing programs, databases, code libraries, but nothing accounting wise, not ever.

The core thing I guess is that you need to use transactions to make sure that your 'double entry' is a single operation that succeeds or fails. Beyond that, if you need help in designing the tables, you'd need to say what you're trying to store.

|||

Yeah, the cost effectiveness of buying an existing tool/class library is often lost on programmers :-)

|||

*grin* actually, I'm not a graduate at all, I'm self taught.

Great, that actually happens to be my philosophy as well . And even I'm not a graduate, I'm still an undergrad.

I think I should go into a bit more detail here, for those who don't know about accounting systems. As I mentioned, there are two effects for every financial transaction - debit and credit. Every transaction is related to an account. An account stores all the financial info of a particular item. For example you have the cash a/c which tells you about all the cash transactions that you have had, bank a/c which gives you details of all your transactions using your actual bank account ( the two are different ), accounts for different assets that you purchase, that keep track of how much of that asset was purchased, how much had to be sold etc. Then you have the various accounts for the heads of incomes and expenses that you have. These give details of which incomes and expenses you incurred at what dates and what amounts. Now whenever a transaction takes place, it has two effects - one account is debited with a certain amount and another account is credited with the equal amount because there are always atleast two accounts related to every transaction. When you buy something, as per my earlier example, you have an asset coming in your hands, and cash ( or a cheque which means the bank a/c ) going out. So the entry would be to debit the asset account with the purchase amount and to credit the cash a/c with the same amount. Now for storing any financial transaction, we have a book, which stores the base transaction, which is called the journal. So you enter the debited and credited accounts along with the amount and the date into this journal. Now, to make a meaningful picture of all the transactions you have entered in the journal, you need to 'post' them into the accounts' respective ledgers. So the ledger of the cash a/c would list on the left hand side ( debit side ) side, all the sales related transactions, and all income related transactions, because in these transactions, in the journal, the cash account is debited. In the right hand side of the cash a/c ( credit side ), all transactions relating to purchase, expenses etc are stored, as the cash a/c is credited here ( as seen in the above example ). Then you need to total the amounts on both the debit and the credit side periodically, to get the cash balance you have If the total of the debit side of the cash account is more than total of the credit side (which should be the case since you cannot have a negative cash balance), then total of debit side minus total of credit side gives you the cash balance. Now, without computers and RDBMSes, people used to actually write down the journal entries first and manually create the accounts in ledgers in large books and post the entries there and then total all the accounts. This would also lead to duplication of effort, you need to write the same thing twice while posting. But with a computerised system, you only need to enter the journal entry and the system automatically posts the transactions to the ledger and totalls all the accounts in real time to tell you the balances you have on hand for each account. Now there are quite a few good accounting software out in the market, and I am even aware of a few designed using access as well, but I am looking to create a larger database system of which the accounting system is only a part and which stores info about a lot of other aspects of a business, so I wouldn't be able to use these other software. I am just stuck on the accounting part of the database.

|||

It seems to me that you have a good understanding of the business rules here, so you seem the best person to design the tables :-)

If you're building a larger system, is Access the best choice for a database ?

|||

Now there are quite a few good accounting software out in the market, and I am even aware of a few designed using access as well, but I am looking to create a larger database system of which the accounting system is only a part and which stores info about a lot of other aspects of a business, so I wouldn't be able to use these other software.

Really? Sounds like your team needs a Systems Engineer with some integration experience.

|||

It seems to me that you have a good understanding of the business rules here, so you seem the best person to design the tables :-)

Actually, as I mentioned Christian, I am still in college, undergoing studies in the commerce field. And I do not have much knowledge of programming, I just know how to use Access and a bit of HTML. I am trying to learn SQL Server Express and VB Express. And, I most certainly do not intend to use Access for creating the entire system, I am going to use SQL Server and VB Express. Its just that creating tables and relationships in Access is faster ( I have a slow system, need to buy a faster one in a couple of weeks time ) and I will understand it better using Access' example, and then I will recreate the whole thing using the GUI tools in SQL Server. Actually I did try to take assistance from the 'Accounts' template in Access, but couldn't make much headway using that either. I couldn't understand many of the fields they put in their tables. I think I will check out that template once more, to see if I can find anything of substance there. Meanwhile, if someone knows the solution to my problem, could you please help me out ?

No team here Blair, I'm the sole team member here, a one man army. Actually I'm just an amateur hobbyist, and I'm trying to build a complete ERP solution for my Dad's business, I've been trying to persuade him to get it computerised for a long time. Don't worry, its not a large project, the business is a proprietory concern with no employees ( not counting peons ) and is limited to a single computer, but has multiple operations and data requirements. No internet connectivity or setting up a web server for accesing the data remotely here, its just for internal access.

|||

So is your question really how to create tables and relationships using SQL in SQL Server ? That would be a programming question. I doubt very much that anyone here is going to design your database for you, and it's still quite frankly impossible to do so based on the information you have provided.

|||

No, my question is not how to create tables and relationships using SQL in SQL Server. My question is ( to anybody who knows both the accounting methods and principles, and SQL and RDBMS theories ) what tables do I create, what fields do I create in them and which relationships should I create, so that I can get the basic journal and ledger functionality of an accounting system.

|||

I think the point is, it is not as simple as you think it is. We could fill up an entire forum just for hashing out this business solution.

What I would suggest is searching sourceforge.net for some freeware to get an idea on how others have approached this particular situation. You might even find a solution you can employ in its entirety or customize to your needs.

We can offer general help, such as how to design/create/use/manipulate databases/tables/relationships/triggers in general, But particular solutions, to seriously complex issues such as a functional accounting system, I believe are beyond the scope of the developer forums.

Creating a Dimension Table from a 3-key table

Hi All,

I have a situation with a table that was created for a transactional

system with a 3 columns key. The table is similar to the following:

country state city description
1 12 21 City A from country 1 and state 12
1 13 21 City A from country 1 and state 13
2 14 22 City B from country 2 and state 14
2 15 22 City B from country 2 and state 15

Now I'm trying to create a dts package that would allow me to build a

city dimension table with unique codes (keys) for each city. What kind of

transformation should I use to translate the old codes (based on the

country-state-city key) into the new ones and preserving the data

integrity?

Thanks,

Ignaciodoesn't that defeat the purpose of building a cube?

What's it going to be for?

How are you going to go after the data?|||This cube is going to show sales history since 2002. The table where data is being pulled could contain data as the following:

cust_id year country state city amount_cash amount_credit
525 2002 1 12 21 8500 3200
714 2002 1 13 21 3250 775

Let's say I create a fact table with fk and measures only. If I would like to know city totals, it looks like cities sharing the same id will be aggregated, when in fact they shouldn't. And in the other hand, cities that are geographically shared by different states will add up correctly. Maybe I need to further analyze this, but what first puzzled me was the city table with no unique id.

Thanks for your thoughts!

Ignacio