Showing posts with label hii. Show all posts
Showing posts with label hii. Show all posts

Sunday, March 25, 2012

Best practise regarding Tables?

Hi!

I have 6-7 tables total containing subobjects for different objects like phonenumbers and emails for contacts.
This meaning i have to do some querys on each detailpage. I will use stored proc for fetching subobjects.

My question therefore was: if i could merge subobjects into same tables making me use perhaps 2 querys instead of 4 and thus perhaps doubling the size
of the tables would this have a possibility of giving me any performance difference whatsoever?

As i see pros arefewer querys, and cons are larger tables and i will need another field separating the types of objects in the table.

Anyone have insight to this?

I would be curious to see what you mean by "subobjects" - usually when you ask a question like this it is a good idea to post your table structure. You'll get more specific help that way.

In general, you should strive for proper normalization of your database. This normally means more tables, and the tables are thin, not wide. However, if you have similar sets of data that can be "typed" and placed into the same table, that is normally a good route to take. For example, if you have a business phone numbers and home phone numbers, I would recommend putting these in the same table and adding a field to specify its type, rather than having two separate tables. On the other hand, you shouldn't try to squeeze more disparate types of data into the same table and type them.

|||

By objects i mean like applications, users, groups.
By subobjects i mean phonenumbers, emails, contacts(for example when an application have a number of contacts linked to it) etc

To illustrate i post some of my tables:

First an object table:

CREATE TABLE [sw20aut].[sw_apps] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[kund_id] [int] NOT NULL ,
[namn] [varchar] (80) COLLATE Finnish_Swedish_CI_AS NOT NULL ,
[beskrivning] [text] COLLATE Finnish_Swedish_CI_AS NOT NULL DEFAULT ('') ,
[usr_rubrik] [varchar] (60) COLLATE Finnish_Swedish_CI_AS NOT NULL DEFAULT ('Övrig information') ,
[usr_information] [text] COLLATE Finnish_Swedish_CI_AS NOT NULL DEFAULT ('') ,
[kat] [int] NOT NULL DEFAULT('0') ,
[typ] [tinyint] NOT NULL DEFAULT('0') ,
[skapare] [varchar] (15) COLLATE Finnish_Swedish_CI_AS NOT NULL ,
[skapad] [datetime] NOT NULL ,
[del] [bit] NOT NULL DEFAULT ('0')
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

Here are some subtables:

CREATE TABLE [sw20aut].[sw_sub_email] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[p_typ] [varchar] (3) COLLATE Finnish_Swedish_CI_AS NOT NULL ,
[p_id] [int] NOT NULL ,
[epost] [varchar] (60) COLLATE Finnish_Swedish_CI_AS NULL ,
[kommentar] [varchar] (60) COLLATE Finnish_Swedish_CI_AS NOT NULL
) ON [PRIMARY]

CREATE TABLE [sw20aut].[sw_sub_phone] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[p_typ] [varchar] (3) COLLATE Finnish_Swedish_CI_AS NOT NULL ,
[p_id] [int] NOT NULL ,
[tel_land] [varchar] (6) COLLATE Finnish_Swedish_CI_AS NULL ,
[tel_rikt] [varchar] (6) COLLATE Finnish_Swedish_CI_AS NULL ,
[tel_nr] [varchar] (30) COLLATE Finnish_Swedish_CI_AS NULL ,
[kommentar] [varchar] (60) COLLATE Finnish_Swedish_CI_AS NOT NULL
) ON [PRIMARY]

CREATE TABLE [sw20aut].[sw_sub_contacts] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[p_typ] [varchar] (3) COLLATE Finnish_Swedish_CI_AS NOT NULL ,
[p_id] [int] NOT NULL ,
[kon_id] [int] NOT NULL ,
[kon_kid] [int] NOT NULL ,
[kommentar] [varchar] (60) COLLATE Finnish_Swedish_CI_AS NOT NULL
) ON [PRIMARY]

CREATE TABLE [sw20aut].[sw_sub_grupper] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[p_typ] [varchar] (3) COLLATE Finnish_Swedish_CI_AS NOT NULL ,
[p_id] [int] NOT NULL ,
[grp_id] [int] NOT NULL ,
[grp_kid] [int] NOT NULL ,
[kommentar] [varchar] (60) COLLATE Finnish_Swedish_CI_AS NOT NULL
) ON [PRIMARY]

