Showing posts with label names. Show all posts
Showing posts with label names. Show all posts

Sunday, March 11, 2012

Check Constraints or Triggers

Hi, Im facing teh following situation:

This are just sample table names, but should do for discussing
purpouses.

Create table Invoice
(
InvoiceID Integer Not Null,
CustomerType Integer Not Null,
CustomerCode Integer Not Null,
Amount DECIMAL(10,2) Not Null,
.............
)

Create Table Type1Customer
(
CustomerCode Integer Not Null,
........................
)

Create Table Type2Customer
(
CustomerCode Integer Not Null,
........................
)

I need to add a way to restrict the CustomerType and CustomerCode,
in the Invoice table to the correct values.
This means that if customerType equals 1 the customerCode should be
checked against Type1Customer and if customerType equals 2 the
customerCode should be checked against Type2Customer.

I succesfully created a check constraint. That ensures that the valid
values exists when the rows in the Invoice table are inserted or
updated, but doesnt prevent from deleting records from tables
Type1Customer and Type2Customer that are referenced from the Invoice
table.

Are triggers the only way to go?

Thanks in advance

Sebastin streigerIn addition to Erland's suggestion,
I would recommend adding CustomerType to both Type1Customer and
Type2Customer, and adding CustomerType to their FK constraints|||(sebastian.streiger@.gmail.com) writes:
> This are just sample table names, but should do for discussing
> purpouses.
> Create table Invoice (
> InvoiceID Integer Not Null,
> CustomerType Integer Not Null,
> CustomerCode Integer Not Null,
> Amount DECIMAL(10,2) Not Null,
> ............. )
> Create Table Type1Customer (
> CustomerCode Integer Not Null,
> ....................... )
>
> Create Table Type2Customer (
> CustomerCode Integer Not Null,
> ....................... )
> I need to add a way to restrict the CustomerType and CustomerCode,
> in the Invoice table to the correct values.
> This means that if customerType equals 1 the customerCode should be
> checked against Type1Customer and if customerType equals 2 the
> customerCode should be checked against Type2Customer.
>...
> Are triggers the only way to go?

With that data model, yes. But is that really the right data model?

I would rather have a CustomerCode table which could look like this:

CREATE TABLE CustomerCode (
CustomerType integer NOT NULL,
CustomerCode integer NOT NULL,
CONSTRAINT pk_CustomerCode(CustomerType, CustomerCode))

Then Invoices could refer to this table, and so could the child
tables Type1Customer and Type2Customer.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Erland and AK:
Thank you for answering.
I DO agree that the model is no the best one that we can have. But due
to organizational issues Im not in position to change the tables
structures by now. So, Im trying to add constraints to ensure the
data consistency.

Thanks for your valuable feedback

Saturday, February 25, 2012

Charting and the Document Map

Hi,
I have a report which contains 3 different charts. What I need to do is have
all 3 of the chart names in the Document and only 1 chart showing at a time.
The users can then click on a different chart name in the Document Map to
view a different chart.
Is this possible and any suggestions?
ThanksThe document map cannot be used to dynamically "show/hide" report items. It
can only be used to navigate through the report.
If the report only contains charts, you could add page breaks between the
charts and therefore have 3 pages and clicking in the document map would
just navigate the pages of the report. Not sure if that would work in your
situation.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Spencer23" <Spencer23@.discussions.microsoft.com> wrote in message
news:0C181E97-D056-495C-829D-94D78E73FFB6@.microsoft.com...
> Hi,
> I have a report which contains 3 different charts. What I need to do is
> have
> all 3 of the chart names in the Document and only 1 chart showing at a
> time.
> The users can then click on a different chart name in the Document Map to
> view a different chart.
> Is this possible and any suggestions?
> Thanks

Friday, February 24, 2012

Chart legend wrapping

