Showing posts with label group. Show all posts
Showing posts with label group. Show all posts

Friday, March 30, 2012

how to Diff vs Sum in Group By query?

Hello,
if area 'A' contains 2 numbers in 2 rows then
Select area, Sum(number) from tbl1 where area = 'A'
Group By area
gives me the sum of these 2 numbers in area 'A'
But how can I retrieve the difference of these 2 numbers
using T-Sql?
Thanks,
RonRon wrote:
> Hello,
> if area 'A' contains 2 numbers in 2 rows then
> Select area, Sum(number) from tbl1 where area = 'A'
> Group By area
> gives me the sum of these 2 numbers in area 'A'
> But how can I retrieve the difference of these 2 numbers
> using T-Sql?
> Thanks,
> Ron
Max(number) - Min(number)
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.|||Thanks. That is pretty . I forgot to include a
twist in here. I also have a datefld. So num1 may be min
or num may be max. I have to show +num or -num.
select area, (First(num) - Last(num)) as num1 from tbl1
where datefld between '1/1/2005' and 1/2/2005' Group By
area having area = 'A'
I was able to use your trick to get my positive or
negative result using First and Last functions. Any
suggestions appreciated if this is incorrect usage.
Thanks again,
Ron

>--Original Message--
>Ron wrote:
>Max(number) - Min(number)
>Bob Barrows
>--
>Microsoft MVP -- ASP/ASP.NET
>Please reply to the newsgroup. The email account listed
in my From
>header is my spam trap, so I don't check it very often.
You will get a
>quicker response by posting to the newsgroup.
>
>.
>|||Ron wrote:
> Thanks. That is pretty . I forgot to include a
> twist in here. I also have a datefld. So num1 may be min
> or num may be max. I have to show +num or -num.
> select area, (First(num) - Last(num)) as num1 from tbl1
> where datefld between '1/1/2005' and 1/2/2005' Group By
> area having area = 'A'
> I was able to use your trick to get my positive or
> negative result using First and Last functions. Any
> suggestions appreciated if this is incorrect usage.
First? Last? You must be using Access ... This is a SQL Server group
Do you need a SQL Server (Transact-SQL) solution? Those fnctions do not
exist in T-SQL.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.|||On Fri, 25 Feb 2005 11:19:41 -0800, Ron wrote:

>Thanks. That is pretty . I forgot to include a
>twist in here. I also have a datefld. So num1 may be min
>or num may be max. I have to show +num or -num.
>select area, (First(num) - Last(num)) as num1 from tbl1
>where datefld between '1/1/2005' and 1/2/2005' Group By
>area having area = 'A'
>I was able to use your trick to get my positive or
>negative result using First and Last functions. Any
>suggestions appreciated if this is incorrect usage.
Hi Ron,
Try if this helps:
SELECT G.Area, F.num - L.num AS num1
FROM (SELECT area, MIN(datefld) AS FDate, MAX(datefld) AS LDate
FROM tbl1
WHERE datefld BETWEEN '20050101' AND '20050201'
GROUP BY area) AS G
INNER JOIN tbl1 AS F
ON F.area = G.area
AND F.datefld = G.FDate
INNER JOIN tbl1 AS L
ON L.area = G.area
AND L.datefld = G.LDate
WHERE G.area = 'A'
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||SELECT A.area, A.num-B.num
FROM Tbl1 AS A
JOIN Tbl1 AS B
ON A.datefld < B.datefld
AND A.area = 'A'
AND B.area = 'A'
David Portas
SQL Server MVP
--|||Yes, I figured that out. I was writing the sql in Access
and transferring in to Query Analyzer. Sorry bout that.
I did end up creating a udf for first and last.

>--Original Message--
>Ron wrote:
min
>First? Last? You must be using Access ... This is a SQL
Server group
>Do you need a SQL Server (Transact-SQL) solution? Those
fnctions do not
>exist in T-SQL.
>
>Bob Barrows
>--
>Microsoft MVP -- ASP/ASP.NET
>Please reply to the newsgroup. The email account listed
in my From
>header is my spam trap, so I don't check it very often.
You will get a
>quicker response by posting to the newsgroup.
>
>.
>|||Thanks. I will give that a try.

>--Original Message--
>On Fri, 25 Feb 2005 11:19:41 -0800, Ron wrote:
>
min
>Hi Ron,
>Try if this helps:
>SELECT G.Area, F.num - L.num AS num1
>FROM (SELECT area, MIN(datefld) AS FDate, MAX
(datefld) AS LDate
> FROM tbl1
> WHERE datefld BETWEEN '20050101'
AND '20050201'
> GROUP BY area) AS G
>INNER JOIN tbl1 AS F
> ON F.area = G.area
> AND F.datefld = G.FDate
>INNER JOIN tbl1 AS L
> ON L.area = G.area
> AND L.datefld = G.LDate
>WHERE G.area = 'A'
>
>Best, Hugo
>--
>(Remove _NO_ and _SPAM_ to get my e-mail address)
>.
>|||Thanks very much for your reply. I will give this a try.

>--Original Message--
>SELECT A.area, A.num-B.num
> FROM Tbl1 AS A
> JOIN Tbl1 AS B
> ON A.datefld < B.datefld
> AND A.area = 'A'
> AND B.area = 'A'
>--
>David Portas
>SQL Server MVP
>--
>.
>

Wednesday, March 28, 2012

