Integrity With Multiple Commands

Aug 10, 2006

How can I make sure that a couple of commands are either all executed on the database or none of them. For example right now I have an insert, update and delete command. I'm calling each of them with a SqlCommand. So I am afraid that that one of them might be executed, then there's a bad connection and the other two are not. How can I prevent this so that only all commands or nothing is executed on the database?

View 2 Replies


ADVERTISEMENT

Multiple SQL Commands At Once

Jan 8, 2006

I'm running asp.net 2.0 and acessing MSSQL 2K.  I am trying to run a query in which I need to set up variables first.  I tried the following group of commands as shown, passing it to the  SqlDataReader object, but it failed.. does anyone know how i can pass multiple SQL commands?         MainQuery = "declare @MinGrades as Table(GradeID Bigint) " & _                    " INSERT @MinGrades SELECT MIN(CreditGrades.SplitID) AS Expr1" & _                       "  FROM          CreditGrades INNER JOIN" & _                        "    CreditGradeSplits ON CreditGradeSplits.CreditGradeSplitID = CreditGrades.SplitID " & _                        " WHERE      (CreditGrades.x0x30 = - 1 OR " & _                        "    CreditGrades.x0x30 >= 0) AND (CreditGrades.x1x30 = - 1 OR " & _                        "    CreditGrades.x1x30 >= 0) AND (CreditGrades.x2x30 = - 1 OR " & _                        "    CreditGrades.x2x30 >= 0) AND (CreditGrades.x3x30 = - 1 OR " & _                        "    CreditGrades.x3xNOD >= 0) " & _                        " GROUP BY CreditGradeSplits.CreditGradeGroupID" & _                    " Select * from @MinGrades "

View 2 Replies View Related

Integrity Across Multiple Database Types

Jul 8, 2005

Since most use SQL server, I thought I would post the question here.Is it possible, or is there a product or DBMS that enforces referential integrity across multiple databases and database types? Such as SQL Server, Oracle, etc...Thanks,Zath

View 2 Replies View Related

Problems With Multiple Commands Using Views

Jan 10, 2008

I am new to SQL, so I appologize if I am doing something wrong which is really basic.
I am receiving a "Incorrect syntax near ';' " when trying to create a view and then perform action based upon the results
Here is my basic code...the error is on the ; following the create view statement:
create view temp2 as select * from history where crc='XL' and processed<1;
insert into history2 (dialid, calldatetime, origcalldate, crc, revenue, projectid, agentid, phonenum)select  temp2.dialid, temp2.calldatetime, temp2.calldatetime, 'XL', 0, history2.projectid, temp2.agentid, temp2.phonenum from temp2, history2where temp2.dialid=history2.dialid and temp2.crc='XL' and temp2.processed<1 and temp2.projectid=110;
What am I doing wrong???
 Thanks for your help.

View 5 Replies View Related

Multiple Concurrent Sql Exec Commands?

Mar 12, 2008