We have very long names for our series that appear in a chart legend so they
appear cut off with an ellipsis (three dots ...) at the end. We noticed
though that if we specify a \n in any one of the series names then they will
all wrap over two lines!
Ideally we would like the series names to all wrap over two lines in the
legend without having to specify \n in one of then - otherwise we would need
to carefully calculate where to add the \n
Is this possible to configure so that the metric names will automatically
wrap over two lines?You could write a function which uses GDI calls to calculate the actual
width of string glyphs based on font name, etc. However, the GDI calls are
usually not 100% accurate.
Another option to consider is to "draw" the legend by using a table report
item, rather using the built-in legend of the chart. Please check this
related newsgroup posting:
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.sqlserver.reportingsvcs&mid=ef87e605-48af-4c87-ac3f-ad43cd5fb1fc&sloc=en-us
Also check this blog posting which includes a link to a sample report.
http://blogs.msdn.com/bwelcker/archive/2005/05/20/420349.aspx
Robert M. Bruckner
Microsoft SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Matt" <Matt@.discussions.microsoft.com> wrote in message
news:DDB98FDE-3FC8-4926-B318-BD89E7BF0B07@.microsoft.com...
> We have very long names for our series that appear in a chart legend so
> they
> appear cut off with an ellipsis (three dots ...) at the end. We noticed
> though that if we specify a \n in any one of the series names then they
> will
> all wrap over two lines!
> Ideally we would like the series names to all wrap over two lines in the
> legend without having to specify \n in one of then - otherwise we would
> need
> to carefully calculate where to add the \n
> Is this possible to configure so that the metric names will automatically
> wrap over two lines?

Thursday, February 16, 2012

Characters not to use in Table and Field Names: your opinion/experiences

Hi,
I know we can use several non-alpha characters in the names of Tables and
Fields, but I still think it's not a good rpactice. The same thing with the
spaces etc, which can be used, but tiwh the brackets []. Microsoft even uses
underscore_ in their own tables, but still I don't like it because I guess
it could mess up when using the _ for a wildcard.
So I actually prefer not to use Table and field names with special
(non-alpha) characters. Reserved words aren't done either!
And what about figures? I can't really find an exemple wheir it could harm
something, but I don't like it either. Can anybody give me some more info
about this? And any idea about non-alpha characters that can be used safely?
All this not only taking in my Sql Server itself, but also programming
languages that use these databases (especially .NET).
Pieter
My personal preference is to have purely alphabetical table and column
names. For example, ProductID is much more preferable than Product_ID or
[Product-ID] or [Product ID]
Not having these non-alphabetic and special characters in the names makes it
much easier to type things when I am busily troubleshooting something for
example.
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"DraguVaso" <pietercoucke@.hotmail.com> wrote in message
news:%23Jsbr6$lFHA.572@.TK2MSFTNGP15.phx.gbl...
Hi,
I know we can use several non-alpha characters in the names of Tables and
Fields, but I still think it's not a good rpactice. The same thing with the
spaces etc, which can be used, but tiwh the brackets []. Microsoft even uses
underscore_ in their own tables, but still I don't like it because I guess
it could mess up when using the _ for a wildcard.
So I actually prefer not to use Table and field names with special
(non-alpha) characters. Reserved words aren't done either!
And what about figures? I can't really find an exemple wheir it could harm
something, but I don't like it either. Can anybody give me some more info
about this? And any idea about non-alpha characters that can be used safely?
All this not only taking in my Sql Server itself, but also programming
languages that use these databases (especially .NET).
Pieter

Characters not to use in Table and Field Names: your opinion/experiences

Hi,
I know we can use several non-alpha characters in the names of Tables and
Fields, but I still think it's not a good rpactice. The same thing with the
spaces etc, which can be used, but tiwh the brackets []. Microsoft even
uses
underscore_ in their own tables, but still I don't like it because I guess
it could mess up when using the _ for a wildcard.
So I actually prefer not to use Table and field names with special
(non-alpha) characters. Reserved words aren't done either!
And what about figures? I can't really find an exemple wheir it could harm
something, but I don't like it either. Can anybody give me some more info
about this? And any idea about non-alpha characters that can be used safely?
All this not only taking in my Sql Server itself, but also programming
languages that use these databases (especially .NET).
PieterMy personal preference is to have purely alphabetical table and column
names. For example, ProductID is much more preferable than Product_ID or
[Product-ID] or [Product ID]
Not having these non-alphabetic and special characters in the names makes it
much easier to type things when I am busily troubleshooting something for
example.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"DraguVaso" <pietercoucke@.hotmail.com> wrote in message
news:%23Jsbr6$lFHA.572@.TK2MSFTNGP15.phx.gbl...
Hi,
I know we can use several non-alpha characters in the names of Tables and
Fields, but I still think it's not a good rpactice. The same thing with the
spaces etc, which can be used, but tiwh the brackets []. Microsoft even
uses
underscore_ in their own tables, but still I don't like it because I guess
it could mess up when using the _ for a wildcard.
So I actually prefer not to use Table and field names with special
(non-alpha) characters. Reserved words aren't done either!
And what about figures? I can't really find an exemple wheir it could harm
something, but I don't like it either. Can anybody give me some more info
about this? And any idea about non-alpha characters that can be used safely?
All this not only taking in my Sql Server itself, but also programming
languages that use these databases (especially .NET).
Pieter

