How Do I Reference A Table In One Database From A SQL Script Running In Another Database?

Jan 5, 2007

I am construvcting a number of databases, some of which contain
sensitive data and most of which do not. I am attempting to handle the
security issues involved in protecting sensitive data in part by
putting it in its own database. If the sensitive data is in a database
called d_SensitiveData, and in that database there is a table called
't_A' (I know, not very informative, but this is only a trivially
simple example :-), and I have a script running in a database
'NotSensitiveData' (i.e. there is a statement at the beginning of the
script "USE NotSensitiveData"), how do I referenece the primary key in
table 'A'?

I tried a variety of things like:

ALTER TABLE t_nsX
ADD CONSTRAINT FK_PersonID FOREIGN KEY (p_idPerson)
REFERENCES SensitiveData.t_A (p_idPerson);

The above is, in fact, my latest attempt. Everything I tried has
failed precisely at the point where I specify a table in a different
database. So what is the trick to refering to a table in one database
when using another database?

This will be used in a ASP.NET v3 application where one of the things I
want to do is have the authentication provider be a different database
from the one used for the main application data.

Does anyone know of an example I can download from the web that does
the same sort of thing I want to try, with some discussion of security
issues involved (i.e. what I can do to harden the application and data
server)?

NB: I am an application developer, not a DBA nor a system
administrator.

Thanks

Ted

View 6 Replies


ADVERTISEMENT

How To Reference A Table In A Different Database?

Apr 5, 2006

I have 2 databases in sql server. let us say database1 = db1 and database2 = db2
Now both the databases have a same table called table1 with the same fields.

IF data in db1.table1 is updated then data in db2.table2 should be updated automatically.

There are many ways we can do this. one way is to create a INSERT trigger on db1.table1.

But i would like to avoid trigger
Is there something in SQL server where I can just link table1 of db1 to db2 and delete the table1 in db2. That means db2 is using the same table that of db1.

Thanks

View 2 Replies View Related

How Do You Reference A Table In Another (SQL) Database In TSQL

Jan 9, 2001

Good afternoon one and all,

I am trying to write a query that will use tables in more than one SQL database (on the same server). How do refer to the table? I have tried dbasename.tablename.fieldname but I don't think that's working.

TIA for any and all help

Gurmi

View 3 Replies View Related

Transact SQL :: Database Constraint Check On Table With Reference Key

Jun 11, 2015

CREATE TABLE PRODUCT_SALES
(
Salesmanid BIGINT,
Productid BIGINT
)

INSERT INTO PRODUCT_SALES (Salesmanid,Productid) VALUES (1,1)
INSERT INTO PRODUCT_SALES (Salesmanid,Productid) VALUES (1,2)
INSERT INTO PRODUCT_SALES (Salesmanid,Productid) VALUES (1,3)

SELECT * FROM PRODUCT_SALES