I was wondering if it was possible to run 2 queries at the same time,IE rather than runningexec query1  exec query2 and having to wait for query1 to finish before query2 started, just have them run at the same time (they're not conflicting).I want to do this in TSQL, not by opening another query window in vs2005. 

View 2 Replies View Related

Execute Multiple Sql Commands With One Trip To The Database.

Jun 12, 2007

Ive got a List<sqlCommand> and I want to execute all the commands in it, but only using one trip to the database. I dont need any return values from any of these commands. Most of the commands are update/insert/delete. Sometimes after a insert command there may be a command "set @NEWID =identity_insert"  to facilitate the next insert to a related table, but thats the only other type of command to insert/update/delete.I am using microsofts enterprise data application block. I want to execute all the commands in the list with just one trip to the database. Would the following code achieve this : db = DatabaseFactory.CreateDatabase("wlmAdmin"); foreach (SqlCommand sc in saveCommands)            {                db.ExecuteNonQuery(sc);            }or would this make multiple trips to the database? Im not 100% on whats going on behind the db object. If I create the db Item in the constructor of my class using "db = DatabaseFactory.CreateDatabase("wlmAdmin");" would this mean that every instance of that class would maintain an open database connection throughout its scope/lifetime?Ive created the class to retrieve all data using a single stored procedure and then when saving, the class builds a List of SqlCommands which as Ive mentioned I want to execute in one trip, to make the number of trips to the database as small as possible. Because of this I don't need the db object maintain an open connection to the database all the time. However It doesnt seem to have any dispose methods so Im not clear on how it operates.In the case that the code above opens a connection for each command, how would I got about batch executing the queries in one trip?Thanks,C    

View 12 Replies View Related

Running Multiple Commands On Single Button Click

Feb 21, 2008

I have a form that contains data that some of which needs to be inserted into one table and the rest updated to another table. I want this to happen on a single button click. Is this possible?Here's what I have so far:            String id = parm_tb_tktid.Text;            String update = parm_tb_desc.Text;            String status = parm_cb_status.Text;                     SqlCommand cmd = new SqlCommand("Insert into History (tkt_id, hist_desc) values(@parm_tb_tktid, @parm_tb_desc)", HelpdeskConnectionString);            cmd.CommandType = CommandType.Text;            cmd.Parameters.AddWithValue("@parm_tb_tktid", id);            cmd.Parameters.AddWithValue("@parm_tb_desc", update);                        SqlCommand cmd1 = new SqlCommand("Update Ticket (tkt_status) values(@parm_cb_status) where tkt_id = @parm_tb_tktid)", HelpdeskConnectionString);            cmd1.CommandType = CommandType.Text;            cmd1.Parameters.AddWithValue("@parm_cb_status", status);            HelpdeskConnectionString.Open();            cmd.ExecuteNonQuery();            cmd1.ExecuteNonQuery();            HelpdeskConnectionString.Close();            parm_tb_tktid.Text = String.Empty;            parm_tb_desc.Text = String.Empty;            parm_cb_status.Text = String.Empty;I know it isn't right, but I can't find any info on why it's wrong and how to code it properly.  

View 9 Replies View Related

Multiple Tables, Inserts, Identity Columns And Database Integrity

Apr 30, 2008

Hi all,
I am writing a portion of an app that is of intensely high online eCommerce usage. I have a question about identity columns and locking or not.
What I am doing is, I have two tables (normalized), one is OrderDemographics(firstname,lastname,ccum,etc) the other is OrderItems. I have the primary key of OrderDemographics as a column called 'ID' (an Identity Integer that is incrementing). In the OrderItems table, the 'OrderID' column is a foreign key to the OrderDemographics Primary Key column 'ID'.
What I have previously done is to insert the demographics into OrderDemographics, then do a 'select top 1 ID from OrderDemographics order by ID DESC' to get that last ID, since you can't tell what it is until you add another row....
The problem is, there's up to 20,000 users/sessions at once and there is a possiblity that in the fraction of a second it takes to select back that ID integer and use it for the initial OrderItems row, some other user might have clicked 'order' a fraction of a second after the first user and created another row in OrderDemographics, thus incrementing the ID column and throwing all the items that Customer #1 orders into Customer #2's order....
How do I lock a SQL table or lock the Application in .NET to handle this problem and keep it from occurring?
Thanks, appreciate it.

View 2 Replies View Related

Referential Integrity - Linking Multiple Tables To Transaction Table

Mar 3, 2006

I have transaction table where the rows entered into the transactioncan come a result of changes that take place if four different tables.So the situation is as follows:Transaction Table-TranId-Calc AmountTable 1 (the amount is inserted into the transaction table)- Tb1Id- Tb1AmtTable 2 (an amount is calculated based on the percentage and insertedinto the transaction table)-Tbl2Id-Tb2PercentageTable 3 (the amount is inserted into the transaction table)-Tbl3Id-Tbl3AmutTable 4 (an amount is calculated based on the percentage and insertedinto the transaction table. )-Tbl2Id-Tb2PercentageHow do I create referential integrity between the Transaction table andthe rest of the tables. When I make changes to the values in Table 1 -4, I need to be able to reflect this in the Transaction table.Thanks.

View 6 Replies View Related

What Is Going On Here? SQL Commands And ODBC Commands Aren't Compatible

Oct 1, 2004

I'm building a simple webform, except Visual Studio and my service provider have combined to drive me nutty.

First, I MUST use an ODBC connection to my remote SQL Server do to some unknown configuartion problem. I've been playing with Visual Studio for only a month, so normally when something goes wrong I can go look in the mirror and find the culprit. This is different. I've got a totally functional web form with a SQL Connection, but when I try to change it to an ODBC Connection, I get the following error.

An OdbcParameter with ParameterName '@CertHolder' is not contained by this OdbcParameterCollection

My coding is fine because I stole it straight from the walkthrough and it works. But the specifications that Visual Studio provide are quite suspect. Please note the failure to include some key "@" signs.


#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.cmdUpdate = New System.Data.SqlClient.SqlCommand
Me.cmdGetAll = New System.Data.SqlClient.SqlCommand
Me.cmdSelect = New System.Data.SqlClient.SqlCommand
Me.OdbcConnection1 = New System.Data.Odbc.OdbcConnection
Me.OdbcGetAll = New System.Data.Odbc.OdbcCommand
Me.OdbcSelect = New System.Data.Odbc.OdbcCommand
Me.OdbcUpdate = New System.Data.Odbc.OdbcCommand
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "this works fine"
'
'cmdUpdate
'
Me.cmdUpdate.CommandText = "UPDATE InsuranceData SET Name = @Name, Address = @Address, Address2 = @Address2, " & _
"City = @City, State = @State, Zip = @Zip, CertHolder = WHERE (CertHolder = @Cert" & _
"Holder)"
Me.cmdUpdate.Connection = Me.SqlConnection1
Me.cmdUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.NVarChar, 50, "Name"))
Me.cmdUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 50, "Address"))
Me.cmdUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Address2", System.Data.SqlDbType.NVarChar, 50, "Address2"))
Me.cmdUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 50, "City"))
Me.cmdUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@State", System.Data.SqlDbType.NVarChar, 50, "State"))
Me.cmdUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Zip", System.Data.SqlDbType.NVarChar, 50, "Zip"))
Me.cmdUpdate.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CertHolder", System.Data.SqlDbType.NVarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "CertHolder", System.Data.DataRowVersion.Original, Nothing))
'
'cmdGetAll
'
Me.cmdGetAll.CommandText = "SELECT CertHolder, Name, Address, Address2, City, State, Zip FROM InsuranceData"
Me.cmdGetAll.Connection = Me.SqlConnection1
'
'cmdSelect
'
Me.cmdSelect.CommandText = "SELECT CertHolder, Name, Address, Address2, City, State, Zip FROM InsuranceData W" & _
"HERE (CertHolder = @CertHolder)"
Me.cmdSelect.Connection = Me.SqlConnection1
Me.cmdSelect.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CertHolder", System.Data.SqlDbType.NVarChar, 50, "CertHolder"))
'
'OdbcConnection1
'
Me.OdbcConnection1.ConnectionString = "This works fine"
'
'OdbcGetAll
'
Me.OdbcGetAll.CommandText = "SELECT CertHolder, Name, Address, Address2, City, State, Zip FROM InsuranceData"
Me.OdbcGetAll.Connection = Me.OdbcConnection1
'
'OdbcSelect
'
Me.OdbcSelect.CommandText = "SELECT CertHolder, Name, Address, Address2, City, State, Zip FROM InsuranceData W" & _
"HERE CertHolder = @CertHolder"
Me.OdbcSelect.Connection = Me.OdbcConnection1
Me.OdbcSelect.Parameters.Add(New System.Data.Odbc.OdbcParameter("CertHolder", System.Data.Odbc.OdbcType.NVarChar, 50, "CertHolder"))
'
'OdbcUpdate
'
Me.OdbcUpdate.CommandText = "UPDATE InsuranceData SET Name = @Name, Address = @Address, Address2 = @Address2, " & _
"City = @City, State = @State, Zip = @Zip WHERE CertHolder = @CertHolder"
Me.OdbcUpdate.Connection = Me.OdbcConnection1
Me.OdbcUpdate.Parameters.Add(New System.Data.Odbc.OdbcParameter("Name", System.Data.Odbc.OdbcType.NVarChar, 50, "Name"))
Me.OdbcUpdate.Parameters.Add(New System.Data.Odbc.OdbcParameter("Address", System.Data.Odbc.OdbcType.NVarChar, 50, "Address"))
Me.OdbcUpdate.Parameters.Add(New System.Data.Odbc.OdbcParameter("Address2", System.Data.Odbc.OdbcType.NVarChar, 50, "Address2"))
Me.OdbcUpdate.Parameters.Add(New System.Data.Odbc.OdbcParameter("City", System.Data.Odbc.OdbcType.NVarChar, 50, "City"))
Me.OdbcUpdate.Parameters.Add(New System.Data.Odbc.OdbcParameter("State", System.Data.Odbc.OdbcType.NVarChar, 50, "State"))
Me.OdbcUpdate.Parameters.Add(New System.Data.Odbc.OdbcParameter("Zip", System.Data.Odbc.OdbcType.NVarChar, 50, "Zip"))
Me.OdbcUpdate.Parameters.Add(New System.Data.Odbc.OdbcParameter("Original_CertHolder", System.Data.Odbc.OdbcType.NVarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "CertHolder", System.Data.DataRowVersion.Original, Nothing))