Characters not to use in Table and Field Names: your opinion/experiences

Hi,
I know we can use several non-alpha characters in the names of Tables and
Fields, but I still think it's not a good rpactice. The same thing with the
spaces etc, which can be used, but tiwh the brackets []. Microsoft even uses
underscore_ in their own tables, but still I don't like it because I guess
it could mess up when using the _ for a wildcard.
So I actually prefer not to use Table and field names with special
(non-alpha) characters. Reserved words aren't done either!
And what about figures? I can't really find an exemple wheir it could harm
something, but I don't like it either. Can anybody give me some more info
about this? And any idea about non-alpha characters that can be used safely?
All this not only taking in my Sql Server itself, but also programming
languages that use these databases (especially .NET).
PieterMy personal preference is to have purely alphabetical table and column
names. For example, ProductID is much more preferable than Product_ID or
[Product-ID] or [Product ID]
Not having these non-alphabetic and special characters in the names makes it
much easier to type things when I am busily troubleshooting something for
example.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"DraguVaso" <pietercoucke@.hotmail.com> wrote in message
news:%23Jsbr6$lFHA.572@.TK2MSFTNGP15.phx.gbl...
Hi,
I know we can use several non-alpha characters in the names of Tables and
Fields, but I still think it's not a good rpactice. The same thing with the
spaces etc, which can be used, but tiwh the brackets []. Microsoft even uses
underscore_ in their own tables, but still I don't like it because I guess
it could mess up when using the _ for a wildcard.
So I actually prefer not to use Table and field names with special
(non-alpha) characters. Reserved words aren't done either!
And what about figures? I can't really find an exemple wheir it could harm
something, but I don't like it either. Can anybody give me some more info
about this? And any idea about non-alpha characters that can be used safely?
All this not only taking in my Sql Server itself, but also programming
languages that use these databases (especially .NET).
Pieter

Tuesday, February 14, 2012

Character set support

I'm looking at an MS SQL server database and it stores city names
across the world. All a
arabic , chinese etc names are converted to the latin alphabet.

I feel it is probably critical we support accents as a means to
distinguish between cities that would be converted to the same Latin
alphabet representation otherwise and as a matter of cultural
politeness.

Now ..... how do we do this?
Use varchar? which character code page do we use?
Use nvarchar? I heard a rumour that SQL server pads unused characters
with blanks and hence will use space unnecessarily.

The data will be presented on sheets and emailed around the world - it
will also appear on a website.

Any advice greatly appreciated - thanks
Oliver(oraustin@.hotmail.com) writes:

Quote:

Originally Posted by

I'm looking at an MS SQL server database and it stores city names
across the world. All a
arabic , chinese etc names are converted to the latin alphabet.
>
I feel it is probably critical we support accents as a means to
distinguish between cities that would be converted to the same Latin
alphabet representation otherwise and as a matter of cultural
politeness.
>
>
Now ..... how do we do this?
Use varchar? which character code page do we use?
Use nvarchar?


You need to use nvarchar. With varchar you can only support one code
page, and that is not enough. For instance, if you use CP-1252, Windows
Latin-1, you will not be able to enter the capital of Roumania
correctly, nor the largest city of Turkey. (I'm using a newsreader that
is not Unicode capable, so embarrassing enough, I cannot enter these
name correctly myself.)

