Login different to Login Name - sql-server-2005

I am currently working with SQL Server 2005 and I had the question arising whether you can have a Login with a different Loginname. I came to ask the question as the query
SELECT * FROM master.sys.syslogins
throws up, amongst others, the two columns "name" and "loginname" both displaying the same values.
So I asked myself if it was possible to have a Login called "XTest" where the user can actually log on with the Username "Test"...

No, it is not possible! Both columns have always the save value. You should not use sys.syslogins (in any database) at all in any current SQL Server version. This table is still provided for backward compatibility, use sys.server_principals and sys.sql_logins instead.

Related

How can I get a query of possible login names for SQL job owner?

I'm trying to get the list of all possible login names for a job owner. The following query
SELECT * FROM sys.syslogins
WHERE hasaccess=1
gives me close to what I'm looking for but it returns additional login names that I do not find in the Browse Objects dialog box using SSMS (such as ##MS_AgentSigningCertificate## or BUILTIN\Administrators). I cannot find any logic in sys.syslogins table to discriminate those records. I looked in other logins tables but nothing comes closer than sys.syslogins.
SQL Server is version 10.50 (2008R2) but I'm looking for a query that will give me the results for this version or earlier.
What am I missing?
#Larnu pointed me in the right direction.
Query that solves my question is:
SELECT * FROM sys.server_principals
WHERE [type] IN ('S', 'U')

How can I get the current user in Microsoft SQL Server? [duplicate]

This question already has an answer here:
SQL Server - current user name
(1 answer)
Closed 3 years ago.
I am trying to get the current user logged into my Microsoft SQL Server database.
After some research, I have found functions such as CURRENT_USER or USER, which are supposed to show me the user I am using at that moment.
SELECT USER, CURRENT_USER
The problem is that these functions keep giving me dbo as the result, which is, as far as I know, the schema I am using.
Am I not using the correct functions?
Maybe there is any problem with my users?
You can use SUSER_NAME() instead of SYSTEM_USER. From the manual of SUSER_NAME(),
Returns the login identification name of the user.
You need SUSER_NAME(), which gives you the login identification of the current user.
Try this
SELECT SYSTEM_USER
To understand regarding why you get dbo as answer, suggest reading this
You may use SYSTEM_USER in order to get current username.
You might refer link below to get more details.
https://learn.microsoft.com/en-us/sql/t-sql/functions/system-user-transact-sql?view=sql-server-2017

SQL select by field acting weird

I am writing this post because I have encountered something truly weird with an SQL statement I am trying to make.
Context:
I am developing an app which uses JPA in the backend to persist / retrieve objects to/from a postgres database.
Problem:
During some tests I have noticed that when a particular user adds entries in the database and later I try to fetch them by his facebook id, the result is an empty list, even though the entries are there in the database. Doing a select statement on the database returns no rows. This does not happen with other users.
I have noticed that the mentioned user's facebook id is slightly longer then others. I do not know if and how this affects this situation.
Interesting part:
When during debugging I created an entry not programmatically, but manually with a SQL INSERT statement directly on the database (marked red on the 1st screenshot), I could fetch the data by facebook id both in my app and with a select statement.
Do you have any ideas what is going on here?
Please check the screenshots:
result of select * from table:
result of select * from table where user_facebook_id = 10215905779020408 :
Please help,
Thanks

Windows Login Names and their impact on SQL Server 2005

Does anyone know of the impact on SQL Server of adopting 'two part' user Windows Loginnames in the form "fred.bloggs" instead of "bloggsf"?
I have scoured the Microsoft Knowledgebase and can nothing clear about one or the other: only that all examples shown by them are in the 'single word' format.
I have tried to use fred.bloggs ( that is fred dot bloggs ) in some SQL statements and get error messages, so they obviously cannot be used in a straight forward form.
You need to wrap a login like this in brackets, like: [your.login]
There is no impact on the SQL Server engine and performance.
A user name is a user name, whether there is a . in the middle or not.
The only issue is that of how the name is interpreted - ensure you use [] when specifying a user name, otherwise SQL will interpret the part before the . as a schema name.
So, for CREATE LOGIN, you should do:
CREATE LOGIN [xxxxx.yyyyy]

Access 2007 to Oracle 10g linked table -- query with flawed results, but no errors thrown

Access 2007 databases querying linked oracle 10g tables are returning flawed result sets when using the WHERE clause to filter-out unwanted records. Oddly, some filtering is happening, but not reliably.
I can reliably demonstrate/produce the problem like this:
Create a *new* database with Access 2007.
Create a second *new* database with Access 2007, and then "save-as" 2000.
Create a third *new* database with an older version of Access.
Run the following query in each database:
SELECT
STATUS,
ID,
LAST_NAME,
FIRST_NAME
FROM
Oracle10g_table
WHERE
STATUS="A"
In both databases created with Access 2007, running this query will give you a result set in which some of the records where (STATUS="A") = false have been filtered out, but not all of them.
In databases created with older versions of access, the where clause filters properly, and the result set is correct.
STATUS is a text field
The table is a "linked" table to an Oracle10g Database
The table has 68k rows
I've tested my timeout at 60, 1000 and 0
Has anyone run into this problem?
I wonder if this is a new "feature" of access that will also affect 2010. Could this have anything to do with ODBC?
Thanks for any help,
- dave
MORE...
I just tried an alternate form of the query, using HAVING instead of WHERE, and it worked! Problem is, besides that this shouldn't change anything (yes -- more virtual tables, but shouldn't change the end result) my end-users will be using the Access 2007 visual query designer, not typing SQL directly, which is going to default any criteria they enter into a WHERE.
My hunch is that one of your ODBC drivers used by Access to connect to Oracle is treating "A" as a column name not the literal 'A'. Have you tried single quotes on the 'A'? In Oracle double quotes are used to reference column names, is there a column named "A" by any chance?
Oracle Query Example #1
Select object_name from all_objects
where "OBJECT_NAME" = 'DUAL'
Oracle Query Example #2
with example as (
Select object_name as "Fancy Column Name" from all_objects
)
select * from example
where "Fancy Column Name" = 'DUAL'
I've had a similar problem. In my case, changing the ODBC driver worked, but I could also just change the 'unique record identifier' to a column with no nulls in it. It still doesn't have to be the "right" unique record identifier.
This turned-out to be an ODBC-related issue. Our tech support service unit installs connectivity on each of our workstations -- they program it themselves, and who knows what they actually put into it -- but the net result is that when you link to an ODBC datasource with Access (of any version), our network servers show-up in the 'machine data source' tab, so we just click on the one we want and away we go. This has worked well until Access 2007.
What I did was create a "new" machine data source, which let me choose the ODBC driver myself (instead of making me use the one our tech support folks created). I picked "Microsoft ODBC for Oracle", entered the name of the server I wanted, and that all it took. Now the WHERE-clause inconsistent filtering problem is solved (I hope).
The only thing remaining is to send this back to our tech support folks, so they can clean-up their installation. Should I ask for hazard pay? :-) hehe