p_id = the parents id
p_typ = type of parent, for example app, con or grp

As seen above i could join sub_contacts and sub_groups easily(need another field to set if its a contact or group though) and i could probably join email and phone as well, in worst case using some kind of commaseparated format to separate countrycode, areacode etc. I have a couple of other similar sub tables as well The question is if it could be worth the effort or the larger tables(more rows) and another field to sort by would negate the advantage of fewer querys when listing? Practically it would mean a step from 6-7 querys on worst pages down to 3-4.
I use batched dynamic querys and some stored procs depending on circumstances

|||

The baseline for the table definition is files and association so if what I am seeing is correct you have maybe one or two secondary tables and the relationship is actually quantified by upper and lower bound Cardinality meaning number of expected rows. And I don't think name should be VarChar 80 more like 30-50. Try the links below for functional dependency and free tables you can clone. Hope this helps.

http://www.databaseanswers.org/data_models/

http://www.utexas.edu/its/windows/database/datamodeling/rm/rm7.html

|||

The problem regarding sizeing the name columns in different tables are partly because i will have to import data from old tables used by the former application.

These tables are very poorly designed(even to my standards ;) ) and have caused users to add more than just name in the namefields so forth. I will control this better programatically but
nevertheless stripping of existing text in the field would not be popular so my thought weher to implement it and try steering all new information in a better way.
I think that this meant i needed that size when examining the old data to prevent truncation.

Anyway the tables above are examples i have more secondary tables and quite a few primary tables as well.
The basic concept i was thinking about if its better practice to have larger tables wich results in less querys / page (merging the sub/secondary tables as much as practically possible) or using smaller, slicker tables and more inpage querys/procs. For example using 1 table to link both contacts and groups and 1 table for perhaps phone/email and even links as long as one can reuse the fields not resulting in empty fields.

Shall check your links btw

|||

You could clean the data before importing it and I am concerned you are describing tables on the Calculus end where you have main table and the dimenssions on this end tables sizes should be similar. I know you can use validators but you can also use CHECK CONSTRAINT on you columns so people cannot insert whatever they like in name columns.

http://msdn2.microsoft.com/en-us/library/ms188258.aspx

Wednesday, March 7, 2012

Best Performance Query

Hi:

I have the following query, can somebody help me?

SELECT
s.Id, s.Name
FROM
Switch s
INNER JOIN
SwitchTelephoneRange r ON s.Id = r.Id
WHERE
'1526858' BETWEEN FromTelephone AND ToTelephone

Where the '1526858' is a phone number.

My problem is, I want to run the above query for each record in :

select Telephone from PhoneDirectory

So, each telephone number in the second phone, would macth the ' ' in the first query.

How can I do so? Do I need a loop? a cursor? Can you help please?

Thanks

Sounds like you need a correlated sub-query. Seehere andhere for more help.|||

Maybe something like this?

SELECT
s.Id, s.Name
FROM
Switch s
INNER JOIN
SwitchTelephoneRange r ON s.Id = r.Id
INNER JOIN
PhoneDirectory pd ON pd.Telephone BETWEEN FromTelephone AND ToTelephone

|||You could prob' do it by self joining too|||

Thanks for all.

Darek, your way is the best.

How can I join on a table without specifying that a key = key ?

You just joined on a table to get the phone number from and said

"inner join ... ON telephon between"

Can you explain that to me please?

That was a great tip.

Thanks a lot.

|||

Thanks.

Everything afterON inJOIN clause is nothing more like simply conditions.

You can write something like that:

FROM a
inner join b.SomeVarChar LIKE a.SomeOtherVarChar

Previous query in ther way:

SELECT
s.Id, s.Name
FROM
Switch s
INNER JOIN
SwitchTelephoneRange r
INNER JOIN
PhoneDirectory pd
WHERE
s.Id = r.Id
AND pd.Telephone BETWEEN FromTelephone AND ToTelephone

Saturday, February 25, 2012

Best configuration for SQL Server 2005