Quote:

Originally Posted by

I heard a rumour that SQL server pads unused characters
with blanks and hence will use space unnecessarily.


That is incorrect. If you use varchar/nvarchar, SQL Server will not
pad. However, if you save data with trailing spaces, SQL Server will
by default to chop that off. The char/nchar data types on the other
hand are fixed-length, but you would not use them for city length.

On the other hand, in nvarchar each character takes up two bytes, in
difference to varchar with one byte per character. So nvarchar takes
twice the space.

But given your requirements, you don't have much choice.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Friday, February 10, 2012

Chaning login name

There have been some major changes here at work, and in order to keep up we
need to change some of the Group names in Active directory. Will the
changes that are made in Active Directory cascade down into SQL Server?
What is the protocol for this type of change?
Thanks,
DrewNo. On 2005, you can rename a login (to reflect the name change) using ALTER LOGIN.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Drew" <drew.laing@.swvtc.dmhmrsas.virginia.gov> wrote in message
news:OQx$0ftqIHA.5096@.TK2MSFTNGP02.phx.gbl...
> There have been some major changes here at work, and in order to keep up we need to change some of
> the Group names in Active directory. Will the changes that are made in Active Directory cascade
> down into SQL Server? What is the protocol for this type of change?
> Thanks,
> Drew
>|||What is the protocol for SQL Server 2000?
Thanks,
Drew
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:C42BDB9F-51A2-424C-8C25-58B905FB94E4@.microsoft.com...
> No. On 2005, you can rename a login (to reflect the name change) using
> ALTER LOGIN.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "Drew" <drew.laing@.swvtc.dmhmrsas.virginia.gov> wrote in message
> news:OQx$0ftqIHA.5096@.TK2MSFTNGP02.phx.gbl...
>> There have been some major changes here at work, and in order to keep up
>> we need to change some of the Group names in Active directory. Will the
>> changes that are made in Active Directory cascade down into SQL Server?
>> What is the protocol for this type of change?
>> Thanks,
>> Drew
>|||You can't change the name for a login in 2000. You'd have to delete and re-create the login...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Drew" <drew.laing@.swvtc.dmhmrsas.virginia.gov> wrote in message
news:%234%233Q7tqIHA.2292@.TK2MSFTNGP03.phx.gbl...
> What is the protocol for SQL Server 2000?
> Thanks,
> Drew
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in message
> news:C42BDB9F-51A2-424C-8C25-58B905FB94E4@.microsoft.com...
>> No. On 2005, you can rename a login (to reflect the name change) using ALTER LOGIN.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "Drew" <drew.laing@.swvtc.dmhmrsas.virginia.gov> wrote in message
>> news:OQx$0ftqIHA.5096@.TK2MSFTNGP02.phx.gbl...
>> There have been some major changes here at work, and in order to keep up we need to change some
>> of the Group names in Active directory. Will the changes that are made in Active Directory
>> cascade down into SQL Server? What is the protocol for this type of change?
>> Thanks,
>> Drew
>>
>

changing/reordering text in a field

I have a table with approx 1200 names in the format of "John Doe" I need to edit the names to the format of "Doe, John"
Any easy way in SQL to do this or am I better off dumping to text file, making the changes in another app and then updating the table?I guess in some time you'll need another format - "FN Doe LN John" ;). It is better to keep first and last name in different fields.|||Your lucky day. See attached file with function for parsing names.|||Yes, Separate columns would be better.

USE Northwind
GO

SET NOCOUNT ON
CREATE TABLE myTable99(myName varchar(50))
GO

INSERT INTO myTable99(myName)
SELECT 'John Doe' UNION ALL
SELECT 'John Apple' UNION ALL
SELECT 'John Q. Adams' UNION ALL
SELECT 'Mr. John Doe' UNION ALL
SELECT 'John Doe III'
GO

SELECT SUBSTRING(myName,(CHARINDEX(' ',myName)+1),(LEN(myName)-(CHARINDEX(' ',myName)))) + ', '
+ SUBSTRING(myName,1,(CHARINDEX(' ',myName)-1))
FROM myTable99
GO

SET NOCOUNT OFF
DROP TABLE myTable99
GO