How to determine what components are installed for SQL 2005 Express

We have serveral app groups that have installed SQL 2005 Express, but each group have installed different components. How can I determine, specifically if the following components were previously installed.

ADDLOCAL=SQL_Engine
ADDLOCAL=SQL_FullText
ADDLOCAL=RS_Server

And if not installed re-install with the missing component?

Thanks

Tony Z

There are two approaches you can check.

1. You can go Control Panel --> Add/Remove Program. Select the SQL Express entry and choose Update. Then you can see the components installed.

2. On x86 machine, check the regsigry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup : FeatureList

On x64 machine, check the corresponding WOW registry key.

Monday, March 26, 2012

How to determine if the logged on user is a member of an active directory security group?

We are using Windows authenication within our system, and I was wondering how it would be possible to determine if the user conected to the SQL SERVER instance was a member of a particular active directory security group?

Thanks.

Moved to Security...

|||

You can use sys.login_token (http://msdn2.microsoft.com/en-us/library/ms186740.aspx) or xp_logininfo (http://msdn2.microsoft.com/en-us/library/ms190369.aspx) to get that information.

I hope this information helps,

-Raul Garcia

SDE/T

SQL Server Engine

Friday, March 23, 2012

How to Determine if a user is a member of the System Admin role?

Is there a script/function that can be used to determine if a user (granted
login/access via NT Group Membership) is a member of the System Administrato
r
group?
We had an issue where a user was a member of multiple NT Global Groups, one
of which was a member of (had) the System Admin role. Our application check
s
to see if the NT Group for our Application has DBO rights, but this returned
false ... yet the user would (by default) create objects (views/tables) in
dbo. We finally traced this down via Enterprise Mgr, Security, Server Roles
and dbl-clicked "System Administrators" and found that there were unexpected
groups there, and our user(s) were in one or more of these groups. How can w
e
determine this via code/script and then "turn it off" for our database (of
course it is possible that a user that is a member of another group MAY need
SA rights in another database)?
Thank you,
Brad
--
Brad Ashforth> Is there a script/function that can be used to determine if a user
> (granted
> login/access via NT Group Membership) is a member of the System
> Administrator
> group?
SELECT IS_SRVROLEMEMBER('sysadmin')

> How can we
> determine this via code/script and then "turn it off" for our database (of
> course it is possible that a user that is a member of another group MAY
> need
> SA rights in another database)?
In SQL 2000, there are only 2 cases where objects will be created in the dbo
schema by default: 1) user is the database owner and 2) user is a
sysadmin role member. The query 'SELECT USER' will return 'dbo' in both
cases.
I'm not sure I understand what you mean by 'turn it off'. Do you mean that
you want the default schema to be other than 'dbo' for the dbo user? Have
you considered schema-qualifying object names so that the default schema
isn't relevant?
Hope this helps.
Dan Guzman
SQL Server MVP
"Brad Ashforth" <banospam@.nospam.nospam> wrote in message
news:5BEE8141-69CC-415A-A57E-48C875CB31AE@.microsoft.com...
> Is there a script/function that can be used to determine if a user
> (granted
> login/access via NT Group Membership) is a member of the System
> Administrator
> group?
> We had an issue where a user was a member of multiple NT Global Groups,
> one
> of which was a member of (had) the System Admin role. Our application
> checks
> to see if the NT Group for our Application has DBO rights, but this
> returned
> false ... yet the user would (by default) create objects (views/tables) in
> dbo. We finally traced this down via Enterprise Mgr, Security, Server
> Roles
> and dbl-clicked "System Administrators" and found that there were
> unexpected
> groups there, and our user(s) were in one or more of these groups. How can
> we
> determine this via code/script and then "turn it off" for our database (of
> course it is possible that a user that is a member of another group MAY
> need
> SA rights in another database)?
> Thank you,
> Brad
> --
> Brad Ashforth|||Hello Brad,
As for a windows user account(or group) or a sqlserver account, before we
check if it is of sysadmin role (in the server instance), we should first
check if it's a server login(principal) on that server instance. For this,
we can use some T-SQL query to lookup all the principals of sysadmin role
in the master db. It'll be a bit different for SQL 2005 and SQL 2000:
============2005===========
select p1.Name as Role_name, p2.Name as Member_name from
sys.server_role_members r1 inner join sys.server_principals p1
on r1.Role_principal_id = p1.Principal_id
inner join sys.server_principals p2
on r1.Member_principal_id = p2.Principal_id
=========================
As you can see, we need to query multiple catalog views in sys schema.
While in SQL server 2000, we can diretly query the "syslogins" table in
master db, and this table contains a "sysadmin" column indicate whether the
certain principal is of sysadmin role.
==============2000==================
select * from syslogins
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Community Support
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)|||Hello Brad,
How are you doing on this issue or does our suggestion help you some? If
there is still anything we can help, please feel free to post here.
Regards,
Steven Cheng
Microsoft MSDN Online Support Lead
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)|||Hello Brad,
How are you doing on this issue or does our suggestion help you some? If
there is still anything we can help, please feel free to post here.
Regards,
Steven Cheng
Microsoft MSDN Online Support Lead
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Wednesday, March 21, 2012

How to determine % of free space