Hi
I am having a little trouble finding what is the ideal configuration
for running SQL Server 2005.
Basically I have a 2 x Quad Core Processor Computer with 4Gb Ram.
Operating System will be Windows 2003 Standard Server R2
I can have any number of hard drives for either a Raid 1 or Raid 5
configuration or whatever, any comments appreciated?
How should the Hard Disk Drives be set up for a 10Gb Database?
Thanks
DominicHi
1) Separate .LDF (Log File) and .MDF (Data File) into phyical disks
2) Put tempdb database on different phsyical disk
3) Add much more RAM as you can and as it allowed by OS
http://www.microsoft.com/technet/pr...5/tsprfprb.mspx --Per
formance
2005
http://www.microsoft.com/technet/pr...ce/default.mspx -
--Best
Practices 2005
<lorenzdominic_@.hotmail.com> wrote in message
news:1180246075.190524.45060@.q19g2000prn.googlegroups.com...
> Hi
> I am having a little trouble finding what is the ideal configuration
> for running SQL Server 2005.
> Basically I have a 2 x Quad Core Processor Computer with 4Gb Ram.
> Operating System will be Windows 2003 Standard Server R2
> I can have any number of hard drives for either a Raid 1 or Raid 5
> configuration or whatever, any comments appreciated?
> How should the Hard Disk Drives be set up for a 10Gb Database?
> Thanks
> Dominic
>|||On May 27, 4:43 pm, "Uri Dimant" <u...@.iscar.co.il> wrote:
> Hi
> 1) Separate .LDF (Log File) and .MDF (Data File) into phyical disks
> 2) Put tempdb database on different phsyical disk
> 3) Add much more RAM as you can and as it allowed by OS
> http://www.microsoft.com/technet/pr...orma
nce
> 2005http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/default.
.--Best
> Practices 2005
> <lorenzdomin...@.hotmail.com> wrote in message
> news:1180246075.190524.45060@.q19g2000prn.googlegroups.com...
>
>
>
>
>
>
>
> - Show quoted text -
Excellent thanks
Dominic|||On May 27, 4:43 pm, "Uri Dimant" <u...@.iscar.co.il> wrote:
> Hi
> 1) Separate .LDF (Log File) and .MDF (Data File) into phyical disks
> 2) Put tempdb database on different phsyical disk
> 3) Add much more RAM as you can and as it allowed by OS
> http://www.microsoft.com/technet/pr...orma
nce
> 2005http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/default.
.--Best
> Practices 2005
> <lorenzdomin...@.hotmail.com> wrote in message
> news:1180246075.190524.45060@.q19g2000prn.googlegroups.com...
>
>
>
>
>
>
>
> - Show quoted text -
Hi
What is difference between tempDb and .mdf files?
Regards
Dominic|||Hi
> What is difference between tempDb and .mdf files?
Tempdb is a database (is a workspace) .It used for temporary tables
explicity created by users
.MDF is a Primary data file . Each database has .MDF and .LDF file . You ca
n
add additional data file (called secnadary .NDF)
<lorenzdominic_@.hotmail.com> wrote in message
news:1180318236.636287.270400@.j4g2000prf.googlegroups.com...
> On May 27, 4:43 pm, "Uri Dimant" <u...@.iscar.co.il> wrote:
> Hi
> What is difference between tempDb and .mdf files?
> Regards
> Dominic
>|||In addition to Uri's comments:
- Make sure you have a battery-backed caching RAID controller with lots of
cache, and configure write caching on about half of the memory.
- Use 15k SCSI disks set up with Raid 1.
- Consider partitioning the database and any big tables.
The first point will gain you more than any other tweak you make.
Finally, buy and read the MS book "SQL Server 2005: Inside the Storage
Engine"
<lorenzdominic_@.hotmail.com> wrote in message
news:1180246075.190524.45060@.q19g2000prn.googlegroups.com...
> Hi
> I am having a little trouble finding what is the ideal configuration
> for running SQL Server 2005.
> Basically I have a 2 x Quad Core Processor Computer with 4Gb Ram.
> Operating System will be Windows 2003 Standard Server R2
> I can have any number of hard drives for either a Raid 1 or Raid 5
> configuration or whatever, any comments appreciated?
> How should the Hard Disk Drives be set up for a 10Gb Database?
> Thanks
> Dominic
>|||If you rely on what you can get from this group for something so major as
this (with so little information given to us) you are definitely going to
get suboptimal results. Hire a professional to assist you in this matter.
He/she can evaluate MANY more things than can be easily put forth in a
newsgroup and get you off on the right foot with the new system.
TheSQLGuru
President
Indicium Resources, Inc.
<lorenzdominic_@.hotmail.com> wrote in message
news:1180246075.190524.45060@.q19g2000prn.googlegroups.com...
> Hi
> I am having a little trouble finding what is the ideal configuration
> for running SQL Server 2005.
> Basically I have a 2 x Quad Core Processor Computer with 4Gb Ram.
> Operating System will be Windows 2003 Standard Server R2
> I can have any number of hard drives for either a Raid 1 or Raid 5
> configuration or whatever, any comments appreciated?
> How should the Hard Disk Drives be set up for a 10Gb Database?
> Thanks
> Dominic
>