I NEVER EVER TYPED ORIGINAL_CERTHOLDER IN THE SQL PREPARATION

End Sub
Protected WithEvents btnSave As System.Web.UI.WebControls.Button
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents ddlCertHolder As System.Web.UI.WebControls.DropDownList
Protected WithEvents txtName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtAddress As System.Web.UI.WebControls.TextBox
Protected WithEvents ddlCH As System.Web.UI.WebControls.DropDownList
Protected WithEvents cmdUpdate As System.Data.SqlClient.SqlCommand
Protected WithEvents cmdGetAll As System.Data.SqlClient.SqlCommand
Protected WithEvents cmdSelect As System.Data.SqlClient.SqlCommand
Protected WithEvents txtAddress2 As System.Web.UI.WebControls.TextBox
Protected WithEvents txtCity As System.Web.UI.WebControls.TextBox
Protected WithEvents txtState As System.Web.UI.WebControls.TextBox
Protected WithEvents txtZip As System.Web.UI.WebControls.TextBox
Protected WithEvents OdbcConnection1 As System.Data.Odbc.OdbcConnection
Protected WithEvents OdbcGetAll As System.Data.Odbc.OdbcCommand
Protected WithEvents OdbcSelect As System.Data.Odbc.OdbcCommand
Protected WithEvents OdbcUpdate As System.Data.Odbc.OdbcCommand

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region