Ok I can't seem to find an answer to this question. I have a NDF file in a
second file group and want to know how much space it used or how much space
is free. Can I do this? If so how? I've just got to be missing it.
Thanks,
PaulWThis isn't documented, but easy to use:
DBCC SHOWFILESTATS
For 2005, there are also a bunch of dynamic management views, and I assume that one of them can give
you the answer.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Paul Widner" <paul_widner@.hotmail.com> wrote in message
news:uC3vnSltGHA.1224@.TK2MSFTNGP03.phx.gbl...
> Ok I can't seem to find an answer to this question. I have a NDF file in a second file group and
> want to know how much space it used or how much space is free. Can I do this? If so how? I've
> just got to be missing it.
> Thanks,
> PaulW
>|||Maybe not what you wanted but - DBCC SHOWFILESTATS will show it in
extents, but not KB....
Paul Widner wrote:
> Ok I can't seem to find an answer to this question. I have a NDF file in a
> second file group and want to know how much space it used or how much space
> is free. Can I do this? If so how? I've just got to be missing it.
> Thanks,
> PaulW|||Sorry about that Tibor, I should have hit refresh! ;)
SGCSNA wrote:
> Maybe not what you wanted but - DBCC SHOWFILESTATS will show it in
> extents, but not KB....
>
> Paul Widner wrote:
> > Ok I can't seem to find an answer to this question. I have a NDF file in a
> > second file group and want to know how much space it used or how much space
> > is free. Can I do this? If so how? I've just got to be missing it.
> >
> > Thanks,
> > PaulW|||No problem. Happens to all of us, all of the time. Also, refresh might not help, as you might be
connected to a different news server than I am, and replication between the news server incurs a
delay. :-)
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"SGCSNA" <sean.gorman@.computershare.com> wrote in message
news:1154540131.071946.269940@.m79g2000cwm.googlegroups.com...
> Sorry about that Tibor, I should have hit refresh! ;)
> SGCSNA wrote:
>> Maybe not what you wanted but - DBCC SHOWFILESTATS will show it in
>> extents, but not KB....
>>
>> Paul Widner wrote:
>> > Ok I can't seem to find an answer to this question. I have a NDF file in a
>> > second file group and want to know how much space it used or how much space
>> > is free. Can I do this? If so how? I've just got to be missing it.
>> >
>> > Thanks,
>> > PaulW
>|||Are those extents in 8k pages?
Paul
"SGCSNA" <sean.gorman@.computershare.com> wrote in message
news:1154540044.752066.187980@.b28g2000cwb.googlegroups.com...
> Maybe not what you wanted but - DBCC SHOWFILESTATS will show it in
> extents, but not KB....
>
> Paul Widner wrote:
>> Ok I can't seem to find an answer to this question. I have a NDF file in
>> a
>> second file group and want to know how much space it used or how much
>> space
>> is free. Can I do this? If so how? I've just got to be missing it.
>> Thanks,
>> PaulW
>|||An extent is 64K. A page is 8k or 8192 bytes. Pages go into extents.
Paul Widner wrote:
> Are those extents in 8k pages?
> Paul
> "SGCSNA" <sean.gorman@.computershare.com> wrote in message
> news:1154540044.752066.187980@.b28g2000cwb.googlegroups.com...
> > Maybe not what you wanted but - DBCC SHOWFILESTATS will show it in
> > extents, but not KB....
> >
> >
> > Paul Widner wrote:
> >> Ok I can't seem to find an answer to this question. I have a NDF file in
> >> a
> >> second file group and want to know how much space it used or how much
> >> space
> >> is free. Can I do this? If so how? I've just got to be missing it.
> >>
> >> Thanks,
> >> PaulW
> >

How to determine % of free space

Ok I can't seem to find an answer to this question. I have a NDF file in a
second file group and want to know how much space it used or how much space
is free. Can I do this? If so how? I've just got to be missing it.
Thanks,
PaulWThis isn't documented, but easy to use:
DBCC SHOWFILESTATS
For 2005, there are also a bunch of dynamic management views, and I assume t
hat one of them can give
you the answer.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Paul Widner" <paul_widner@.hotmail.com> wrote in message
news:uC3vnSltGHA.1224@.TK2MSFTNGP03.phx.gbl...
> Ok I can't seem to find an answer to this question. I have a NDF file in
a second file group and
> want to know how much space it used or how much space is free. Can I do t
his? If so how? I've
> just got to be missing it.
> Thanks,
> PaulW
>|||Maybe not what you wanted but - DBCC SHOWFILESTATS will show it in
extents, but not KB....
Paul Widner wrote:
> Ok I can't seem to find an answer to this question. I have a NDF file in
a
> second file group and want to know how much space it used or how much spac
e
> is free. Can I do this? If so how? I've just got to be missing it.
> Thanks,
> PaulW|||Sorry about that Tibor, I should have hit refresh! ;)
SGCSNA wrote:[vbcol=seagreen]
> Maybe not what you wanted but - DBCC SHOWFILESTATS will show it in
> extents, but not KB....
>
> Paul Widner wrote:|||No problem. Happens to all of us, all of the time. Also, refresh might not h
elp, as you might be
connected to a different news server than I am, and replication between the
news server incurs a
delay. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"SGCSNA" <sean.gorman@.computershare.com> wrote in message
news:1154540131.071946.269940@.m79g2000cwm.googlegroups.com...
> Sorry about that Tibor, I should have hit refresh! ;)
> SGCSNA wrote:
>|||Are those extents in 8k pages?
Paul
"SGCSNA" <sean.gorman@.computershare.com> wrote in message
news:1154540044.752066.187980@.b28g2000cwb.googlegroups.com...
> Maybe not what you wanted but - DBCC SHOWFILESTATS will show it in
> extents, but not KB....
>
> Paul Widner wrote:
>|||An extent is 64K. A page is 8k or 8192 bytes. Pages go into extents.
Paul Widner wrote:[vbcol=seagreen]
> Are those extents in 8k pages?
> Paul
> "SGCSNA" <sean.gorman@.computershare.com> wrote in message
> news:1154540044.752066.187980@.b28g2000cwb.googlegroups.com...