Best configuration for SQL Server 2005

Hi
I am having a little trouble finding what is the ideal configuration
for running SQL Server 2005.
Basically I have a 2 x Quad Core Processor Computer with 4Gb Ram.
Operating System will be Windows 2003 Standard Server R2
I can have any number of hard drives for either a Raid 1 or Raid 5
configuration or whatever, any comments appreciated?
How should the Hard Disk Drives be set up for a 10Gb Database?
Thanks
Dominic
Hi
1) Separate .LDF (Log File) and .MDF (Data File) into phyical disks
2) Put tempdb database on different phsyical disk
3) Add much more RAM as you can and as it allowed by OS
http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx --Performance
2005
http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/default.mspx --Best
Practices 2005
<lorenzdominic_@.hotmail.com> wrote in message
news:1180246075.190524.45060@.q19g2000prn.googlegro ups.com...
> Hi
> I am having a little trouble finding what is the ideal configuration
> for running SQL Server 2005.
> Basically I have a 2 x Quad Core Processor Computer with 4Gb Ram.
> Operating System will be Windows 2003 Standard Server R2
> I can have any number of hard drives for either a Raid 1 or Raid 5
> configuration or whatever, any comments appreciated?
> How should the Hard Disk Drives be set up for a 10Gb Database?
> Thanks
> Dominic
>
|||On May 27, 4:43 pm, "Uri Dimant" <u...@.iscar.co.il> wrote:
> Hi
> 1) Separate .LDF (Log File) and .MDF (Data File) into phyical disks
> 2) Put tempdb database on different phsyical disk
> 3) Add much more RAM as you can and as it allowed by OS
> http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx--Performance
> 2005http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/default...--Best
> Practices 2005
> <lorenzdomin...@.hotmail.com> wrote in message
> news:1180246075.190524.45060@.q19g2000prn.googlegro ups.com...
>
>
>
>
> - Show quoted text -
Excellent thanks
Dominic
|||On May 27, 4:43 pm, "Uri Dimant" <u...@.iscar.co.il> wrote:
> Hi
> 1) Separate .LDF (Log File) and .MDF (Data File) into phyical disks
> 2) Put tempdb database on different phsyical disk
> 3) Add much more RAM as you can and as it allowed by OS
> http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx--Performance
> 2005http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/default...--Best
> Practices 2005
> <lorenzdomin...@.hotmail.com> wrote in message
> news:1180246075.190524.45060@.q19g2000prn.googlegro ups.com...
>
>
>
>
> - Show quoted text -
Hi
What is difference between tempDb and .mdf files?
Regards
Dominic
|||Hi
> What is difference between tempDb and .mdf files?
Tempdb is a database (is a workspace) .It used for temporary tables
explicity created by users
..MDF is a Primary data file . Each database has .MDF and .LDF file . You can
add additional data file (called secnadary .NDF)
<lorenzdominic_@.hotmail.com> wrote in message
news:1180318236.636287.270400@.j4g2000prf.googlegro ups.com...
> On May 27, 4:43 pm, "Uri Dimant" <u...@.iscar.co.il> wrote:
> Hi
> What is difference between tempDb and .mdf files?
> Regards
> Dominic
>
|||In addition to Uri's comments:
- Make sure you have a battery-backed caching RAID controller with lots of
cache, and configure write caching on about half of the memory.
- Use 15k SCSI disks set up with Raid 1.
- Consider partitioning the database and any big tables.
The first point will gain you more than any other tweak you make.
Finally, buy and read the MS book "SQL Server 2005: Inside the Storage
Engine"
<lorenzdominic_@.hotmail.com> wrote in message
news:1180246075.190524.45060@.q19g2000prn.googlegro ups.com...
> Hi
> I am having a little trouble finding what is the ideal configuration
> for running SQL Server 2005.
> Basically I have a 2 x Quad Core Processor Computer with 4Gb Ram.
> Operating System will be Windows 2003 Standard Server R2
> I can have any number of hard drives for either a Raid 1 or Raid 5
> configuration or whatever, any comments appreciated?
> How should the Hard Disk Drives be set up for a 10Gb Database?
> Thanks
> Dominic
>
|||If you rely on what you can get from this group for something so major as
this (with so little information given to us) you are definitely going to
get suboptimal results. Hire a professional to assist you in this matter.
He/she can evaluate MANY more things than can be easily put forth in a
newsgroup and get you off on the right foot with the new system.
TheSQLGuru
President
Indicium Resources, Inc.
<lorenzdominic_@.hotmail.com> wrote in message
news:1180246075.190524.45060@.q19g2000prn.googlegro ups.com...
> Hi
> I am having a little trouble finding what is the ideal configuration
> for running SQL Server 2005.
> Basically I have a 2 x Quad Core Processor Computer with 4Gb Ram.
> Operating System will be Windows 2003 Standard Server R2
> I can have any number of hard drives for either a Raid 1 or Raid 5
> configuration or whatever, any comments appreciated?
> How should the Hard Disk Drives be set up for a 10Gb Database?
> Thanks
> Dominic
>