Comments? Suggestions, I am not positive about how to fix this.

View 2 Replies View Related

Multiple Database / Cross Database Referencial Integrity (foreign Keys)

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

Referential Integrity Constraints W/o Referential Integrity In The Db?

Mar 16, 2007

Using the new referential integrity constraints that will be made available, will it allow us to manually define the relationships between entities even if there is no true foreign key constraints setup in the database?

Lets say we deleted the FK_Orders_Customers in Northwind between orders and customers.

Or is this ability available now?

Thank for your time.

View 2 Replies View Related

Do I Need More Integrity On My DB?

Jul 5, 2004

I am not sure I need more integrity on my DB. My DDL are down below.
thanks

************************************************** *****

create table person(
personId int identity(1,1) primary key,
fName varchar(25) not null,
mI char(1) null,
lName varchar(25) not null
);


create table student(
studentId char(4) not null primary key,
personId int not null
);


alter table student
add constraint fk_person_student
foreign key (personId)
references person (personId)
;

create table instructor(
instructorId char(4) not null primary key,
instructorQual varchar(100) not null,
personId int not null
);

alter table instructor
add constraint fk_person_instructor
foreign key (personId)
references person (personId)
;

create table contract(
contractNum int identity(1,1) primary key,
contractDate smalldatetime not null,
tuition money not null,
studentId char(4) not null foreign key references student (studentId),
contactId int not null foreign key references contact (contactId)
);