/* SalesmanID is reference key from Sales Master and ProductID is reference key from Product Master. How should i restrict user through DB with any constraint check, if user tries to enter

INSERT INTO PRODUCT_SALES (Salesmanid,Productid) VALUES (1,2),

It should throw error , if possible user defined message would be more useful.

View 7 Replies View Related

SQL Server 2008 :: Queries Running Against To A Table In Database

Jun 15, 2015

How can we get most frequent queries that are running against to a table in our database?

View 3 Replies View Related

TempDB Log File Running Out Of Free Space While Running DBCC CheckDB On Large Database

May 28, 2015

In my environment, there is maintenance plan configured on one of the server and while running DBCC checkdb on a database of size around 200GB, log file usage of tempdb is increasing and causing the maintenance job to fail.

What can I do to make the maintenance job run successfully, size of the tempdb database is only 50GB and recovery model is set to simple. It cannot be increased as the mount point on which it is residing is 50GB.

View 3 Replies View Related

Any Way To Parameterize A Database Reference??

Mar 13, 2004

I need to refer to a second database from within the database that I login to. Can any one help me with how to abstract this reference? I would like to be able to change a parameter somewhere (i don't really care where) and have it effect any Stored Porcedure which references the second database.

View 1 Replies View Related

How To Make Database For Reference

Jun 9, 2014

I am making a project where I have to add city, agentname, rankofagent, referenceagent name the problem is that who can I make a table where suppose I add member a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p like that

b is joined by a
c is joined by b
d by c, e by d and so on,

What I want here is that how can I get the result suppose i want to see that chain of p. I want result to be printed as a,b,c,d,e,f,g,h,i,j,k,l,m,n,o either result should be in horizontal form or vertical. with or without comma. I am doing this in SQL....

View 2 Replies View Related

How To Reference Items From Different Database?

Jul 20, 2005

Hi all,I have two databases DB_External and DB_Internal.I am writing some stored procedures (in DB_Internal) that reads fromthe tables in DB_External. I execute my stored procedures fromDB_Internal.Everytime I want to read the tables in DB_External, I have to refer tothe table as DB_External.dbo.tableName.Is there a better way of declaring the database DB_External up frontin the stored procedure so I don't have to pre-fix "DB_External.dbo."in all the table names?Thanks in advance,June Moore.

View 1 Replies View Related

ForeignKey Reference With Another Database

Apr 29, 2008



Hi All,

I have a table [Vendor] in first database SAMPLEDB. And i have another table [Contract] in another database TESTDB. I need a foreign key in the [Contract] table (which is in TESTDB database) is reference to the other table [Vendor] which is present in the SAMPLEDB.
When i try to creating them through SQL, i received the following error message :

Msg 1763, Level 16, State 0, Line 1
Cross-database foreign key references are not supported. Foreign key 'SAMPLEDB..VENDOR'.


Is that possible to refer foreign key in external database or not?
If possible, please give solution for this. If not possible, please suggest some alternate way.


Thanks in Advance

View 8 Replies View Related

Invalid Object Name When Trying To Reference A Database

Mar 19, 2006

Hi There
Let me start by explaining what I am trying to achieve as there may be a better way to perform this. I have two databases and I want to refer to four tables - one in one database and three in the other in a sql select statement.
When I use the query builder in VWD I can only see tables for the database that is defined in the connection string - so therefore how do I add tables from another database? After reading a few posts I realized that all I have to do is use the syntax: database.owner.table (or [database].[owner].[table]). Unfortunately this didn't work and came up with the error "Invalid Object Name".
Assuming that I must have got the owner incorrect I used the Query Tool in SQL Server Express Edition and it worked perfectly! So my sql must be correct, but why will it not work inside VWD?
The two databases are named assessment and aspnetdb - the assessment database contains the table reviews and the aspnetdb database contains the tables TutorDetails, EmployerDetails and StudentDetails.
Here is the connection string and sql:
Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Assessment.mdf;Integrated Security=True;User Instance=True
SELECT Reviews.Programme, aspnetdb.dbo.TutorDetails.Tutor_DisplayName AS [Tutor Name],
aspnetdb.dbo.EmployerDetails.DisplayName AS [Employer Name], aspnetdb.dbo.StudentDetails.Student_DisplayName AS [Student Name]
FROM Reviews INNER JOIN
aspnetdb.dbo.StudentDetails ON Reviews.StudentID = aspnetdb.dbo.StudentDetails.Username INNER JOIN
aspnetdb.dbo.EmployerDetails ON Reviews.EmployerID = aspnetdb.dbo.EmployerDetails.UserName INNER JOIN
aspnetdb.dbo.TutorDetails ON Reviews.TutorID = aspnetdb.dbo.TutorDetails.UserName
WHERE (Reviews.ReviewID = 15)
Disregard the value of '15' in the WHERE statement as this was just put in to ensure I got some valid data back, this will be replaced with a variable eventually.
I know the sql statement works properly, I think the problem may be something to do with either the connection string - any ideas would be much appreciated.
Regards
Stuart

View 7 Replies View Related

Trying To Reference Another Database In Update Command On Same SQL Server

Aug 15, 2006

I'm trying to update a table in MyDB1 with a value in MyDB2 on the same SQL server (2000)

     UPDATE MyDB1.dbo.Users
     SET MyDB1.dbo.Users.InstantASP_UserID = MyDB2.dbo.InstantASP_Users.UserID
     FROM MyDB2
     INNER JOIN dbo.aspnet_Membership a ON a.UserId = MyDB1.dbo.Users.UserID
     WHERE MyDB2.dbo.InstantASP_Users.EmailAddress = a.Email

I don't want to have to create a linked server.  It's on the same box.

I'm getting Invalid object name 'MyDB2'.

View 1 Replies View Related

Connecting To Database - Object Reference Not Set Error Message

Feb 11, 2005

I've got code that on my own machine (visual studio .net 2003 and iis and sql server all exist on this box) works great. I display my test page, which loads a dropdownlist on page_load. This works great on my own machine.

When I move the code to our dev environment. Web server and database servers on separate boxes. I get the error "Object reference not set to an instance of an object" when i try to open the connection to the database. I thought it had to do with permissions and I check all through sql server and everything looks great. I then thought it was the connection string. I still haven't ruled this out, but I wrote a quick vbscript app to attach to the database and try to pull a record. The vbscript worked fine. So, the code works fine on my computer, but not on the web server. The connection does work with vbscript, but through my asp.net web app I get the "object reference" error.

All code below...

ASP.NET webpage:
private void Page_Load(object sender, System.EventArgs e)
{

if( !IsPostBack )
{
// Create a command object for the query
string mySelectQuery = "select id from vw_abcd order by ID";

SqlCommand myCommand = new SqlCommand(mySelectQuery,sqlConnection1);
sqlConnection1.Open();

DropDownList1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
DropDownList1.DataBind();
sqlConnection1.Close();

RangeValidator1.MinimumValue = "1";
RangeValidator1.MaximumValue = DropDownList1.Items.Count.ToString();
}
}

Connection string on my machine:
workstation id=wXXXXXX01;packet size=4096;user id=testuser;password=testpass;integrated security=SSPI;data source=wXXXXXX01;persist security info=False;initial catalog=TestDB"/>

Connection string on web server:
network library=DBMSSOCN;data source=xxx.xx.xxx.xxxinstance1;user id=testuser;password=testpass;initial catalog=TestDB


vbscript:
Dim connConnection, rstresultset
strConnectionString = "driver={Sql Server};server=xxx.xx.xxx.xxxinstance1;user id=testuser;password=testpass;database=TestDB"

Set connConnection = CreateObject("ADODB.Connection")

connConnection.Open strConnectionString
Set rstresultset = createobject("ADODB.Recordset")

rstresultset.ActiveConnection = connConnection

rstresultset.Open "select id, comment from testtable", connConnection

msgbox rstresultset(0)
msgbox rstresultset.Fields(0).Value



Error message and stack trace:
Object reference not set to an instance of an object.

at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at Web2.Drilldown.Page_Load(object sender, System.EventArgs e)




Any ideas what's going on?????

View 1 Replies View Related

SQL 2012 :: Unable To Add Service Reference In A CLR Database Project?

Apr 17, 2014

I created a CLR procedure with a service reference in Visual Studio 2010 that is being used in SQL Server 2008 R2. We recently tried to deploy it to a 2012 SQL Server, but were unable to due to compatibility issues. When I tried to upgrade the package to Visual Studio 2013 I got this error message:

Unable to cast object of type 'Microsoft.VisualStudio.Data.Tools.Package.Project.DatabaseFileNode' to type 'Microsoft.VisualStudio.Data.Tools.Package.Project.Internal.FolderNode'

I tried to create this using the 2012 Data Tools, but was unable to add a service reference with the GUI. It appears Microsoft has removed this functionality. My company has a third party app that we have limited control over, which is why we need this functionality.

[URL]

View 0 Replies View Related

SQL 2012 :: Suppress SSDT Database Reference Error

Aug 21, 2015

In database projects, VS2015, I want to create some views for me database that will reference another database table using 3 part naming reference.

Works fine in SSMS but when I try and build me project I is throwing up a reference error.

I can't import the other database into this project, so is there a way to suppress the error? I don't really want to exclude these view from the project.

View 5 Replies View Related

Copy A Database Table With All Its Data, Indexes And Constraints To A New Table In The Same Database

Feb 4, 2008

Hi,
How can I copy a database table with all its data, indexes and constraints to a new table in the same database in sql server 2005

View 7 Replies View Related

Running Total For Cell Reference In SQL Reports

Mar 19, 2007

Hi,

I'm trying to do running total of the calculated field. Here is the detail of my RDL:

In a table, I have "textbox34" with the formula =count(Fields!ADF_NO.Value) in it and "textbox30" with the formula =first(Fields!TOTSTKS2.Value, "ProdServSales") - reportitems!TOTSTKS.value in it. I have divided "textbox 34" with "textbox30", and placed the results in "textbox36". Now, I want to do a cummulative total (Running total) of "textbox36", using the formula =runningvalue(reportitems!textbox36.Value, sum, nothing) in "textbox14". Its giving me an error saying:

"[rsAggregateReportItemInBody] The Value expression for the textbox 'textbox14' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers."

Any suggestions? I appreciate your help on this.

Thanks

Perm

View 2 Replies View Related

How To Insert All Info From A Table Of Database To Onther Table Of Other Database?

Mar 16, 2004

I have two database and both of them has the same table, i want to copy all info from this first table to the secornd table

For Example:
Database : DB_1, table is table_1
Database : DB_2, table is table_2

both table_1 and table_2 have the same struct

how can i insert all records from table_1 to table_2

thanks

View 4 Replies View Related

How Can I Set A Update Trigger On A Table In Database A After A Record Had Been Updated From Another Database B?

Jan 22, 2008



Hi guys, may I know is it possible to create an update trigger like this ? Assuming there are two database, database A and database B and both are having same tables called 'Payments' table. I would like to update the Payments records on database A automatically after Payments records on database B had been updated. I can't use replication because both tables might having different records and some records are the same. Hope can get any assistance here, thank you.

Best Regards,
Hans

View 8 Replies View Related

Integration Services :: How To Insert / Update Table From Database 1 To Database 2

Oct 26, 2015

I am using two database server. Both are sql server. 

My task is :I want to insert data from server 1 table to server 2 table and update same when modified the existing data from server 1. is it possible to do the integration in single package.

I know to do insert and update seperately by ssis but need to do same with single task. 

View 5 Replies View Related

Best Way To Test To See If The Database Is Running?

Aug 7, 2007

Hello all-I need to check to see if the database is running before I begin all sorts of processing and figured I would do something like this.  Any better ways to do this?  I want to check to see if the db is up and running and also check to make sure I can connect to it.
Private Function DatabaseRunning() As Boolean
'Checks to see if the database is up and running.Dim objDataConnection As SqlConnection = New SqlConnection(ConnectionString)
Try
objDataConnection.Open()Catch ex As Exception
Return False
End Try
objDataConnection.Close()
Return True
End Function

View 3 Replies View Related

Running Statistics On A Database

Jun 2, 2005

How often should I run statistics on a database and what should I use? The create statistics function? Right now we have not run statistics against the database in over 8 months. However, we do have the database setup so that it will autocreate and auto update statistics on each table. Is this the best way to keep statistics up to date or is it better to run a function that rebuilds them on a nightly/weekly basis. Our database does have a large amount of activity against 99% of it takes place between 7am-6pm so the rest of the day/night we have open to schedule things like this. Any suggestions? I am really just trying to get a handle on the best way to keep our database running smoothly and quickly.

View 2 Replies View Related

Specify Database When Running A Report

Mar 4, 2008

Hi,

Currently I have a Report Model that uses a Data Source where the "Credentials are supplied by the user running the report". This works quite well.
The only further requirement is that I would also like to be able to specify which database to use (at runtime), would this be possible?



Kind Regards,
Robert

View 3 Replies View Related

Database Table Primary Key Question For Database Experts

Jan 17, 2008

Hi, I have a Users table that I use for membership. Now I am using username varchar(30) as the primary key for this table since username will always be unique.I am storing username in UsersInRole table so that I can find what roles each user has.The question I have is regarding how SQL Server actually stores data:I see that when I add users, they are always stored alphabetically sorted on username. I was expecting that all users will appear on the users table in the order they were added.Example: I have 3 users (john, jonah, wilson). Now I added 4 user with username='bob'If I execute select * from users, it returns me (bob, john, jonah, wilson). Look bob is has become the first row of the table.My question: Is Sql server moving 3 older rows to make room for 'bob' and it is also rebuilding part of the index due this new username 'bob'?If this is the case, then it will have big impact if I have 100K users and I add one user that becomes firstrow. In that case huge other rows will have to move.Bottom line, insert, delete will be expensive. I know sql server keeps data physically sorted on PK. But I am concerned here since rows are losing the order in which they were inserted.Thanks  

View 8 Replies View Related

How To Pull Existing Table From Database And Merge Into New Database

Apr 17, 2012

I am new to sql and my boss want me to write the program for database and he wants to pull the info from existing table from sql server which is used by Microsoft GP Dynamics and write me code or some kind of front end so when he wants he can pull same data from GP dynamics table and generate some report with other custom table.

How i can do this task? What I have to do in sql so I can use same table to view info in real time so that means if i enter new data in the table it will show up same time in the front end as well.

View 4 Replies View Related

How To Copy Table From Oracle Database To Sqlserver Database ?

Jul 20, 2005

Hello,I need to copy a table from an 8i oracle database to a sqlserver 2000 database.Is it possible to use the command "COPY FROM ... TO ..." ?So, what is the correct syntax ?Thanks for your helpCyril

View 1 Replies View Related

Updating A Table On My Hosted Database From A Local Database

Aug 1, 2007

Hi,

How do I insert data that I have collected in a local database onto a table on my online ie hosted database which is on a different server?

At the moment I am just uploading all the data to the hosted DB but this is wasting bandwith as only a small percentage of data is actually selected and used.

I thought that if i used a local DB and then update the table on my hosted DB this would be much more efficient, but I am not sure how to write the SQL code to do this!

Do I do some kind of

INSERT INTO sample_table

SELECT xxx

FROM origanal_table



Or is it more complicated than this?

Thanks

View 6 Replies View Related

SQL Express Database Table Data Insert Into Another Database

Apr 15, 2007

Hi,

I have two SQL Express database and I want to do two things. One is to transfer a table over to the other database. Two, move the files from one table in one database to another. Please let me know when you get a chance.

Thanks,

Kyle

View 8 Replies View Related

Compare And Update A Table From One Database To Another Table On Another Database

Jul 17, 2007

Hi everybody.. need help on this situation which i am to.

I have two databases named db1 and db2
both of which has two identical tables named tbl1 and tbl2

I need to compare tbl1 of db1 to the tbl2 of db2
if there is a record that is existing on tbl1 and not on the tbl2 then
i need to create a tblnew on db2
from that tblnew then i need to append all the data from tblnew to tbl2 of db2.

I don't know how to start with it because i'm used to appending data on two tables on the same database but not on a different one...

thanks
alex

View 3 Replies View Related

Error 823 While Running Queries On A Database

Jan 11, 2002

Hi, I have the following error logged in SQL Server's error log whenever I run a query on a particular database :

2002-01-04 22:54:02.46 spid11 Error: 823, Severity: 24, State: 1 2002-01-04 22:54:02.46 spid11 I/O error 1117(The request could not be performed because of an I/O device error.) detected during read of BUF pointer = 0x14eac480, page ptr = 0x73c94000, pageid = (0x1:0x158c89), dbid = 8, status = 0x801, file = d:mssql7datamydb.mdf..

2002-01-05 05:54:22.01 kernel SQL Server terminating because of system shutdown. 2002-01-05 05:54:22.14 kernel LogEvent: Failed to report the current event. Operating system error = 31(A device attached to the system is not functioning.).

and get this error in the Results pane of Query analyzer : Server: Msg 823, Level 24, State 1, Line 1 I/O error 1117(The request could not be performed because of an I/O device error.) detected during read of BUF pointer = 0x14ace4c0, page ptr = 0x35df6000, pageid = (0x1:0x44b73), dbid = 14, status = 0x801, file = d:MSSQL7DATAmydb.mdf.

Connection Broken

select @@version returns, Microsoft SQL Server 7.00 - 7.00.961 (Intel X86) Oct 24 2000 18:39:12 Copyright (c) 1988-1998 Microsoft Corporation Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 2)

Books Online Help on Error 823 indicates that it is a disk problem and suggests that DBCC checkdb needs to be run on the database. But, hardware diagnostics on the server do not report any disk problems and dbcc checkdb also returns no errors.

Help on the cause of error 823 would be greatly appreciated. Thank you, Praveena

View 1 Replies View Related

Why Is My Database Running Out Of Space Already!! (urgent)

Aug 28, 2001

I have a question on database size, specifically, what difference would I expect in the size of a db (the space actually used for data, not indexes) if I have one single data device vs. multiple data devices spanned across different physical drives. I have 2 customers that have identical database tables (all columns are integers), customer A has 27 million rows and customer B has 36 million rows. If I do an sp_spaceused on the table, customer A's data takes up 9.7 gig, whereas customer B only takes up 3.2 gig, even though it has 9 million more rows. Statistics have been updated, so I'm confident the sp_spaceused is accurate on both databases.

The only differences I can see between the 2 databases is that customer B has 5 separate data files (6 gig each) for the database which are part of the Primary filegroup. These files are all on the D: drive, which is a partition on a RAID 5 array. Customer A has a single large data file (24 gig), which is also on a RAID 5 array.

Any ideas?

View 4 Replies View Related

Updating Tables On A Running Database

Aug 7, 2006

First post here, hi to everyone.

Is it possible to update rows in a table while users are working on that table or do I have to throw them out? Thanks for the help!

View 1 Replies View Related

Sql Server Not Running Or Database Not Found

May 28, 2008

I have just installed sql server 2005 express, and ssmse..

have created the db, and can work in the management studio writing queries,etc.. all is fine..

when i try to open my proprietary exe i get the error of

"SQL SERVER NOT RUNNING OR DATABASE CANNOT BE FOUND" Now, I know the DB is there, and I know SQL is runnig.. what could it be?

any ideas and thanks in advance..

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved