Permissions in SQL Server 2008 - sql

I have created 10 database of 'Northwind' for training purpose. Suppose I have 10 students, so databases are Northwind_Student1,Northwind_Student2 etc. I would like to create separate login for each pupil, so that Student1 can only see(or can access) the data base 'Northwind_Student1'. How can I accomplish this using T-SQL or SSMS 2008 ?

You can create different users for different databases and assign permissions like below. It's for SQL 2008, but it will be same for 2005 also :

In SSMS, expand the Security tree of the server in Object Explorer and right-click Logins to choose New Login..., then add as many as needed.
Then in the Security tree of each individual database, add the login as a user of that db and grant appropriate rights.

Create 10 different logins and assign each to the database it can access.

CREATE LOGIN yourloginname WITH PASSWORD = 'yourpassword'

Related

How can I query the list of database roles in a SQL Server 2000 database?

In Sql Server 2000, is it possible to return, via SQL query, a complete list of database roles that exist in a given database?
I know it is possible to see these roles by expanding the Security, Roles, and Database Roles nodes in SQL Server Management Studio, but I'd like to get them through a query that I can parse programmatically.
To clarify, I'm not looking for a list of users with their roles, but just the list of roles themselves.
Every database in SQL Server 2000 has a sysusers system table
Probably something like
Use <MyDatabase>
Select
[name]
From
sysusers
Where
issqlrole = 1
will do the trick
With our SQL Server 2016 this works for me
Use Sandbox
Select
name, principal_id
From
sys.database_principals
Where
type = 'R' and principal_id < 16384
where Sandbox is the name of my database.
(I'm using SQL with ESRI ArcGIS Enterprise 10.6.)

can not retrieve data from sql server

I can not retrieve data from db in sql server.
I use the c3p0 as the pool,this is the c3p0.properties:
c3p0.user=test
c3p0.password=123456
c3p0.jdbcUrl=jdbc:sqlserver://xxxxxx:1433;databaseName=TIMDB;SelectMethod=cursor
c3p0.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver
c3p0.maxPoolSize=15
c3p0.testConnectionOnCheckin=true
c3p0.idleConnectionTestPeriod=3600
In the sql server,I have create a new user named test,and its default db is TIMDB,the server roles is public,and this is the user mapping:
But when I start the application,I can get nothing.
From the log created by log4j,I can get the sql used to retrieve data,but if I copy the sql to the sql management stutio and create a new query,I can retrieve some data.
I wonder why?
It looks like a permissions problem to me. If the generated SQl runs when you use it in management studio (i.e under your user account) then you know the code is good. What access have you given the user "test" from your post I see "user mapping: enter image description here"? he will need at least db_datareader and possibly more depending on what code is generated.
You could also try logging on to SQL Management studio under your "test" user and see if you can execute the code. That will eliminate the possibility that its something wrong with your application/network.

Adding tables to sql server result in Domain\user.name.tablename

Our app uses migratordotnet to modify the backing SQL Server 2005 database. This works great 99% of the time but we are running into an issue. We have a client that is using and Active Directory group for sql server login and when new tables are added it creates them as Domain\login.table_name. What permissions are needed to be given to the AD group to add the tables as dbo.table_name? This does not happen in with all of our clients with similar configurations so I must be missing something.
Make sure that the default schema for that login / group is set to dbo.
Can you set the default schema for a group? I was unable to do that using the management studio. I am trying a solution now that specifies the schema "dbo.table_name"

Retrieving users for specific SQL Server databases

I have a few SQL Server databases (all in one server), containing their own set of users. Now I'm trying to design a small application that would query those users and then display them in a report (TBD). I've looked over online how to do this, however I didn't find any. Is it possible in SQL Server to retrieve all the users of a database? If so, how?
On SQL Server 2005 and up:
connect to that specific database you're interested in
USE Databasename
execute this query
SELECT * FROM sys.database_principals
That gives you a slew of information on all users defined in the database
See the MSDN documentation for a detailed explanation of all rows returned from that view.

How do I create a user account in SQL Server 2000?

My project needs a SQL Server 2000 User Id and password created for an ASP.NET website. How do I create a user account in SQL Server 2000?
Basically, you'll have to run the system stored proc sp_addlogin.
See Example "A" in the link.
I've always used the SQL-Enterprise manager to create the user accounts and set the permissions for the databases and the access. See this intro tutorial.