create table contact(
contactId int not null primary key,
fName varchar(25) not null,
mI char(1) null,
lName varchar(25) not null,
street varchar(50) not null,
city varchar(25) not null,
state char(2) not null,
zip char(5) not null,
relationship varchar(25) not null,
phNum char(12) not null,
emailAdd varchar(50) null,
);

create table class(
classNum char(4) not null primary key,
className varchar(25) not null,
classDay char(3) not null,
classTime char(8) not null,
testNum char(5) not null
);


alter table class
add constraint fk_class_testnum
foreign key (testNum)
references test (testNum)
;

create table discount(
discountNum char(3) primary key,
discountDesc varchar(100) not null,
discountPer decimal(3,2) not null
);

create table test(
testNum char(5) primary key,
testName varchar(50) not null,
testDate smalldatetime not null,
testFee money not null,
);

create table studentClass(
studentId char(4) not null,
classNum char(4) not null,
pass char(1) not null
);

alter table studentClass
add constraint pk_studentclass primary key clustered (studentId, classNum)
;


alter table studentClass
add constraint fk_studentclass_studenttid
foreign key (studentId)
references student(studentId)
;

alter table studentClass
add constraint fk_studentclass_classnum
foreign key (classNum)
references class(classNum)
;

create table contractDiscount(
contractNum int not null,
discountNum char(3) not null
);

alter table contractDiscount
add constraint pk_contractdiscount primary key clustered (contractNum, discountNum)
;

alter table contractDiscount
add constraint fk_contractdiscount_contractnum
foreign key (contractNum)
references contract(contractNum)
;

alter table contractDiscount
add constraint fk_contractdiscount_discountnum
foreign key (discountNum)
references discount(discountNum)
;

create table instructorClass(
instructorId char(4) not null,
classNum char(4) not null,
);


alter table instructorClass
add constraint pk_instructorclass primary key clustered (instructorId, classNum)
;

alter table instructorClass
add constraint fk_instructorclass_instructorid
foreign key (instructorId)
references instructor(instructorId)
;

alter table instructorClass
add constraint fk_instructorclass_classnum
foreign key (classnum)
references class(classnum)
;

View 2 Replies View Related

MDF Integrity

Jun 8, 2007

Hi all,



Is there any way to check the integrity of .Mdf file before attaching it to a database means to check whether its valid (or) not.



Thanks.



//Najeed

View 2 Replies View Related

Commands

Jan 7, 2008

Hi All,

I have these two commands that I execute at the end of my stored procedure. I get an email every time I execute this stored procedure whether the select statement returns a value or not. But I only want to get an email if select statement returns an Error value. How can I accomplish this?

set @cmd = 'osql -S server -U user -P psswd -q "set nocount on; select distinct(rtrim(col1)) from ##table where datediff(dd,col2,getdate()) = 1 and (col1 like ''%Error: %'')" -h-1 -w 1025 -o J:MyFolderErrorLogMsg.txt'

EXEC master.dbo.xp_cmdshell @cmd, no_output

SET @email = 'mailsend -f someone@mymail.com -d -smtp -t someone@mymail.com -sub "Error Log Errors" -m J:MyFolderErrorLogMsg.txt'

EXEC master.dbo.xp_cmdshell @email, no_output


Thanks.

View 2 Replies View Related

Commands

Jan 7, 2008

Hi All,

I have these two commands that I execute at the end of my stored procedure. I get an email every time I execute this stored procedure whether the select statement returns a value or not. But I only want to get an email if select statement returns an Error value. How can I accomplish this?

set @cmd = 'osql -S server -U user -P psswd -q "set nocount on; select distinct(rtrim(col1)) from ##table where datediff(dd,col2,getdate()) = 1 and (col1 like ''%Error: %'')" -h-1 -w 1025 -o J:MyFolderErrorLogMsg.txt'

EXEC master.dbo.xp_cmdshell @cmd, no_output

SET @email = 'mailsend -f someone@mymail.com -d -smtp -t someone@mymail.com -sub "Error Log Errors" -m J:MyFolderErrorLogMsg.txt'