Monday, March 19, 2012

How to design this?

I know this group is about programming, and there is no other group (or
is there?) about database design. So I'll just ask it here.
A product can be sourced from multiple suppliers (worldwide). So I came
up with the tables below.
CREATE TABLE Product (
ProductCode NVARCHAR(10) NOT NULL PRIMARY KEY,
ProductName NVARCHAR(50) NOT NULL,
..
)
CREATE TABLE Supplier (
SupplierCode NVARCHAR(10) NOT NULL PRIMARY KEY,
SupplierName NVARCHAR(50) NOT NULL,
..
)
CREATE TABLE ProductSupplier (
ProductCode NVARCHAR(10) NOT NULL
REFERENCES Product(ProductCode),
SupplierCode NVARCHAR(10) NOT NULL
REFERENCES Supplier(SupplierCode),
..,
PRIMARY KEY (ProductCode, SupplierCode)
)
Now, for a product that is source from a supplier, I have multiple
prices, depending on the quantity I ordered. How would I model this? Is
the following correct?
CREATE TABLE ProductSupplierPrice (
ProductCode NVARCHAR(10) NOT NULL
REFERENCES Product(ProductCode),
SupplierCode NVARCHAR(10) NOT NULL
REFERENCES Supplier(SupplierCode),
Price MONEY NOT NULL,
Qty BIGINT NOT NULL,
PRIMARY KEY (ProductCode, SupplierCode)
)
Or, should I just have an identity column in ProductSupplier, and then
references it from ProductSupplierPrice? Like this:
CREATE TABLE ProductSupplier (
ProductSupplierId INT NOT NULL PRIMARY,
ProductCode NVARCHAR(10) NOT NULL
REFERENCES Product(ProductCode),
SupplierCode NVARCHAR(10) NOT NULL
REFERENCES Supplier(SupplierCode),
..,
? UNIQUE INDEX (ProductCode, SupplierCode)
)
CREATE TABLE ProductSupplierPrice (
ProductSupplierPriceId INT NOT NULL PRIMARY,
ProductSupplierId INT NOT NULL
REFERENCES ProductSupplier(ProductSupplierId),
Price MONEY NOT NULL,
Qty BIGINT NOT NULL,
PRIMARY KEY (ProductCode, SupplierCode)
)> CREATE TABLE ProductSupplierPrice (
> ProductCode NVARCHAR(10) NOT NULL
> REFERENCES Product(ProductCode),
> SupplierCode NVARCHAR(10) NOT NULL
> REFERENCES Supplier(SupplierCode),
> Price MONEY NOT NULL,
> Qty BIGINT NOT NULL,
> PRIMARY KEY (ProductCode, SupplierCode)
> )
is incorrect

