Pages

Wednesday, 11 July 2012

Difference Between Oracle and Sql Server in terms of Object Name Unique

SQL SERVER:

In SQL Server, objects must be unique within users.

This allows two users to own an object with the same name.

For example, consider two users in a certain database. Each one of these two users could own a table with the same name. Therefore, in this case, there would be two tables with the same name in the database.

In the following example, users user1 and user2 successfully create a table with the same name (Tablex) in the Northwind database.

Using Query Analyzer, connect to SQL Server with the sa login and execute the following code, which creates both logins (login1 and login2 with blank password), adds users (user1 and user2) to the Northwind database for these logins, and grants CREATE DATABASE permissions to these two users:

USE Northwind

EXEC sp_addlogin 'login1'
EXEC sp_addlogin 'login2'
EXEC sp_adduser 'login1','user1'
EXEC sp_adduser 'login2','user2'

GRANT CREATE TABLE TO user1

GRANT CREATE TABLE TO user2
GO

Using Query Analyzer, open another connection to SQL Server, but use the newly created login1 login with blank password, and execute the following code:

USE Northwind
CREATE TABLE Tablex
 (col1 INT)
GO

Using Query Analyzer, open a third connection to SQL Server using the newly created login2 login with blank password, and execute the following code:

USE Northwind
CREATE TABLE Tablex
 (col1 INT)
GO

Finally, to check that both tables were successfully created, execute the following code from the first connection (the one with the sa login):
USE Northwind
PRINT 'user1'
SELECT * FROM user1.Tablex
PRINT 'user2'
SELECT * FROM user2.Tablex
GO

OutPut: 
user1
col1
-----------
(0 row(s) affected)

user2
col1
-----------
(0 row(s) affected)

need to countinue...

No comments:

Post a Comment