EXEC master.dbo.xp_cmdshell @email, no_output


Thanks.

View 2 Replies View Related

Sql Commands

Jan 13, 2004

How can I get all SQL commands in SqlServer? How can I trace this commands?

Thansk

View 1 Replies View Related

SET Commands

Feb 8, 2006

Hello,

I finally got access to Northwind/pubs.

I would like to know when and why do we use the following set commands. The SQL Server BOL does not say why and when to use these commands.

Thanks in advance!!!
sqlnovice123



Option Default Setting
Set nocount OFF
Set rowcount 0
Set ansi_nulls ON
Set quoted_identifier ON

View 3 Replies View Related

SQL Server And Integrity

Jan 23, 2004

Where should tests for data integrity be done, a few examples:

Inserting data but the underlying data has changed?

Adding data, say an order item row, but since going to that screen the order (and as a result all its order items as well) have been deleted?

It's just I'm starting to see even the simplest of stored procedures as being quite complicated. What puzzles me is a I see lots of INSERT stored procedures with none of this checking in, or returning error codes?

So are they badly done or am I missing somethign?

View 3 Replies View Related

Referential Integrity ?

Aug 11, 2001

Question:
What is used to enforce referential integrity ?
Answer: Triggers; Foriegn Keys.
what is Foreign Keys ?

View 1 Replies View Related

Referential Integrity

Oct 17, 2001

How do you enforce referential integrity in SQL between tables?

Thanks.

View 1 Replies View Related

DTS Integrity Violation

Jun 12, 2000

I having a problem importing a text file into an existing table using the DTS import wizard. The problem I am having is, I am getting an error message stating: Integrity violation: attempt to insert null data or data which violates constraints. The column the error is referenced to is an identity field and I am not trying to insert any data into the field. I have the allow insert identity box checked in the transformation section. Does anyone know about how to solve this problem.
Thanks
James

View 1 Replies View Related

Integrity Checks

Aug 21, 2002

On weekends I have Integrity Checks scheduled to run. Many of these fail for individual databases because users do not log off and the databases cannot be switched to single user mode.

I have checked Books-on-line and have not yet stumbled onto a TSQL command that breaks the connections.

Is there a TSQL command to do this? If not, how can these connections be broken?

View 2 Replies View Related

I Have Referential Integrity. Now What

Feb 26, 2008

I used to work with little databases and throw everything into a table with no relation, and modify them all individually. Now I've learned about referential integrity, makes things a lot easier.

My question is, now what? Say I have a Customers table and an Orders table (to keep it simple). If custID is the primary key in customers, foreign key in orders, then if I want to insert into Orders, I need the custID. So those kinds of things I need to keep stored in a session state and insert them like that, correct?

View 1 Replies View Related

Integrity Job Error

Sep 6, 2004

Hi folks,

I created a job to check the integrity of my databases every week using SQL Server Maintenance Plan Wizard.
The job is failing every time...
For tb_basico database it works fine, but with the other one (tb_cep) it doesn't work...

Does someone have an idea to solve this problem?

The message is:

[1] Database tb_basico: Check Data and Index Linkage...

** Execution Time: 0 hrs, 0 mins, 11 secs **

[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 5070: [Microsoft][ODBC SQL Server Driver][SQL Server]Database state cannot be changed while other users are using the database 'tb_cep'
[Microsoft][ODBC SQL Server Driver][SQL Server]ALTER DATABASE statement failed.
[Microsoft][ODBC SQL Server Driver][SQL Server]sp_dboption command failed.
[2] Database tb_cep: Check Data and Index Linkage...
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 7919: [Microsoft][ODBC SQL Server Driver][SQL Server]Repair statement not processed. Database needs to be in single user mode.

The following errors were found:

[Microsoft][ODBC SQL Server Driver][SQL Server]Repair statement not processed. Database needs to be in single user mode.
** Execution Time: 0 hrs, 0 mins, 1 secs **

View 1 Replies View Related

Referential Integrity

Oct 26, 2004

Hi guys,

Is there a way of finding the foreign keys for a table and therefore determine weather any referential integrity rules would be broken if a record was deleted?

For example. You have an author you want to delete, but that author has books. You call a procedure to delete the author. The stored procedure checks the foriegn keys, checks the tables and determines what is in them and if any tables have records that would be "orphaned" you return an error reporting what tables have the "would be orphaned" data in them.

It need to be fairly generic int he manner that it checks the foreign keys and the sub table data.

This is on behalf of a guy at work so "requirements" may change. ;)

