Monday, March 12, 2012
List only the visible columns in a view?
row for every column in a view including those that might not be visible but
used only in the WHERE or ORDER BY clauses for example.
Is there an easy way to reduce the list to only show the columns that
actually appear in the SELECT clause of the view definition?
I've tried examining Profiler when expanding the columns node under the View
in Management Studio as it seems to load only one node per visible column
but haven't been able to make much sense of how it does this.
BTW I'm using that view as it promises to only show views and columns "to
which the current user has permissions". Is this reliable or is there a
preferred way of listing visible views, talbe, & columns etc?
cheers,
Paul.Hi, Paul
Look in the INFORMATION_SCHEMA.COLUMNS view.
Razvan|||Use the catalog schema views...
SELECT
name
FROM
sys.columns
WHERE
object_id = OBJECT_ID('dbo.YourViewName');
"Paul Ritchie" <REMOVEpritchie@.REMOVExtra.REMOVEco.REMOVEnz> wrote in
message news:%23S90IfVBGHA.4004@.TK2MSFTNGP15.phx.gbl...
> In SQL Server 2005, when using INFORMATION_SCHEMA.VIEW_COLUMN_USAGE I get
> a
> row for every column in a view including those that might not be visible
> but
> used only in the WHERE or ORDER BY clauses for example.
> Is there an easy way to reduce the list to only show the columns that
> actually appear in the SELECT clause of the view definition?
> I've tried examining Profiler when expanding the columns node under the
> View
> in Management Studio as it seems to load only one node per visible column
> but haven't been able to make much sense of how it does this.
> BTW I'm using that view as it promises to only show views and columns "to
> which the current user has permissions". Is this reliable or is there a
> preferred way of listing visible views, talbe, & columns etc?
> cheers,
> Paul.
>|||Thanks Aaron - much appreciated.
Is there an easy way to determine which columns a user might have access to
when using the "sys" tables? That was what the INFORMATION_SCHEMA views
seemed to promise although there was some doubt in newsgroups as to their
accuracy in SQL2000 due to them being derived from the sysdepends table.
I'm betting that this will have changed in 2005.
However moving back to the sys tables/views will mean I have to determine
this permission information in some other way. Any seggestions would be
appreciated tremendously.
cheers,
Paul.
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:OCq14hWBGHA.1180@.TK2MSFTNGP09.phx.gbl...
> Use the catalog schema views...
> SELECT
> name
> FROM
> sys.columns
> WHERE
> object_id = OBJECT_ID('dbo.YourViewName');
>
> "Paul Ritchie" <REMOVEpritchie@.REMOVExtra.REMOVEco.REMOVEnz> wrote in
> message news:%23S90IfVBGHA.4004@.TK2MSFTNGP15.phx.gbl...
>|||> Is there an easy way to determine which columns a user might have access
> to when using the "sys" tables?
Take a look at sys.database_permissions
I believe the join between sys.database_permissions p and sys.comments c
would be:
ON
c.object_id = p.major_id
AND c.column_id = p.minor_id
WHERE
p.class = 1
AND p.grantee_principal_id = SUSER_ID('username');
I am not 100% sure on that, and don't have time today to experiment with
column-level permissions. But hopefully that gets you started.
> accuracy in SQL2000 due to them being derived from the sysdepends table.
Permissions derived from sysdepends? I think that is inaccurate.
A
List of tables
Is there any command to find all the tables(including system tables) in SQLserver(I do not want to use enterprise manager).
Regards,Originally posted by sursujmad
Hi,
Is there any command to find all the tables(including system tables) in SQLserver(I do not want to use enterprise manager).
Regards,
You can use a sql request like this
select * from sysobjects where type = 's' or type = 'u'|||--Try
exec sp_tables
select user_name(uid)+'.'+name from sysobjects where xtype in ('U','S')
select * from information_schema.tables
Friday, March 9, 2012
List of Packaged XP's
Can somebody point me to where i can find a list (including what they do
with parameters) of all the Sp's and XP's that come with SQL 2000
Thanks
RegIn Books Online, look in the index for "system stored procedures, listed".
There are more SPs and XPs shipped with SQL Server than are listed there,
but these undocumented procedures can change without warning with a new
version, service pack or hotfix and use is at your own risk.
--
Jacco Schalkwijk
SQL Server MVP
"Reg Besseling" <reg.usenet.nospam@.epic-sc.com> wrote in message
news:JO-dnQYtM7TTyhyiU-KYhw@.is.co.za...
> Hi All
> Can somebody point me to where i can find a list (including what they do
> with parameters) of all the Sp's and XP's that come with SQL 2000
> Thanks
> Reg
>|||Probably the best reference for this is SQL Server Books
Online. Just go through the help file's index reviewing
sp_xxx and xp_xxxx.
-Sue
On Mon, 6 Oct 2003 13:53:49 +0200, "Reg Besseling"
<reg.usenet.nospam@.epic-sc.com> wrote:
>Hi All
>Can somebody point me to where i can find a list (including what they do
>with parameters) of all the Sp's and XP's that come with SQL 2000
>Thanks
>Reg
>|||Thanks - I was searching for xp_qv
"Jacco Schalkwijk" <NOSPAMjaccos@.eurostop.co.uk> wrote in message
news:elkk$cAjDHA.1956@.TK2MSFTNGP12.phx.gbl...
> In Books Online, look in the index for "system stored procedures, listed".
> There are more SPs and XPs shipped with SQL Server than are listed there,
> but these undocumented procedures can change without warning with a new
> version, service pack or hotfix and use is at your own risk.
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Reg Besseling" <reg.usenet.nospam@.epic-sc.com> wrote in message
> news:JO-dnQYtM7TTyhyiU-KYhw@.is.co.za...
> > Hi All
> >
> > Can somebody point me to where i can find a list (including what they do
> > with parameters) of all the Sp's and XP's that come with SQL 2000
> >
> > Thanks
> >
> > Reg
> >
> >
>|||Some information about xp_qv courtesy of Microsoft employee Gert Drapers:
"xp_qv, hosted in xpsqlbot.dll is a wrapper around functionality in
sqlboot.dll, which returns information about the SKU type, licensing etc
It is not documented that is why you can not find a reference.
I should be getting called very infrequently and as far as I know it only
visits the Registry"
Jacco Schalkwijk
SQL Server MVP
"Reg Besseling" <reg.usenet.nospam@.epic-sc.com> wrote in message
news:_cudnaOFzsXY5ByiU-KYiQ@.is.co.za...
> Thanks - I was searching for xp_qv
> "Jacco Schalkwijk" <NOSPAMjaccos@.eurostop.co.uk> wrote in message
> news:elkk$cAjDHA.1956@.TK2MSFTNGP12.phx.gbl...
> > In Books Online, look in the index for "system stored procedures,
listed".
> >
> > There are more SPs and XPs shipped with SQL Server than are listed
there,
> > but these undocumented procedures can change without warning with a new
> > version, service pack or hotfix and use is at your own risk.
> >
> > --
> > Jacco Schalkwijk
> > SQL Server MVP
> >
> >
> > "Reg Besseling" <reg.usenet.nospam@.epic-sc.com> wrote in message
> > news:JO-dnQYtM7TTyhyiU-KYhw@.is.co.za...
> > > Hi All
> > >
> > > Can somebody point me to where i can find a list (including what they
do
> > > with parameters) of all the Sp's and XP's that come with SQL 2000
> > >
> > > Thanks
> > >
> > > Reg
> > >
> > >
> >
> >
>|||Thanks for the prompt help
"Jacco Schalkwijk" <NOSPAMjaccos@.eurostop.co.uk> wrote in message
news:ux78ncBjDHA.2336@.TK2MSFTNGP11.phx.gbl...
> Some information about xp_qv courtesy of Microsoft employee Gert Drapers:
> "xp_qv, hosted in xpsqlbot.dll is a wrapper around functionality in
> sqlboot.dll, which returns information about the SKU type, licensing etc
> It is not documented that is why you can not find a reference.
> I should be getting called very infrequently and as far as I know it only
> visits the Registry"
>
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Reg Besseling" <reg.usenet.nospam@.epic-sc.com> wrote in message
> news:_cudnaOFzsXY5ByiU-KYiQ@.is.co.za...
> > Thanks - I was searching for xp_qv
> > "Jacco Schalkwijk" <NOSPAMjaccos@.eurostop.co.uk> wrote in message
> > news:elkk$cAjDHA.1956@.TK2MSFTNGP12.phx.gbl...
> > > In Books Online, look in the index for "system stored procedures,
> listed".
> > >
> > > There are more SPs and XPs shipped with SQL Server than are listed
> there,
> > > but these undocumented procedures can change without warning with a
new
> > > version, service pack or hotfix and use is at your own risk.
> > >
> > > --
> > > Jacco Schalkwijk
> > > SQL Server MVP
> > >
> > >
> > > "Reg Besseling" <reg.usenet.nospam@.epic-sc.com> wrote in message
> > > news:JO-dnQYtM7TTyhyiU-KYhw@.is.co.za...
> > > > Hi All
> > > >
> > > > Can somebody point me to where i can find a list (including what
they
> do
> > > > with parameters) of all the Sp's and XP's that come with SQL 2000
> > > >
> > > > Thanks
> > > >
> > > > Reg
> > > >
> > > >
> > >
> > >
> >
> >
>
Monday, February 20, 2012
list all duplicate names (query help)
1. how to list all duplicate customer names(occurring more than once), including frequency of occurrence.
2. find out how many customers have more than 2 account
Thanksselect customer, [number of accounts]=count(*)
from customer_account_table
group by customer
having count(*) > 1|||try this query
select cust_name , count(cust_name) from customer_table group by cust_name order by count(cust_name) desc|||Originally posted by ms_sql_dba
select customer, [number of accounts]=count(*)
from customer_account_table
group by customer
having count(*) > 1
Above is answer to question #1. Below is answer to question#2.
select count(*) from (
select customer, [number of accounts]=count(*)
from customer_account_table
group by customer
having count(*) > 1) as q|||actually, asnwer #1 lacks one line to become both #1 and #2:
select customer, [number of accounts]=count(*)
from customer_account_table
group by customer
having count(*) > 1
compute count(customer)
List all databases accessible by a login
Hi all. I am new to SQL-DMO so sorry if what i am asking is really easy.
Is it possible to get a list of all objects (including databases) which are accessible for a particular login.
So far I have:
Dim oSQLServer As SQLDMO.SQLServer
Dim oSQLDatabase As SQLDMO.Database
Dim oSQLLogin As New SQLDMO.Login
Dim oUser As New SQLDMO.User
oSQLServer = New SQLDMO.SQLServer
oSQLServer.Name = _oSQLServer.Host
' Check server is alive
If (oSQLServer.Status = SQLDMO.SQLDMO_SVCSTATUS_TYPE.SQLDMOSvc_Running) Then
Try
oSQLServer.LoginSecure = False
oSQLServer.Connect(_oSQLServer.Host, _oSQLServer.Login, _oSQLServer.Password)
For Each oSQLDatabase In oSQLServer.Databases
'oSQLDatabase.Users.
' Get a list of databases accessible by user
oSQLLogin.Name = _oSQLServer.Login
'oSQLObjectList = oSQLUser.ListOwnedObjects(SQLDMO.SQLDMO_OBJECT_TYPE.SQLDMOObj_Database)
'oSQLDMONameList = oSQLServer.ListMembers(SQLDMO.SQLDMO_ROLE_TYPE.SQLDMORole_All)
System.Diagnostics.Debug.Write(oSQLDatabase.Name.ToString & " : " & oSQLDatabase.IsUser(oSQLLogin.Name))
'oSQLDatabase.IsUser()
Next
Catch ex As Exception
System.Diagnostics.Debug.Write(ex.Message.ToString)
Finally
oSQLDatabase = Nothing
oSQLServer.DisConnect()
oSQLServer = Nothing
End Try
Else
System.Diagnostics.Debug.Write(oSQLServer.StatusInfoRefetchInterval( _
SQLDMO.SQLDMO_STATUSINFO_TYPE.SQLDMOStatInfo_All))
End If
The "oSQLLogin.Name = _oSQLServer.Login" statement does not seem to satisfy your requirements. Another side question, is there a particular reason why you are starting out with DMO? If not, you should consider using SMO, which ships with SQL Server 2005.
I have created a SMO program to meet your needs...The program checks to see if a user exists in the database. By access, you might want to check if the user has certain permissions. You may also need to deal with logins that are mapped to a different user name.
Server srv = new Server("MyServer"); //Yukon
srv.ConnectionContext.LoginSecure = true;
srv.ConnectionContext.Connect();
srv.DefaultTextMode = false;
string checkUser = "bob";
try
{
foreach (Database db in srv.Databases)
{
if (db.Users[checkUser] != null)
{
Console.WriteLine(checkUser + " has access to " + db.Name.ToString());
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
|||I am using DMO as when I wrote the specification for the project, I stated that I would be using SQL-DMO. SQL 2005 had not be released and I could not wait for release date, incase of delays.
I am able to get a list of accessible databases for a particular login using
Dim oSQLDatabase As SQLDMO.Database
......
System.Diagnostics.Debug.WriteLine(oSQLDatabase.UserName & " user within database " & oSQLDatabase.Name)
However, it throughs an exception when every it hits the 'model' databases, dont suppose anybody knows why?
Thanks
DAN
|||I tried the following code and it works against model (i.e no exception). What exception are you seeing? Which version of SQLDMO are you using -- located in "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn" folder? Which version of SQL Server are you targeting? (I am using the version of SQL-DMO that ships with SQL Server 2005 and I am targeting SQL Server 2000).
foreach (Interop.sqldmo._Database db in srv.Databases)
{
try
{
Console.WriteLine(db.Name + ":" + db.IsUser("bob"));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
|||Forget about the error, it was problem with the code else where in the applcation, conflicting names me thinks. Took your advice and moved over to SMO, after some alteration to the spec. Things a lot easier!
Thanks for your help Peter.