DataBase Referencial Intergrity Check
Jul 30, 2007
I allow the user to delete record1 from SQL Table1 and record2 from Table2. The only problem is, record1 and record2 refers to record3 in Table3 and I can´t allow the user to delete record1 if the is a field in record3 with record1 ref. code. I can´t set FK between them cuz there is more than one reference to the same field.
Can someone point the best solution for my problem?
View 3 Replies
ADVERTISEMENT
Feb 12, 2008
Using SQL Server Express 2005, I have two databases. AppDB - The main application database.GeoDB - A somewhat static ZIP code / states / other geographic stuff databaseI need to have some foreign key columns in tables in AppDB reference columns in the GeoDB database tables. Eventually other application database besides AppDB will be doing the same thing in our infrastructure. After googling and reading for days, here is what I
think I know:You cannot create foreign keys that reference tables in another database in SQL Server.You
cannot create foreign keys that reference columns in a view, and you definitely cannot make an index on a view that has base tables in another database.You can create a trigger that references tables in another database, but this can be flaky? (nested/recursive trigger problem).SQLServer
2005 supports multiple schemas within the same database. Maybe I should logically separate my databases this way? Seems like it would be a tough solution to manage since I already have some databases live in production that will eventually use this 'static' GeoDB. Also, seems like it
wouldn't be as portable as keeping the GeoDB info in its own database,
but maybe I'm being too software engineer-ish here - afraid of low
cohesion, high coupling.I will greatly appreciate any advice I can get, or any more options I am missing. Thanks,Adam Nofsingerucnmedia.com
View 2 Replies
View Related
Feb 12, 2008
Using SQL Server 2005, I have two databases.
AppDB - The main application database.
GeoDB - A somewhat static ZIP code / states / other geographic stuff database
I need to have some foreign key columns in tables in AppDB reference columns in the GeoDB database tables. Eventually other application database besides AppDB will be doing the same thing in our infrastructure. After googling and reading for days, here is what I think I know:
You cannot create foreign keys that reference tables in another database in SQL Server.
You cannot create foreign keys that reference columns in a view, and you definitely cannot make an index on a view that has base tables in another database.
You can create a trigger that references tables in another database, but this can be flaky? (nested/recursive trigger problem).
SQLServer2005 supports multiple schemas within the same database. Maybe I should logically separate my databases this way? Seems like it would be a tough solution to manage since I already have some databases live in production that will eventually use this 'static' GeoDB. Also, seems like itwouldn't be as portable as keeping the GeoDB info in its own database, but maybe I'm being too software engineer-ish here - afraid of low cohesion, high coupling.
I will greatly appreciate any advice I can get, any links to articles, or any more options I am missing.
Thanks,Adam Nofsinger
ucnmedia.com
View 9 Replies
View Related
Mar 24, 2008
Hi,
Let's say you have these 3 tables
--------------------------------------------------------------
use tempdb
go
create table TableMain (
RowID int primary key identity(1, 1)
, ItemTypeID tinyint NOT NULL
, Details varchar(200) NOT NULL
)
go
create table TableDetails (
DetailRowID int primary key identity(1, 1)
, RowID int NOT NULL
, ItemTypeID tinyint NOT NULL
, Details varchar(200) NOT NULL
)
go
create table ItemTypes (
ItemTypeID tinyint primary key identity(1, 1)
, Details varchar(50) NOT NULL
)
go
create unique nonclustered index IX_TableMain__ItemTypeID__RowID on TableMain (ItemTypeID, RowID)
go
alter table TableDetails
add constraint FK_TableDetails_TableMain__RowID__ItemTypeID foreign key (ItemTypeID, RowID) references TableMain(ItemTypeID, RowID);
go
alter table TableMain
add constraint FK_TableMain_ItemTypes__ItemTypeID foreign key (ItemTypeID) references ItemTypes(ItemTypeID);
go
/*
drop table TableDetails
drop table TableMain
drop table ItemTypes
*/
--------------------------------------------------------------
As you can see TableDetails references TableMain by ItemTypeID and RowID. TableMain also has a foreign key on ItemTypeID.
In this example although there is no references between TableDetails and ItemTypes on ItemTypeID field, referential integrity is still maintain because of the foreign key on TableMain (ItemTypeID, RowID)
So here is my question. Although referential integrity is maintain with this structure, would you guys still create a foreign key on TableDetails (ItemTypeID), i.e.:
alter table TableDetails
add constraint FK_TableDetails_ItemTypes__ItemTypeID foreign key (ItemTypeID) references ItemTypes(ItemTypeID);
go
There might not be any right or wrong, it might be a personal preference sort of thing. To me it seems performance wise it's better to not create this extra contraints since it doesn't add any additional integrity, on the other hand when looking at a DB schema this extra constraint might help understanding what's going on. Also perhaps it helps SQL Server in picking the right execution plan but that I am not sure.
Perhaps the solution is to create the constraint with a NOCHECK on it... is it?
View 14 Replies
View Related
Oct 9, 2007
yes,I have an error, like 'The database file may be corrupted. Run the repair utility to check the database file. [ Database name = SDMMC Storage Cardwinpos_2005WINPOS2005.sdf ]' .I develope a program for Pocket Pcs and this program's database sometimes corrupt.what can i do?please help me
View 4 Replies
View Related
Sep 21, 2000
Hi !
How do I check when my database was last used ? I have two old databases that I think is not in use, but I want to check to make sure before I delete them or take them "offline".
TIA MAttias
View 1 Replies
View Related
May 6, 2008
Hello,
I am performing a number of queries on a database and inputting the results of those queries into a target database.
These queries are performed inside a number of data flows.
I would like to do two things:
1) Check that the target database can be seen before entering the dataflows. If not, wait X minutes and then retry.
2) If, for some reason, SSIS loses connectivity to the target database during the process, I would like to, is possible, roll back any current transactions and start over.
Unfortunately my knowledge of SSIS is very limited, so if anyone could lend a hand I would appreciate it.
Best regards,
Simon
View 1 Replies
View Related
Nov 19, 2004
Hello, Everyone:
There are some databases in a SQL Server. How to check,
1. User database numbers
2. Backup plan
3. Configuration
4. User database size
5. Nightly process
Thanks a lot
ZYT
View 1 Replies
View Related
Jun 18, 2007
I was wondering if it was possible to check what server database you are currently connected to, using T-SQL, when executing commands in Query Analyzer. Even though you choose the server and database when connection, sometimes by habit you may connect to the wrong server & DB, and execute an .SQL file. Is it possible to put a line of T-SQL at the beginning that performs this pseudo-code, as a safety feature:-- While in Query Analyzer with a certain .SQL file open:If current server <> 'TheCorrectServer' and current DB <> 'TheCorrectDB' then cancel this .SQL file execution.
View 3 Replies
View Related
Oct 31, 2007
Hi everyone,
I am looking for a way to check to see if a database is a snapshot or not. You can for example check different properties of a database by running the following:
SELECT DATABASEPROPERTYEX('databasename','Recovery')
SELECT DATABASEPROPERTYEX('databasename','IsInStandBy')
SELECT DATABASEPROPERTYEX('databasename','Status')
So I am trying to see if there is a way to check for a snapshot
Thanks,
Reghardt
View 2 Replies
View Related
Dec 9, 2006
Hi,
I'm wondering is there a command that I can use to check if a certain value exists in the database? Something that returns true or false perhaps?
SELECT * FROM Customers WHERE ID ='1'
Ok so that's simple, but how can I return a true or false if '1' is a value that exists in the db?
thanks.
View 5 Replies
View Related
Feb 14, 2007
I want to query my databases to find out if Auto Shrink is set. I know the status column in sysdatabases holds this value as a bit setting but I don't know how can I check this value using a query.
Canada DBA
View 1 Replies
View Related
Jan 22, 2008
im trying to set up maintenance plan for the check database integrity...
In sql 2000 you get a nice little log in SQL Logs
DBCC CHECKDB (WSS_Search_db3) executed by xxx found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 1 seconds.
But in SQL 2005
Im not getting a nice log of this but getting it against some system database and not the database i selected
Date1/22/2008 5:19:43 PM
LogSQL Server (Current - 1/22/2008 5:19:00 PM)
Sourcespid84
Message
DBCC CHECKDB (mssqlsystemresource) WITH no_infomsgs executed by XXX found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 1 seconds.
Anyone got this to work?
Trying to get the same message i got for SQL 2000 or at least so i can confirm it ran.
View 13 Replies
View Related
Jul 24, 2005
Hi everybody,Is there way to check what were the last modifys to specified database??I mean the last insertion, deletion ........... .. and in which tables.Thanks for advance--"Imagination is more important than knolwege" (Albert Einshtein)Message posted via SQLMonster.comhttp://www.sqlmonster.com/Uwe/Forum...eneral/200507/1
View 6 Replies
View Related
Aug 15, 2005
helloWhat query shoul I send to SQL serwer ( in transact SQL language ) to checkdoes some database exist on serwer ? It similar to problem "does some tableexist in database" - resolve to it is query:use db_silnikIF EXISTS (SELECT * FROM prad)PRINT 'table exist'but what is the query to check does some database exist on serwer ?best regardsAdam
View 2 Replies
View Related
Jul 20, 2005
Hello,I am trying to check the integrity of SQL database. The 'problem' withSQL server is that it's fixing the DB automatically after restore so Ineed a way to do it offline, much like using eseutil on Exchangedatabases.Thanks in advance.
View 1 Replies
View Related
May 23, 2008
I have SQL Server 2005 Standard Edition.
How to calculate database transactions per second?
Thank you,
Gish
View 3 Replies
View Related
Oct 18, 2007
Hi,
I have no way to test this. If let's say the database has logical integrity errors, will it throw back an error to the Check database integrity object such that, the error arrow (the red line which is the error handler stuff) will be triggered for notification purposes?
cherriesh
View 1 Replies
View Related
Sep 26, 2007
How can I check if the database is currently being backed up?
Seems like that should be a property, but it's not an attribute of the DATABASEPROPERTY function.
Thanks
View 7 Replies
View Related
Mar 6, 2008
what does check database integrity in maintenance plan do.
i heard that the transactional log growth in sql server should be fixed to maximum available disk space and must be monitore the threshold through maintenance plan.how can it be done. please advice me through maintance plan instead of
shrinking the log as it is unnecessary IO to the disk.
How often is the check database integrity scheduled. is it daily or weekly.
View 1 Replies
View Related
Sep 21, 2007
Hi
I am working at a site that has no dedicated DBA, and our Sql Server 2000 environment has recently been playing up. There are several databases on the Production server that should be inactive (for applications no longer used).
What is the best way for me to see if there has been any recent activity on these databases (short of taking them offline and waiting for screams). Please keep in mind that I am a Sql Server novice.
Cheers
View 5 Replies
View Related
Aug 2, 2006
I have a database hosted that doesnt passes the integrity test. Here is the error it gives :
Executing the query "USE [db_cs]
failed with the following error: "Could not locate entry in sysdatabases for database 'db_cs'. No entry found with that name. Make sure that the name is entered correctly.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Any idea whats wrong and how I can let the integrity test pass for this db.
Thanks,
Rubal Jain
View 4 Replies
View Related
Dec 8, 2006
I was able to get this code to work but now I get a SQL error if you try to submit the same information twice. How can I add a message saying that the "email" already exists in database without the SQL error? protected void Button1_Click1(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=TECATE;Initial Catalog=subscribe_mainSQL; User Id=maindb Password=123456; Integrated Security=SSPI"); SqlCommand cmd = new SqlCommand("INSERT INTO [main] (, [userid], [fname], [lname], [degree]) VALUES (@email, @userid, @fname, @lname, @degree)", conn); conn.Open(); cmd.Parameters.AddWithValue("@email", email.Text); cmd.Parameters.AddWithValue("@userid", uscid.Text); cmd.Parameters.AddWithValue("@fname", fname.Text); cmd.Parameters.AddWithValue("@lname", lname.Text); cmd.Parameters.AddWithValue("@degree", degree.SelectedItem.Value); int i = cmd.ExecuteNonQuery(); conn.Dispose(); }
View 5 Replies
View Related
Mar 18, 2008
I need to check a login against a database of users. Any help would be appreciated. Thank you!!
This is what I have so far:
Dim Myconnection As SqlConnection Dim MyCommand As SqlCommand
Dim mySQL As StringDim username As String = TextBox1.TextDim password As String = TextBox2.Text
Myconnection = New SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True")
mySQL = "SELECT username, password FROM tblUser WHERE username =" & username & " And password = " & password & ";"MyCommand = New SqlCommand(mySQL, Myconnection)
MyCommand.Connection.Open()
MyCommand.ExecuteNonQuery()
MyCommand.Connection.Close()
View 11 Replies
View Related
Jun 3, 2008
i want to check the new username check availability from database in a same page ,i did in normal coding
i need ajax or java scripts method because this page look and feel is not good
thanks,
@mbi
View 6 Replies
View Related
Mar 25, 2005
Hi im having problems as im new to ASP.NET C#
i have created a button to add details into a SQL database but i want to check the details before i insert the new values from the textboxes
can anyone help....... this is what i have to insert into the database........i just want some help to compare the user name eg... if user name exists a message will appear telling the user to change a different user name
Thanks
private void Button1_Click(object sender, System.EventArgs e)
{
string connectionString = "server='(local)'; trusted_connection=true; database='tester'";
//System.Data.IDbConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
System.Data.IDbConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
conn.Open();
string commandString = "INSERT INTO Users (UserName, Password) " + "Values(@UserName, @Password)";
//SqlCommand dbCommand = new SqlCommand (commandString, dbconn);
System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
//System.Data.SqlClient.SqlCommand myCmd = new System.Data.SqlClient.SqlCommand(queryString, conn);
dbCommand.CommandText = commandString;
dbCommand.Connection = conn;
SqlParameter unParam = new SqlParameter ("@UserName", SqlDbType.NVarChar, 60);
unParam.Value = txtUser.Text;
dbCommand.Parameters.Add(unParam);
SqlParameter paParam = new SqlParameter ("@Password", SqlDbType.NVarChar, 60);
paParam.Value = txtPassword.Text;
dbCommand.Parameters.Add(paParam);
dbCommand.ExecuteNonQuery();
conn.Close();
Response.Redirect ("WebForm1.aspx");
}
View 1 Replies
View Related
Jul 29, 2004
I am trying to manage a sql server.
In this sql server, I have about 200 databases.
Is there any way/suggestions to check to see if some of the database has not been accessed/updated for the last month or longer?
I am trying to develop a system to remove the database that's no longer needed.
Thank you.
View 8 Replies
View Related
Oct 28, 2004
Is there anyway to check for cross-database dependencies?
For example:
I have a stored proc in the Pubs database that contains a query that references a table in the Northwind database (as well as reference a table in the Pubs database.) I'm having no problems finding the depencency for the Pubs table. I can't seem to find the dependency for the Northwind table.
Any help would be appreciated.
Thanks in advance.
Scott
View 1 Replies
View Related
Dec 2, 2005
Hello, everyone:
How to check the function of a Database Maintenance Plan? For example, I want to check how how many databases are backed up in this plan. Thanks
ZYT
View 1 Replies
View Related
May 9, 2008
hello everybody,
i have one problem, I want to check the database table modified or not for every five minutes , how can check? please help me
Senthil
View 2 Replies
View Related
Feb 16, 2007
I have setup a full maintenance plan on SQL2005. When I run the job, I don't see any error but by loooking at the Log file viewer it appears that Check Database Integrity step failed because :
Alter failed for Server 'LUMONT001'.
Moreover, when I run DBCC CHECKDB from the console I have no error message. Any clue?
Thanks, Paul
View 6 Replies
View Related
May 8, 2007
Hello everyone! Looking for some insight here on database backups that fail.
We have many SQL servers that we maintain by storing Job/Maintenence Plan history on a central server, which then emails out daily reports to let us know what backed up last night and what didn't
This was easy to do in SQL 2000, not so much in SQL 2005. I have put together a query that gathers the info I need for the successes:
SELECT DISTINCT '00000000-0000-0000-0000-000000000001' AS Plan_ID, mpld.line1 as "Plan Name", bud.database_name as "Database", mpld.server_name, 'Backup Database' as Activity, mpld.succeeded, bs.backup_finish_date, DATEDIFF (MS,bs.backup_start_date,bs.backup_finish_date) as Duration, bs.backup_start_date, mpld.error_number, mpld.error_messageFROM msdb.dbo.sysmaintplan_logdetail mpld
INNER JOIN msdb.dbo.backupset bs
on (select convert(char(12),mpld.start_time,109))=(select convert(char(12),bs.backup_start_date,109))-- on bs.database_name=bud.database_name
inner join
msdb.dbo.bu_dbs bud
on bs.database_name = bud.database_name
WHERE mpld.succeeded = 1 and mpld.line2 like 'Backup%' and bs.type='d'
and bs.backup_start_date > ( SELECT CONVERT(char(12), (GETDATE()-1), 109) )
ORDER BY bud.database_name DESC
But I am having trouble using a query to determine the databases the FAILED during backup. MSDB.BackupSet and MSDB.SYSMaintPlan_LogDetail really have nothing,because often times, even if a step in a Maint. Plan fails, the plan finishes reporting success.
Does anyone know of a good way to gather info about failed database backups?
Thank you!
Mario
View 6 Replies
View Related
May 9, 2007
I want to run Profiler Traces, Perfmon Checks and whatever else to see what hits the server the hardest in order to work out where I can make performance improvements. We don't have any massive problems other than more timeouts than I would expect from web users no-and-then when they do pretty simple free-text searches. I just want to see if I can lighten the load on the server in general.
Where does a DBA get the most ROI? I don't want to drift into the realm of diminishing returns where I am making changes that have no noticeable impact.
What should I start measuring first and how do you measure it? (E.g. if I should monitor disk writes in Profiler, how many writes are too high for a statement? 100? If so, is one 100-write statement per hour OK but one 100-write statement per second is not OK?)
If there is already an article for this, my apologies. I'd be grateful if you can point me to it.
Is http://www.sql-server-performance.com/ a sufficient one-stop-shop for this question? If so, have you found some articles there to be more useful than others?
View 5 Replies
View Related