> CREATE TABLE ProductSupplierPrice (
> ProductSupplierPriceId INT NOT NULL PRIMARY,
> ProductSupplierId INT NOT NULL
> REFERENCES ProductSupplier(ProductSupplierId),
> Price MONEY NOT NULL,
> Qty BIGINT NOT NULL,
> PRIMARY KEY (ProductCode, SupplierCode)
> )
is incorrect too because (as you've mentioned above) there are (possible)
several prices for each product from each supplier depending on quantity.
So, Qty column should also be a part of the primary key of
ProductSupplierPrice table. But you may add surrogate key column to this
table (not null'ed Identity with Unique index on it) for use in FK
constraints, if needed.
WBR, Evergray
--
Words mean nothing...
"Michael Wong" <nospam@.email.here> wrote in message
news:%23uJb5FzQGHA.5152@.TK2MSFTNGP10.phx.gbl...
>I know this group is about programming, and there is no other group (or is
>there?) about database design. So I'll just ask it here.
> A product can be sourced from multiple suppliers (worldwide). So I came up
> with the tables below.
> CREATE TABLE Product (
> ProductCode NVARCHAR(10) NOT NULL PRIMARY KEY,
> ProductName NVARCHAR(50) NOT NULL,
> ...
> )
> CREATE TABLE Supplier (
> SupplierCode NVARCHAR(10) NOT NULL PRIMARY KEY,
> SupplierName NVARCHAR(50) NOT NULL,
> ...
> )
> CREATE TABLE ProductSupplier (
> ProductCode NVARCHAR(10) NOT NULL
> REFERENCES Product(ProductCode),
> SupplierCode NVARCHAR(10) NOT NULL
> REFERENCES Supplier(SupplierCode),
> ...,
> PRIMARY KEY (ProductCode, SupplierCode)
> )
> Now, for a product that is source from a supplier, I have multiple prices,
> depending on the quantity I ordered. How would I model this? Is the
> following correct?
> CREATE TABLE ProductSupplierPrice (
> ProductCode NVARCHAR(10) NOT NULL
> REFERENCES Product(ProductCode),
> SupplierCode NVARCHAR(10) NOT NULL
> REFERENCES Supplier(SupplierCode),
> Price MONEY NOT NULL,
> Qty BIGINT NOT NULL,
> PRIMARY KEY (ProductCode, SupplierCode)
> )
> Or, should I just have an identity column in ProductSupplier, and then
> references it from ProductSupplierPrice? Like this:
> CREATE TABLE ProductSupplier (
> ProductSupplierId INT NOT NULL PRIMARY,
> ProductCode NVARCHAR(10) NOT NULL
> REFERENCES Product(ProductCode),
> SupplierCode NVARCHAR(10) NOT NULL
> REFERENCES Supplier(SupplierCode),
> ...,
> ? UNIQUE INDEX (ProductCode, SupplierCode)
> )
> CREATE TABLE ProductSupplierPrice (
> ProductSupplierPriceId INT NOT NULL PRIMARY,
> ProductSupplierId INT NOT NULL
> REFERENCES ProductSupplier(ProductSupplierId),
> Price MONEY NOT NULL,
> Qty BIGINT NOT NULL,
> PRIMARY KEY (ProductCode, SupplierCode)
> )|||Thanks for the hint.
Evergray wrote:
>
> is incorrect
>
>
> is incorrect too because (as you've mentioned above) there are (possible)
> several prices for each product from each supplier depending on quantity.
> So, Qty column should also be a part of the primary key of
> ProductSupplierPrice table. But you may add surrogate key column to this
> table (not null'ed Identity with Unique index on it) for use in FK
> constraints, if needed.
>|||>> I have multiple prices, depending on the quantity I ordered. How would I
model this? <<
I know it is an example, but you might want to use reasonable data
types. Do you really expect a BIGINT quantity?
CREATE TABLE ProductQuantiyBreaks
(product_code CHAR(13) NOT NULL -- upc codes?
REFERENCES Products (product_code)
ON DELETE CASCADE
ON UPDATE CASCADE,
,supplier_id CHAR(10) NOT NULL --duns number
REFERENCES Suppliers(supplier_id),
ON DELETE CASCADE
ON UPDATE CASCADE,
low_qty INTEGER NOT NULL
CHECK(low_qty > 0),
high_qty INTEGER NOT NULL,
CHECK(low_qty < high_qty),
unit_price DECIMAL (12,5) NOT NULL,
PRIMARY KEY (product_code, supplier_id, low_qty));
Now fill in the discounts by (low_qty, high_qty) ranges so you can use
a BETWEEN predicate to locate the price of one unit. Never use
IDENTITY, since it is non-relational; never use MONEY since it is
proprietary and has weird math results.|||Yeah, that's definitely easier when querying with the low_qty and high_qty.
Just one question, having
PRIMARY KEY (product_code, supplier_id, low_qty), does that mean the
table ProductQuantiyBreaks is independent of table ProductSupplier?
Sorry to ask this, but I'm still new to these composite keys.
Thanks
--CELKO-- wrote:
>
> I know it is an example, but you might want to use reasonable data
> types. Do you really expect a BIGINT quantity?
> CREATE TABLE ProductQuantiyBreaks
> (product_code CHAR(13) NOT NULL -- upc codes?
> REFERENCES Products (product_code)
> ON DELETE CASCADE
> ON UPDATE CASCADE,
> ,supplier_id CHAR(10) NOT NULL --duns number
> REFERENCES Suppliers(supplier_id),
> ON DELETE CASCADE
> ON UPDATE CASCADE,
> low_qty INTEGER NOT NULL
> CHECK(low_qty > 0),
> high_qty INTEGER NOT NULL,
> CHECK(low_qty < high_qty),
> unit_price DECIMAL (12,5) NOT NULL,
> PRIMARY KEY (product_code, supplier_id, low_qty));
> Now fill in the discounts by (low_qty, high_qty) ranges so you can use
> a BETWEEN predicate to locate the price of one unit. Never use
> IDENTITY, since it is non-relational; never use MONEY since it is
> proprietary and has weird math results.
>|||having PRIMARY KEY (product_code, supplier_id, low_qty), does that
mean the table ProductQuantiyBreaks is independent of table
ProductSupplier? <<
It means that price breaks are VERY dependent on suppliers. In fact
that important; you need to pick the cheapest guy
product_code supplier_id low_qty high_qty unit_price
========================================
================
1234567890123 1111122222 1 10 10.00
1234567890123 3333344444 1 5 10.00
1234567890123 3333344444 6 10 9.50
Both suppliers are the same up to quantity 5, so I would need to make a
decision. After that, go with 3333344444.|||Ok, I got it to work with:
REFERENCES ProductSupplier(Productcode, SupplierCode)
--CELKO-- wrote:
> having PRIMARY KEY (product_code, supplier_id, low_qty), does that
> mean the table ProductQuantiyBreaks is independent of table
> ProductSupplier? <<
> It means that price breaks are VERY dependent on suppliers. In fact
> that important; you need to pick the cheapest guy
> product_code supplier_id low_qty high_qty unit_price
> ========================================
================
> 1234567890123 1111122222 1 10 10.00
> 1234567890123 3333344444 1 5 10.00
> 1234567890123 3333344444 6 10 9.50
> Both suppliers are the same up to quantity 5, so I would need to make a
> decision. After that, go with 3333344444.
>

Wednesday, March 7, 2012

How to delete Guest user, via group membership

Dear all
In my databases I can see the user Guest, via group membership, but I
can not delete it by any way. Is there any way to delete it?
RegardsHi
What does it mean via group membership?
Do you have permissions to drop logins?
<shahdharti@.gmail.com> wrote in message
news:1134650134.830481.233610@.z14g2000cwz.googlegroups.com...
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
>|||delete the row from sysusers table.
shahdharti@.gmail.com wrote:
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards|||ch
It is really deprecate to edit system tables
"ch" <ch@.dontemailme.com> wrote in message
news:43A16AB2.932AD7A0@.dontemailme.com...
> delete the row from sysusers table.
>
> shahdharti@.gmail.com wrote:
>> Dear all
>> In my databases I can see the user Guest, via group membership, but I
>> can not delete it by any way. Is there any way to delete it?
>> Regards|||In Enterprise manager when I see users list I see the Guest user and in
status column I see 'via group membership'.
In sysusers system table I can found guest user.
sp_helpuser does not show guest user.
When I try to delete I get error :15008 user Guest does not exist in
the current database.
Regards|||Hi
Why would you want to delete a rows from system table?
<shahdharti@.gmail.com> wrote in message
news:1134653831.421300.138100@.z14g2000cwz.googlegroups.com...
> In Enterprise manager when I see users list I see the Guest user and in
> status column I see 'via group membership'.
> In sysusers system table I can found guest user.
> sp_helpuser does not show guest user.
> When I try to delete I get error :15008 user Guest does not exist in
> the current database.
> Regards
>|||What version? 2000 or 2005?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
<shahdharti@.gmail.com> wrote in message
news:1134650134.830481.233610@.z14g2000cwz.googlegroups.com...
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
>|||SQL Server 2000, SP3.
One more strange matter , when I register server in my coleagues PC ,
it is not showing Guest user there.
On my pc all servers which are registered I am seeing Guest user,
having status via group memeber ship.
I want to remove this guest for all servers from my PC.
Regards|||The user doesn't really exists in the real sense. Try
SELECT * FROM sysusers WHERE name = 'guest'
You will see that the column hasdbaccess is 0.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
<shahdharti@.gmail.com> wrote in message
news:1134653831.421300.138100@.z14g2000cwz.googlegroups.com...
> In Enterprise manager when I see users list I see the Guest user and in
> status column I see 'via group membership'.
> In sysusers system table I can found guest user.
> sp_helpuser does not show guest user.
> When I try to delete I get error :15008 user Guest does not exist in
> the current database.
> Regards
>|||Have you got the SQL2005 tools installed? The version of SQLDMO installed by
the SQL2005 tools issues a slightly different query to enumerate database
users than the SQL2000 versions. This has the side effect of the guest user
showing up in all databases when viewed via Enterprise Manager. If you open
EM on the server itself (assuming there are no SQL2005 components installed)
you should see that it doesn't show up (the default SQL2000 behaviour). This
is just a UI issue and nothing has actually changed on the server - it's
nothing to worry about.
--
HTH
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
<shahdharti@.gmail.com> wrote in message
news:1134650134.830481.233610@.z14g2000cwz.googlegroups.com...
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
>|||Hi Jasper!
Thanks for that! I thought I was going crazy when looking at this (for this posts sake) and noticed
that guest show up in each database even if it "doesn't exist". I was close to dead certain that
this isn't the normal behavior... :-)
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Jasper Smith" <jasper_smith9@.hotmail.com> wrote in message
news:%23wGk9QaAGHA.3872@.TK2MSFTNGP12.phx.gbl...
> Have you got the SQL2005 tools installed? The version of SQLDMO installed by the SQL2005 tools
> issues a slightly different query to enumerate database users than the SQL2000 versions. This has
> the side effect of the guest user showing up in all databases when viewed via Enterprise Manager.
> If you open EM on the server itself (assuming there are no SQL2005 components installed) you
> should see that it doesn't show up (the default SQL2000 behaviour). This is just a UI issue and
> nothing has actually changed on the server - it's nothing to worry about.
> --
> HTH
> Jasper Smith (SQL Server MVP)
> http://www.sqldbatips.com
> I support PASS - the definitive, global
> community for SQL Server professionals -
> http://www.sqlpass.org
> <shahdharti@.gmail.com> wrote in message
> news:1134650134.830481.233610@.z14g2000cwz.googlegroups.com...
>> Dear all
>> In my databases I can see the user Guest, via group membership, but I
>> can not delete it by any way. Is there any way to delete it?
>> Regards
>|||Thanks Jasper
You are right. Its a relief for me.
Regards|||jasper, you should have also posted this response in my thread titled
"how did guest get back into all of my databases?" ;)
thanks for the info.
Jasper Smith wrote:
> Have you got the SQL2005 tools installed? The version of SQLDMO installed by
> the SQL2005 tools issues a slightly different query to enumerate database
> users than the SQL2000 versions. This has the side effect of the guest user
> showing up in all databases when viewed via Enterprise Manager. If you open
> EM on the server itself (assuming there are no SQL2005 components installed)
> you should see that it doesn't show up (the default SQL2000 behaviour). This
> is just a UI issue and nothing has actually changed on the server - it's
> nothing to worry about.
> --
> HTH
> Jasper Smith (SQL Server MVP)
> http://www.sqldbatips.com
> I support PASS - the definitive, global
> community for SQL Server professionals -
> http://www.sqlpass.org
> <shahdharti@.gmail.com> wrote in message
> news:1134650134.830481.233610@.z14g2000cwz.googlegroups.com...
> > Dear all
> >
> > In my databases I can see the user Guest, via group membership, but I
> > can not delete it by any way. Is there any way to delete it?
> >
> > Regards
> >

How to delete Guest user, via group membership

Dear all
In my databases I can see the user Guest, via group membership, but I
can not delete it by any way. Is there any way to delete it?
RegardsHi
What does it mean via group membership?
Do you have permissions to drop logins?
<shahdharti@.gmail.com> wrote in message
news:1134650134.830481.233610@.z14g2000cwz.googlegroups.com...
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
>|||delete the row from sysusers table.
shahdharti@.gmail.com wrote:
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards|||ch
It is really deprecate to edit system tables
"ch" <ch@.dontemailme.com> wrote in message
news:43A16AB2.932AD7A0@.dontemailme.com...[vbcol=seagreen]
> delete the row from sysusers table.
>
> shahdharti@.gmail.com wrote:|||In Enterprise manager when I see users list I see the Guest user and in
status column I see 'via group membership'.
In sysusers system table I can found guest user.
sp_helpuser does not show guest user.
When I try to delete I get error :15008 user Guest does not exist in
the current database.
Regards|||Hi
Why would you want to delete a rows from system table?
<shahdharti@.gmail.com> wrote in message
news:1134653831.421300.138100@.z14g2000cwz.googlegroups.com...
> In Enterprise manager when I see users list I see the Guest user and in
> status column I see 'via group membership'.
> In sysusers system table I can found guest user.
> sp_helpuser does not show guest user.
> When I try to delete I get error :15008 user Guest does not exist in
> the current database.
> Regards
>|||What version? 2000 or 2005?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
<shahdharti@.gmail.com> wrote in message
news:1134650134.830481.233610@.z14g2000cwz.googlegroups.com...
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
>|||SQL Server 2000, SP3.
One more strange matter , when I register server in my coleagues PC ,
it is not showing Guest user there.
On my pc all servers which are registered I am seeing Guest user,
having status via group memeber ship.
I want to remove this guest for all servers from my PC.
Regards|||The user doesn't really exists in the real sense. Try
SELECT * FROM sysusers WHERE name = 'guest'
You will see that the column hasdbaccess is 0.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
<shahdharti@.gmail.com> wrote in message
news:1134653831.421300.138100@.z14g2000cwz.googlegroups.com...
> In Enterprise manager when I see users list I see the Guest user and in
> status column I see 'via group membership'.
> In sysusers system table I can found guest user.
> sp_helpuser does not show guest user.
> When I try to delete I get error :15008 user Guest does not exist in
> the current database.
> Regards
>|||Have you got the SQL2005 tools installed? The version of SQLDMO installed by
the SQL2005 tools issues a slightly different query to enumerate database
users than the SQL2000 versions. This has the side effect of the guest user
showing up in all databases when viewed via Enterprise Manager. If you open
EM on the server itself (assuming there are no SQL2005 components installed)
you should see that it doesn't show up (the default SQL2000 behaviour). This
is just a UI issue and nothing has actually changed on the server - it's
nothing to worry about.
HTH
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
<shahdharti@.gmail.com> wrote in message
news:1134650134.830481.233610@.z14g2000cwz.googlegroups.com...
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
>

How to delete Guest user, via group membership

Dear all
In my databases I can see the user Guest, via group membership, but I
can not delete it by any way. Is there any way to delete it?
Regards
Hi
What does it mean via group membership?
Do you have permissions to drop logins?
<shahdharti@.gmail.com> wrote in message
news:1134650134.830481.233610@.z14g2000cwz.googlegr oups.com...
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
>
|||delete the row from sysusers table.
shahdharti@.gmail.com wrote:
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
|||ch
It is really deprecate to edit system tables
"ch" <ch@.dontemailme.com> wrote in message
news:43A16AB2.932AD7A0@.dontemailme.com...[vbcol=seagreen]
> delete the row from sysusers table.
>
> shahdharti@.gmail.com wrote:
|||In Enterprise manager when I see users list I see the Guest user and in
status column I see 'via group membership'.
In sysusers system table I can found guest user.
sp_helpuser does not show guest user.
When I try to delete I get error :15008 user Guest does not exist in
the current database.
Regards
|||Hi
Why would you want to delete a rows from system table?
<shahdharti@.gmail.com> wrote in message
news:1134653831.421300.138100@.z14g2000cwz.googlegr oups.com...
> In Enterprise manager when I see users list I see the Guest user and in
> status column I see 'via group membership'.
> In sysusers system table I can found guest user.
> sp_helpuser does not show guest user.
> When I try to delete I get error :15008 user Guest does not exist in
> the current database.
> Regards
>
|||What version? 2000 or 2005?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
<shahdharti@.gmail.com> wrote in message
news:1134650134.830481.233610@.z14g2000cwz.googlegr oups.com...
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
>
|||SQL Server 2000, SP3.
One more strange matter , when I register server in my coleagues PC ,
it is not showing Guest user there.
On my pc all servers which are registered I am seeing Guest user,
having status via group memeber ship.
I want to remove this guest for all servers from my PC.
Regards
|||The user doesn't really exists in the real sense. Try
SELECT * FROM sysusers WHERE name = 'guest'
You will see that the column hasdbaccess is 0.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
<shahdharti@.gmail.com> wrote in message
news:1134653831.421300.138100@.z14g2000cwz.googlegr oups.com...
> In Enterprise manager when I see users list I see the Guest user and in
> status column I see 'via group membership'.
> In sysusers system table I can found guest user.
> sp_helpuser does not show guest user.
> When I try to delete I get error :15008 user Guest does not exist in
> the current database.
> Regards
>
|||Have you got the SQL2005 tools installed? The version of SQLDMO installed by
the SQL2005 tools issues a slightly different query to enumerate database
users than the SQL2000 versions. This has the side effect of the guest user
showing up in all databases when viewed via Enterprise Manager. If you open
EM on the server itself (assuming there are no SQL2005 components installed)
you should see that it doesn't show up (the default SQL2000 behaviour). This
is just a UI issue and nothing has actually changed on the server - it's
nothing to worry about.
HTH
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
<shahdharti@.gmail.com> wrote in message
news:1134650134.830481.233610@.z14g2000cwz.googlegr oups.com...
> Dear all
> In my databases I can see the user Guest, via group membership, but I
> can not delete it by any way. Is there any way to delete it?
> Regards
>

Friday, February 24, 2012

how to delete a specific record inside a DB?

In one of our DB's, we've got a corrupted record. My question to this group,
is there a command to delete a specific record out of the DB? If so, what
all information do i have to provide to the command, so it specifies this
record. Any help is greatly appreciated
Ken Zimmerman
MIS Dept
American Red Cross
The DELETE statement deletes a row identified by its column values. If you
aren't sure what the key columns of the table are then before you delete
anything you'll want to be sure you've found the right row(s). Check by
using a SELECT statement to view the data you are going to delete. For
example:
SELECT *
FROM YourTable
WHERE col1 = 'X'
AND col2 = 'Y'
Once you're happy that you've defined the correct criteria for the row(s)
you want to delete:
DELETE
FROM YourTable
WHERE col1 = 'X'
AND col2 = 'Y'
May be wise also to make sure you have a recent backup before deleting
anything.
David Portas
SQL Server MVP
|||KZimmerman wrote:
> In one of our DB's, we've got a corrupted record. My question to
> this group, is there a command to delete a specific record out of the
> DB? If so, what all information do i have to provide to the command,
> so it specifies this record. Any help is greatly appreciated
> Ken Zimmerman
> MIS Dept
> American Red Cross
I assume by corrupted, you mean that there is strange data in one of the
columns and you believe this to be a "bad" data issue, not a corruption
in the database.
If so, use David's recommendation and locate the primary key for the row
or rows with the problem so you can issue a delete statement to remove
them from the database.
If this is a database corruption issue, try issuing DBC CHECKDB on the
database to check for problems.
David G.
|||If none of that works. you might back up your database and try.
Dbcc checkdb repair_allow_data_loss (read about this in books on line first)
or
export the rows out using bcp ( you'll get the rows you can see)
truncate the table and re-import them (Be careful to get all of the rows ,
you might have to do some tricks to select forward (and it dies when you get
to the bad row, then select backwards to get the rows on the other side.)
Also,
Call MS Tech support, I think they have some tools which might be useful I
think their fee is $250... Not much considering the time you might spend
messing with this ( if the data is important.)
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"KZimmerman" <KZimmerman@.discussions.microsoft.com> wrote in message
news:1087034D-3D76-4827-9166-EA3AB7D6CE91@.microsoft.com...
> In one of our DB's, we've got a corrupted record. My question to this
group,
> is there a command to delete a specific record out of the DB? If so, what
> all information do i have to provide to the command, so it specifies this
> record. Any help is greatly appreciated
> Ken Zimmerman
> MIS Dept
> American Red Cross

How to delete a group of stored procedures

For reasons I won't go into I have a need to delete over a 100 stored procedures from a database. The stored procedures have a common prefix such as dbo.aspnet_createUser.

I'm trying to come up with something that will allow me to delete all procedures that contain aspnet in their name.

The only thing close I've found is CONTAINS but I get an error I can use it against sysobjects because it isn't indexed.

Any ideas of how I can go about doing this other than deleting each one by hand?

ThanksExecute this in query analyzer or management studio, copy the output, paste

to the top pane, and run again:

SELECT 'DROP PROCEDURE dbo.'+ROUTINE_NAME+';'

FROM INFORMATION_SCHEMA.ROUTINES

WHERE ROUTINE_TYPE='PROCEDURE'

AND ROUTINE_SCHEMA='dbo'

AND ROUTINE_NAME LIKE 'aspnet[_]%'

wrote in message

news:d05d74cc-5383-4e2c-93ab-3182561f2726@.discussions.microsoft.com...

> For reasons I won't go into I have a need to delete over a 100 stored

> procedures from a database. The stored procedures have a common prefix

> such as dbo.aspnet_createUser.

>

> I'm trying to come up with something that will allow me to delete all

> procedures that contain aspnet in their name.

>

> The only thing close I've found is CONTAINS but I get an error I can use

> it against sysobjects because it isn't indexed.

>

> Any ideas of how I can go about doing this other than deleting each one

> by hand?

>

> Thanks

>|||

Thank you! Worked like a champ.

Could you by chance recommend a good book with examples for somebody interested in learning Transact-SQL to come up with statements such as you provided?

Thanks again!