Sunday, February 19, 2012

Bench Mark on Performance

Hi
I'm looking quite heavily at SQL Server Profiler (2000 sp3a).
I understand that the profiler looks at the logical reads and physical
writes.
What I'm trying to understand is what people use as a guide as to
whether something should be dedicated or if it could be shared on an
active/passive clustered environment.
If I'm recieving a million reads per hour, they are logical, hence in
the buffer cache, but does that mean the server is performing well? I
know that it's not always down to just read and writes but that is the
essence of a db system... so that's where I start.
Your thoughts would be most appreciated.
SimonHi
I'd also look at Performance Monitor to examine PhysicalDisk Object: Avg.
Disk Queue Length
http://www.sql-server-performance.c...counters_io.asp
Per a query you can use SET STATISTICS IO command
When looking at individual queries ,the Logical Reads is more interesting
because the ibfo is consistent
Pay close attention as well to chache-hit ratio. (>=98%)
<simonaarons@.yahoo.co.uk> wrote in message
news:1129024856.929599.263150@.o13g2000cwo.googlegroups.com...
> Hi
> I'm looking quite heavily at SQL Server Profiler (2000 sp3a).
> I understand that the profiler looks at the logical reads and physical
> writes.
> What I'm trying to understand is what people use as a guide as to
> whether something should be dedicated or if it could be shared on an
> active/passive clustered environment.
> If I'm recieving a million reads per hour, they are logical, hence in
> the buffer cache, but does that mean the server is performing well? I
> know that it's not always down to just read and writes but that is the
> essence of a db system... so that's where I start.
> Your thoughts would be most appreciated.
> Simon
>|||Simon,
This is where a benchmark for your system would help. This would provide
you with how the system operates during normal operations. The performance
values derived from the benchmark can be compared against over time to
establish changes in the environment and to proactively predict future HW
upgrades/additions.
HTH
Jerry
<simonaarons@.yahoo.co.uk> wrote in message
news:1129024856.929599.263150@.o13g2000cwo.googlegroups.com...
> Hi
> I'm looking quite heavily at SQL Server Profiler (2000 sp3a).
> I understand that the profiler looks at the logical reads and physical
> writes.
> What I'm trying to understand is what people use as a guide as to
> whether something should be dedicated or if it could be shared on an
> active/passive clustered environment.
> If I'm recieving a million reads per hour, they are logical, hence in
> the buffer cache, but does that mean the server is performing well? I
> know that it's not always down to just read and writes but that is the
> essence of a db system... so that's where I start.
> Your thoughts would be most appreciated.
> Simon
>

Monday, February 13, 2012

BEGINNER'S QUESTION: SORTING IN ALPHABETICAL ORDER

Hi

I am trying to convert an Access back end into a SQL Server back end and cannot work out how to convert a query that sorts addresses that start with numbers into alphabetical order.

In Access I defined a function that converted the full address to one without the initial numbers eg:
66 Acacia Gardens to Acacia Gardens

I then used this function as an expression in the field column of the query and set it to sort by this field. This put the rows into alphabetical order. (A second function was used to return just the number which was used as the second sort).

I am converting the Access query into a stored procedure. I have successfully converted the Access number removal function into a separate stored procedure and I was intending to execute it from within the main stored procedure but I cannot work out how to do this. I don't think you can insert an Execute statement into a field as you can with a function in Access.

Code for working number removal stored procedure:

ALTER PROCEDURE spRemoveInitialNumbers
@.JobName varchar(20), @.FirstNumbersRemoved varchar(20) OUTPUT
As
DECLARE @.Chopped varchar(20)
DECLARE @.CharacterCount tinyint
DECLARE @.CharacterCode tinyint
SET @.Chopped = @.JobName
IF Substring(@.Chopped,1,5) = 'Unit '
Begin
SET @.Chopped = Right(@.Chopped, Len(@.Chopped)-5)
End
ELSE
SET @.CharacterCount = 1
WHILE @.CharacterCount<=Len(@.Chopped)
BEGIN
SET @.CharacterCode=Ascii(Substring(@.Chopped,@.CharacterCount,1))
If @.CharacterCode>64 and @.CharacterCode<91
Begin
SET @.Chopped=Right(@.Chopped, Len(@.Chopped) - @.CharacterCount + 1)
Break
End
Else
Set @.CharacterCount = @.CharacterCount + 1
End
SET @.FirstNumbersRemoved=@.Chopped

Code for non-working main stored procedure:

SELECT dbo.tblJobs.JobID, dbo.tblJobs.JobNumber, dbo.tblJobs.Surveyor, dbo.tblClients.ClientName, dbo.tblJobs.JobName, dbo.tblJobs.Description,
dbo.tblJobs.Status, dbo.tblJobs.UrgencyCode, dbo.tblJobs.EstimatedFeesOutstanding, dbo.tblJobs.[Live/Dead],
[Intended to Execute SpRemoveInitialNumbers here] AS Expr1,
SUM(dbo.tblFeeAccounts.TotalLessVATandExpenses - dbo.tblFeeAccounts.SubContactors) AS TotalNet, dbo.tblJobs.InstructionDate
FROM dbo.tblJobs INNER JOIN
dbo.tblClients ON dbo.tblJobs.ClientID = dbo.tblClients.ClientID LEFT OUTER JOIN
dbo.tblFeeAccounts ON dbo.tblJobs.JobID = dbo.tblFeeAccounts.JobID
GROUP BY dbo.tblJobs.JobNumber, dbo.tblJobs.Surveyor, dbo.tblClients.ClientName, dbo.tblJobs.JobName, dbo.tblJobs.Description, dbo.tblJobs.Status,
dbo.tblJobs.UrgencyCode, dbo.tblJobs.EstimatedFeesOutstanding, dbo.tblJobs.[Live/Dead], dbo.tblJobs.InstructionDate, dbo.tblJobs.JobID
HAVING (dbo.tblJobs.[Live/Dead] = N'D')
ORDER BY dbo.tblClients.ClientName, dbo.tblJobs.JobName

I would like to undertake the sort on the server, not client side hence my attempt to use stored procedures. I'm not sure that I am going about this the right way. Can anyone help me?

Many thanks.

Whitebeam

Please put the logic of SpRemoveInitialNumbers SP into a TSQL scalar user-defined function. You can then call it from the SELECT list. Alternatively, you can also embed the required substring / charindex / patindex expression in the SELECT list itself for better performance. ( I am assuming you use such functions to remove the initial numbers).

Sunday, February 12, 2012

Beginner & DB creating

Hi!

I'm trying to make a dictionary.

WordEng(#id,word);
WordIta(#id, word);

tables with words in Italian and English.
Connect1(#id,id1,id2); connecting word form Eng with Ita translation.
Connect2(#id,id1,id2); same for Italian.

Is this correct? 3. normalisation? Will this work?is this a 1 to 1 relationship? i do not think so. one word can have multiple meanings and that means your design is not right.|||1:N relationship

In III and IV table I store all different translations.

1,A,B
2,A,C
3,D,B|||Hi,

There is a Data Model on the Database Answers web site that might give you some ideas :-
http://www.databaseanswers.org/data_models/dictionaries_for_foreign_languages/index.htm

HTH

B.Dimple
Senior DBA|||thank you.
I will look those db models|||also, please don't put a hash character '#' in your column names. that's non-standard.

Friday, February 10, 2012

before delete triggers in MSSQL

Hi
I've got several tables that have foreign key relationships with a 'users'
table - for example tasks (assigned to user) and customers (liason of
customer). When I delete a user, I would like to set all the foreignkeyed
rows to have null as a user, rather than doing a cascading delete. This
could be done in a stored procedure, but the problem is that the application
has multiple modules that can be added and removed, so I don't know at
execution time what tables there are. The only way to do this I could think
of was with triggers. I know this is supposed to be a big no no, but
couldn't think of anything else. Not that it matters, because triggers won't
work here as the trigger is fired after the delete is done and hence bombs
out due to violated constraint checking. I can't use an 'INSTEAD OF' trigger
unfortunately as I need the facility to have multiple triggers. I see that
Oracle has a BEFORE trigger, imagining that this would solve the problem. Is
there similar functionality in SQL, or another way to do this?
I was hoping that this is a common task and that there is an easy way to do
it, but no luck so far with searches
Thanks
JoeOn Mon, 14 Feb 2005 14:54:19 +0200, Mombers wrote:

> The only way to do this I could think
>of was with triggers. I know this is supposed to be a big no no, but
>couldn't think of anything else.
Hi Joe,
Why do you think triggers are a big no no? Of course, they shouldn't be
your first option and you should prefer DRI over triggers where possible,
but there are situations where triggers are an invaluable instrument.

> Not that it matters, because triggers won't
>work here as the trigger is fired after the delete is done and hence bombs
>out due to violated constraint checking.
That's correct. You either have to remove the foreign key constraint and
do the checking in the trigger as well, or you have to use INSTEAD OF
triggers.

> I can't use an 'INSTEAD OF' trigger
>unfortunately as I need the facility to have multiple triggers.
Maybe I'm missing something, but why don't you just combine the actions of
those various triggers into one trigger?

> I see that
>Oracle has a BEFORE trigger, imagining that this would solve the problem. I
s
>there similar functionality in SQL,
The INSTEAD OF trigger is the closest to a BEFORE trigger that SQL Server
has to offer.

> or another way to do this?
As I already indicated, you could move the constraint checking to the
trigger as well. But that's a bad idea, since that would force you to
write and maintain more trigger code, it would slow things down and it
would deny the query optimizer the knowledge of this constraint, so that
it can't use this knowledge to optimize query execution.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||I have to agree 100% with Hugo. Use instead of triggers, or drop your
relationships and implement them in triggers (which will be just as good,
but will be pretty painful to implement consiering you can just do it in the
instead of trigger.) You can have as many actions in the trigger as you
want.
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:cva111hh4p6m600c28jagd6m348r6g2jii@.
4ax.com...
> On Mon, 14 Feb 2005 14:54:19 +0200, Mombers wrote:
>
> Hi Joe,
> Why do you think triggers are a big no no? Of course, they shouldn't be
> your first option and you should prefer DRI over triggers where possible,
> but there are situations where triggers are an invaluable instrument.
>
> That's correct. You either have to remove the foreign key constraint and
> do the checking in the trigger as well, or you have to use INSTEAD OF
> triggers.
>
> Maybe I'm missing something, but why don't you just combine the actions of
> those various triggers into one trigger?
>
> The INSTEAD OF trigger is the closest to a BEFORE trigger that SQL Server
> has to offer.
>
> As I already indicated, you could move the constraint checking to the
> trigger as well. But that's a bad idea, since that would force you to
> write and maintain more trigger code, it would slow things down and it
> would deny the query optimizer the knowledge of this constraint, so that
> it can't use this knowledge to optimize query execution.
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)