Anyone got some ideas??

Cheers,
Shaun

View 5 Replies View Related

Referential Integrity

Feb 1, 2008

hi guys,
i was asked to drop some tables...but before dropping i was asked to check for referential integrity..
so where and how can i check this referential integrity????

View 2 Replies View Related

Referential Integrity

Dec 23, 2005

Hihow to set the referential integrity between 2 tables using enterprisemanager (microsoft SQL SERVER).. i tried and the tab doesn't allow meto choose. pls.help.thankssree--chavasreedharMessage posted via http://www.exforsys.com for all your training needs.

View 1 Replies View Related

Check Integrity

Jul 20, 2005

Hi,What methods can we use to check the integrity problems? Some records in mydatabase are having Foreign Keys but the database doesn't have any relatedrecords with required Primary Keys. I need to scan the whole database anddelete (maybe with backup, maybe not) all wrong records.Who can I do that? Is it need to write my own application to do that or wehave some standard way to fix these problems? I'm not a databaseadministrator and don't know these ways (yet). Can somebody help me withadvice?Thanks.Dmitri Shvetsov

View 4 Replies View Related

2 SQL Commands In One Action

Nov 29, 2007

Hi guys,I wanna ask bout the problem with my web application. I'm doing a select a statement from table 1 and and with the query results i got, i need it to store the result on table 2. How will i do this?  I need your tips and suggestions.

View 1 Replies View Related

SQL Commands Disappearing!?!?!?!

Nov 7, 2001

I am experiencing a situation where I issue a lengthy SQL command to MS SQL Server 7.0 through MTS and it "disappears" - no errors or recordsets are returned. The command is "SELECT * FROM CUSTOMERS WHERE LASTNAME LIKE 'SMITH%'". When I issue this command from SQL Query Analyzer it takes 27 seconds to return 87 rows. When I issue this exact same command through MTS it does not return at all.

I've used the SQL Profiler to analyze the requests. It shows the commands from MTS starting but they never stop (or at least the profiler never reports them as stopping). The same commands coming from Query Analyzer are reported as starting and stopping without fail.

Here's a twist: I can issue less demanding commands (ie, one that doesn't take so long to process) through MTS and they come back fine. For example, when a user logs into my application, I use an SQL statement to verify the user name and password and status the user as logged in. This is routed through MTS and it comes back fine in less than a second. Same application, same PC, same MTS and SQL server, same SQL database. The only difference is that the CUSTOMERS table has over 800,000 records and the USERS table has only 5 records.

PLEASE HELP!

View 1 Replies View Related

Using The DBCC Commands

Jul 26, 2004

Hi,

I am very new to sql server and I have been reading up on the dbcc commands. For instance, DBCC SHOWCONTIG where do I execute this command? I went into the cmd prompt and opened osql and typed:
1> DBCC SHOWCONTIG
2> GO

This gives me the information for what I assume is the master database. But, how do I use this command under the other databases?

Also, I have been trying to learn how to determine when to do index maintenance by using the index tuning wizard. But, I don't know what a workload is. Can someone point me in the right direction or give me some information about this topic.

Thanks,
Laura

View 5 Replies View Related

Normalizing Using Sql Commands

Aug 28, 2006

Hi

Please can someone point me in the direction, i built a very badly designed database consisting of only one huge table when i first started databases, since learning about normalization i have designed and set up a new database which consists of many more tables instead of just the one. My question is where do i start in transfering the data from the old single tabled database to my new multi-tabled database?

I have MS SQL server 2005 managment studio if that helps, but want to transfer around 200,000 rows of data into the new database. Both new and old databases are on the same server.

thanks in advance

View 11 Replies View Related







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