Showing posts with label sqlserver. Show all posts
Showing posts with label sqlserver. Show all posts

Thursday, March 29, 2012

Comparing two SQLServer databases

Hi, does anybody know a nice tool to automatically compare and show
only the structural differences between two databases, this is, the
differences in the columns of a table, constrains, data type, etc.

Thanks

J.A.I use this one (there are a number of other, simipar products):

http://www.red-gate.com/SQL_Compare.htm

Simon|||For excellent compare functionality (including data) plus the ability
to link your source control system into the whole process I recommend
looking at DB Ghost (www.dbghost.com). It also guarantees any delta
script produced will work (due to a unique algorithm), something no
other tool can promise.

Comparing to Resultsets

I have a situation where I have two tables, one in Access and one in SQL
Server. There are several hundred thousand rows and the tables should
contain the exact same number of rows. They may not though and the count
could be off by one row or a hundred rows. I need to be able to identify
which rows are not in both resultsets so i can update the second table with
the missing rows.
My problem is that I have built a VB app that SELECT * FROM table and then I
query the second table using the current results from table 1... Select *
From table where companyName = 'value from table1'
This works but it has taken 5 hours so far and isn't even half way done.
The IDs in both table can be (and are) different in both tables so i don't
really have a solid way to compare records on a record by record basis. To
make matters worse Access and SQL server appear to have different sort
engines so when I sort the records by a column, the fields are not in
exactly the same order.
What options do i have to compare these two tables and identify the rows
that are different'
Thanks,
RonYou'd have to post DDL to help us help you.
You don't really need a single common column to compare result sets, they
must, however, contain comparable data.
ML
http://milambda.blogspot.com/

Thursday, March 8, 2012

Compare data difference between two database in SQLServer 2005

Hi,
I have too databases, their structures are completely same, with minor data
difference, I want to generate a patch SQL statements, not complete backup
by comparing them, thus I can synchronzie the out-dated database with that
script. Does SQLServer2005 provide thus functionality? Or there is other
tool I can use. Thank you
zlf
You can do it yourself if you link the servers, but it may take a good
amount of work. Easier might be to use a third party tool. Red-Gate's SQL
Data Compare is probably the most obvious choice...
http://www.red-gate.com/products/SQL_Data_Compare/index.htm

Adam Machanic
SQL Server MVP
Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
"zlf" <zlfcn@.hotmail.com> wrote in message
news:uFrkmWPtHHA.1184@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I have too databases, their structures are completely same, with minor
> data difference, I want to generate a patch SQL statements, not complete
> backup by comparing them, thus I can synchronzie the out-dated database
> with that script. Does SQLServer2005 provide thus functionality? Or there
> is other tool I can use. Thank you
> zlf
>
|||On Jun 22, 1:57 pm, "Adam Machanic" <amacha...@.IHATESPAMgmail.com>
wrote:
> You can do it yourself if you link the servers, but it may take a good
> amount of work. Easier might be to use a third party tool. Red-Gate's SQL
> DataCompareis probably the most obvious choice...
> http://www.red-gate.com/products/SQL_Data_Compare/index.htm
> --
> Adam Machanic
> SQL Server MVP
> Author, "Expert SQL Server 2005 Development"http://www.apress.com/book/bookDisplay.html?bID=10220
> "zlf" <z...@.hotmail.com> wrote in message
> news:uFrkmWPtHHA.1184@.TK2MSFTNGP04.phx.gbl...
>
>
> - Show quoted text -
Hi Zif,
another great choice is xSQL Softwares xSQL Data Compare which you can
get from http://www.xsqlsoftware.com - you don't just get 2 weeks of
free trial but you also have it free forever for smaller size
databases (up to a certain number of objects) as well as free with no
limitations for SQL Server Express databases.
Furthermore, we have a well document api (xSQL SDK) that allows you to
integrate the functionality in your own application if you want.
Hope this helps.
Thanks,
JC
xSQL Software
http://www.xsqlsoftware.com
|||It works. Thank both of you
"Adam Machanic" <amachanic@.IHATESPAMgmail.com>
?:%23jF$gbPtHHA.2164@.TK2MSFTNGP02.phx.gbl...
> You can do it yourself if you link the servers, but it may take a good
> amount of work. Easier might be to use a third party tool. Red-Gate's
> SQL Data Compare is probably the most obvious choice...
> http://www.red-gate.com/products/SQL_Data_Compare/index.htm
>
> --
> Adam Machanic
> SQL Server MVP
> Author, "Expert SQL Server 2005 Development"
> http://www.apress.com/book/bookDisplay.html?bID=10220
>
> "zlf" <zlfcn@.hotmail.com> wrote in message
> news:uFrkmWPtHHA.1184@.TK2MSFTNGP04.phx.gbl...
>

Compare data difference between two database in SQLServer 2005

Hi,
I have too databases, their structures are completely same, with minor data
difference, I want to generate a patch SQL statements, not complete backup
by comparing them, thus I can synchronzie the out-dated database with that
script. Does SQLServer2005 provide thus functionality? Or there is other
tool I can use. Thank you
zlfYou can do it yourself if you link the servers, but it may take a good
amount of work. Easier might be to use a third party tool. Red-Gate's SQL
Data Compare is probably the most obvious choice...
http://www.red-gate.com/products/SQ...mpare/index.htm
Adam Machanic
SQL Server MVP
Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
"zlf" <zlfcn@.hotmail.com> wrote in message
news:uFrkmWPtHHA.1184@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I have too databases, their structures are completely same, with minor
> data difference, I want to generate a patch SQL statements, not complete
> backup by comparing them, thus I can synchronzie the out-dated database
> with that script. Does SQLServer2005 provide thus functionality? Or there
> is other tool I can use. Thank you
> zlf
>|||On Jun 22, 1:57 pm, "Adam Machanic" <amacha...@.IHATESPAMgmail.com>
wrote:
> You can do it yourself if you link the servers, but it may take a good
> amount of work. Easier might be to use a third party tool. Red-Gate's SQ
L
> DataCompareis probably the most obvious choice...
> http://www.red-gate.com/products/SQ...mpare/index.htm
> --
> Adam Machanic
> SQL Server MVP
> Author, "Expert SQL Server 2005 Development"http://www.apress.com/book/boo
kDisplay.html?bID=10220
> "zlf" <z...@.hotmail.com> wrote in message
> news:uFrkmWPtHHA.1184@.TK2MSFTNGP04.phx.gbl...
>
>
>
> - Show quoted text -
Hi Zif,
another great choice is xSQL Softwares xSQL Data Compare which you can
get from http://www.xsqlsoftware.com - you don't just get 2 weeks of
free trial but you also have it free forever for smaller size
databases (up to a certain number of objects) as well as free with no
limitations for SQL Server Express databases.
Furthermore, we have a well document api (xSQL SDK) that allows you to
integrate the functionality in your own application if you want.
Hope this helps.
Thanks,
JC
xSQL Software
http://www.xsqlsoftware.com|||It works. Thank both of you
"Adam Machanic" <amachanic@.IHATESPAMgmail.com>
':%23jF$gbPtHHA.2164@.TK2MSFTNGP02.phx.gbl...
> You can do it yourself if you link the servers, but it may take a good
> amount of work. Easier might be to use a third party tool. Red-Gate's
> SQL Data Compare is probably the most obvious choice...
> http://www.red-gate.com/products/SQ...mpare/index.htm
>
> --
> Adam Machanic
> SQL Server MVP
> Author, "Expert SQL Server 2005 Development"
> http://www.apress.com/book/bookDisplay.html?bID=10220
>
> "zlf" <zlfcn@.hotmail.com> wrote in message
> news:uFrkmWPtHHA.1184@.TK2MSFTNGP04.phx.gbl...
>

Compare data difference between two database in SQLServer 2005

Hi,
I have too databases, their structures are completely same, with minor data
difference, I want to generate a patch SQL statements, not complete backup
by comparing them, thus I can synchronzie the out-dated database with that
script. Does SQLServer2005 provide thus functionality? Or there is other
tool I can use. Thank you
zlfYou can do it yourself if you link the servers, but it may take a good
amount of work. Easier might be to use a third party tool. Red-Gate's SQL
Data Compare is probably the most obvious choice...
http://www.red-gate.com/products/SQL_Data_Compare/index.htm
Adam Machanic
SQL Server MVP
Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
"zlf" <zlfcn@.hotmail.com> wrote in message
news:uFrkmWPtHHA.1184@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I have too databases, their structures are completely same, with minor
> data difference, I want to generate a patch SQL statements, not complete
> backup by comparing them, thus I can synchronzie the out-dated database
> with that script. Does SQLServer2005 provide thus functionality? Or there
> is other tool I can use. Thank you
> zlf
>|||On Jun 22, 1:57 pm, "Adam Machanic" <amacha...@.IHATESPAMgmail.com>
wrote:
> You can do it yourself if you link the servers, but it may take a good
> amount of work. Easier might be to use a third party tool. Red-Gate's SQL
> DataCompareis probably the most obvious choice...
> http://www.red-gate.com/products/SQL_Data_Compare/index.htm
> --
> Adam Machanic
> SQL Server MVP
> Author, "Expert SQL Server 2005 Development"http://www.apress.com/book/bookDisplay.html?bID=10220
> "zlf" <z...@.hotmail.com> wrote in message
> news:uFrkmWPtHHA.1184@.TK2MSFTNGP04.phx.gbl...
>
> > Hi,
> > I have toodatabases, their structures are completely same, with minor
> > data difference, I want to generate a patch SQL statements, not complete
> > backup by comparing them, thus I can synchronzie the out-dated database
> > with that script. Does SQLServer2005 provide thus functionality? Or there
> > is other tool I can use. Thank you
> > zlf- Hide quoted text -
> - Show quoted text -
Hi Zif,
another great choice is xSQL Softwares xSQL Data Compare which you can
get from http://www.xsqlsoftware.com - you don't just get 2 weeks of
free trial but you also have it free forever for smaller size
databases (up to a certain number of objects) as well as free with no
limitations for SQL Server Express databases.
Furthermore, we have a well document api (xSQL SDK) that allows you to
integrate the functionality in your own application if you want.
Hope this helps.
Thanks,
JC
xSQL Software
http://www.xsqlsoftware.com|||It works. Thank both of you:)
"Adam Machanic" <amachanic@.IHATESPAMgmail.com>
':%23jF$gbPtHHA.2164@.TK2MSFTNGP02.phx.gbl...
> You can do it yourself if you link the servers, but it may take a good
> amount of work. Easier might be to use a third party tool. Red-Gate's
> SQL Data Compare is probably the most obvious choice...
> http://www.red-gate.com/products/SQL_Data_Compare/index.htm
>
> --
> Adam Machanic
> SQL Server MVP
> Author, "Expert SQL Server 2005 Development"
> http://www.apress.com/book/bookDisplay.html?bID=10220
>
> "zlf" <zlfcn@.hotmail.com> wrote in message
> news:uFrkmWPtHHA.1184@.TK2MSFTNGP04.phx.gbl...
>> Hi,
>> I have too databases, their structures are completely same, with minor
>> data difference, I want to generate a patch SQL statements, not complete
>> backup by comparing them, thus I can synchronzie the out-dated database
>> with that script. Does SQLServer2005 provide thus functionality? Or there
>> is other tool I can use. Thank you
>> zlf
>

Friday, February 24, 2012

Communication link failure

I have a VB6 application running on an SQLServer database. At first, the co
nnection to the database succeeds, a number of sql subsequent statements (bo
th select and update statements) succeed and then from some point on (after
about 80 sql statements), I
get the following error message : -2147467259 : [Microsoft][ODBD SQL
Server Driver]Communication link failure.
This happens on a number of P.C.'s, however not on all of them.
Thanks,
John DesmetThis sounds like it might share a few common features with a posting I made
here on March 5, under the heading:
Re: Occasional "Timeout expired" message - on SP that should take 1 second
What do you think? This syndrome sometimes also generates the
"Communication Link Failure" message.
- ITFred|||Thank you for your reply. At the end of the day (literally), we found out t
hat the Symantic Client Firewall is causing the problem. When it is turned
off, the problem no longer occurs. Now, we have to modify a number of firew
all settings.
Thanks,
John Desmet

Commons DBCP pooling problem

Hello,
I am using Commons DBCP to pool my sqlserver database connections.
Sometimes there is just an hourglass cursor when trying to access my
application - looks like there are no free connections available.
Am I doing anything wrong in my code? Should I be closing the
datasource, for example? Please see below.
Class for retrieving datasource:
package mypackage.name.here
import javax.sql.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import org.apache.commons.dbcp.*;
import org.apache.commons.pool.*;
import org.apache.commons.pool.impl.*;
public class DatabaseUtil {
static PoolingDataSource dataSource = null;
public static final String DB_PROPERTIES =
"myextension.properties";
// Returns a DataSource that implements connection pooling
public static synchronized DataSource getDataSource(String
configDir) throws Exception {
if (dataSource == null){
Properties p = new Properties();
try{
File cfg = new File(configDir, DB_PROPERTIES);
p.load(new FileInputStream(cfg));
} catch (IOException e) {
System.out.println(e);
}
String type = p.getProperty("dbType");
String url = p.getProperty("url");
String ip = p.getProperty("dbIP");
String name = p.getProperty("dbName");
String port = p.getProperty("dbPort");
String sid = p.getProperty("dbSid");
String fullUrl = null;
if (type.trim().equals("ms")){
// MSSQL
fullUrl = url+ip+"/"+name;
} else {
// ORACLE
fullUrl = url+ip+":"+port+":"+sid;
}
BasicDataSource ds = new BasicDataSource();
ds.setUrl(fullUrl);
ds.setDriverClassName(p.getProperty("driver"));
ds.setUsername(p.getProperty("usr"));
ds.setPassword(EncDoc.decode(p.getProperty("pass") ));
ds.setMaxActive(100);
// Create a PoolableDataSource
ObjectPool connectionPool = new GenericObjectPool(null);
ConnectionFactory connectionFactory = new
DataSourceConnectionFactory(ds);
PoolableObjectFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory, connectionPool, null,
null, false, true);
dataSource = new PoolingDataSource(connectionPool);
}
return dataSource;
}
}
Sample JSP page:
...
DataSource dataSource = DatabaseUtil.getDataSource(configDir);
Connection myConnect = null;
Statement myStatement = null;
ResultSet myResults = null;
try{
myConnect = dataSource.getConnection();
myStatement = myConnect.createStatement();
...
myQuery = "select count (*) as 'total' from admin where courseID =
'"+courseID+"'";
myStatement.executeQuery(myQuery);
myResults = myStatement.getResultSet();
while (myResults.next()) count = myResults.getInt("total");
...
}catch (SQLException e) {
out.println("SQL Error: <br><br>"+e);
} finally {
try { myResults.close(); } catch(Exception e) {}
try { myStatement.close(); } catch(Exception e) { }
try { myConnect.close(); } catch(Exception e) { }
}
Thanks all.
downlode@.gmail.com wrote:

> Hello,
> I am using Commons DBCP to pool my sqlserver database connections.
> Sometimes there is just an hourglass cursor when trying to access my
> application - looks like there are no free connections available.
> Am I doing anything wrong in my code? Should I be closing the
> datasource, for example? Please see below.
Hi. The JSP code is excellent. Very safe and sure to close
the connection. I am not knowledgeable about that pool
implementation. I would suggest getting a full thread dump
of the JVM during that hang, and see what is waiting on what.
Can you find out how many JSPs are running concurrently
when such a hang is happening? If the pool implementation
ever calls DriverManager calls, it may be the cause. DriverManager
calls are all class-synchronized, and lots of JDBC drivers
make those calls under the covers, so any one long-running
DriverManager call (getConnection()) can halt all other JDBC
in the whole JVM...
Joe Weinstein at BEA Systems

> Class for retrieving datasource:
>
> package mypackage.name.here
> import javax.sql.*;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.util.*;
> import org.apache.commons.dbcp.*;
> import org.apache.commons.pool.*;
> import org.apache.commons.pool.impl.*;
> public class DatabaseUtil {
> static PoolingDataSource dataSource = null;
> public static final String DB_PROPERTIES =
> "myextension.properties";
>
> // Returns a DataSource that implements connection pooling
> public static synchronized DataSource getDataSource(String
> configDir) throws Exception {
> if (dataSource == null){
> Properties p = new Properties();
> try{
> File cfg = new File(configDir, DB_PROPERTIES);
> p.load(new FileInputStream(cfg));
> } catch (IOException e) {
> System.out.println(e);
> }
> String type = p.getProperty("dbType");
> String url = p.getProperty("url");
> String ip = p.getProperty("dbIP");
> String name = p.getProperty("dbName");
> String port = p.getProperty("dbPort");
> String sid = p.getProperty("dbSid");
> String fullUrl = null;
> if (type.trim().equals("ms")){
> // MSSQL
> fullUrl = url+ip+"/"+name;
> } else {
> // ORACLE
> fullUrl = url+ip+":"+port+":"+sid;
> }
> BasicDataSource ds = new BasicDataSource();
> ds.setUrl(fullUrl);
> ds.setDriverClassName(p.getProperty("driver"));
> ds.setUsername(p.getProperty("usr"));
> ds.setPassword(EncDoc.decode(p.getProperty("pass") ));
> ds.setMaxActive(100);
> // Create a PoolableDataSource
> ObjectPool connectionPool = new GenericObjectPool(null);
> ConnectionFactory connectionFactory = new
> DataSourceConnectionFactory(ds);
> PoolableObjectFactory poolableConnectionFactory = new
> PoolableConnectionFactory(connectionFactory, connectionPool, null,
> null, false, true);
> dataSource = new PoolingDataSource(connectionPool);
> }
> return dataSource;
> }
> }
>
> Sample JSP page:
> ...
> DataSource dataSource = DatabaseUtil.getDataSource(configDir);
> Connection myConnect = null;
> Statement myStatement = null;
> ResultSet myResults = null;
> try{
> myConnect = dataSource.getConnection();
> myStatement = myConnect.createStatement();
> ...
> myQuery = "select count (*) as 'total' from admin where courseID =
> '"+courseID+"'";
> myStatement.executeQuery(myQuery);
> myResults = myStatement.getResultSet();
> while (myResults.next()) count = myResults.getInt("total");
> ...
> }catch (SQLException e) {
> out.println("SQL Error: <br><br>"+e);
> } finally {
> try { myResults.close(); } catch(Exception e) {}
> try { myStatement.close(); } catch(Exception e) { }
> try { myConnect.close(); } catch(Exception e) { }
> }
>
> Thanks all.
>
|||Joe Weinstein wrote:

>
> downlode@.gmail.com wrote:
>
> Hi. The JSP code is excellent. Very safe and sure to close
> the connection.
Actually, the one extra thing I might try, is to make the
connection and it's subobjects method-level objects. If the
JSP is typically one instantiated class, any multiple threads
executing it could overwrite the connection reference and
leak connections instead of having them all closed.
Joe

> I am not knowledgeable about that pool
> implementation. I would suggest getting a full thread dump
> of the JVM during that hang, and see what is waiting on what.
> Can you find out how many JSPs are running concurrently
> when such a hang is happening? If the pool implementation
> ever calls DriverManager calls, it may be the cause. DriverManager
> calls are all class-synchronized, and lots of JDBC drivers
> make those calls under the covers, so any one long-running
> DriverManager call (getConnection()) can halt all other JDBC
> in the whole JVM...
> Joe Weinstein at BEA Systems
>
|||Hi,
I'm not sure how I would go about making the connection a method-level
object in this scenario. Would I create a new class with a
getConnection() type method for creating and returning the connection?
Thanks,
Mike

> Actually, the one extra thing I might try, is to make the
> connection and it's subobjects method-level objects. If the
> JSP is typically one instantiated class, any multiple threads
> executing it could overwrite the connection reference and
> leak connections instead of having them all closed.
> Joe
|||downlode@.gmail.com wrote:
[vbcol=seagreen]
> Hi,
> I'm not sure how I would go about making the connection a method-level
> object in this scenario. Would I create a new class with a
> getConnection() type method for creating and returning the connection?
> Thanks,
> Mike
>
Hi. You could do that, or you could just make sure the scope of
the connection variable was within a block in the code, eg:
DataSource dataSource = DatabaseUtil.getDataSource(configDir);
try {
Connection myConnect = null; // ensure these have per-thread scope
Statement myStatement = null;
ResultSet myResults = null;
try{
myConnect = dataSource.getConnection();
myStatement = myConnect.createStatement();
...
myQuery = "select count (*) as 'total' from admin where courseID =
'"+courseID+"'";
myStatement.executeQuery(myQuery);
myResults = myStatement.getResultSet();
while (myResults.next()) count = myResults.getInt("total");
...
}catch (SQLException e) {
out.println("SQL Error: <br><br>"+e);
} finally {
try { myResults.close(); } catch(Exception e) {}
try { myStatement.close(); } catch(Exception e) { }
try { myConnect.close(); } catch(Exception e) { }
}
}
finally {}
|||OK, got you.
Thanks again.
Mike

common UPDATE syntax for SqlServer and Oracle

The UPDATE table FROM syntax is not supported by Oracle.

I am looking for a syntax that is understood by both Oracle and SqlServer.

Example:

Table1:

id name city city_id
1 john newyork null
2 peter london null
3 hans newyork null

Table2:

id city
23 london
24 paris
25 newyork

UPDATE table1
SET city_id = table2.id
FROM table1, table2
WHERE table1.city = Table2.city

If possible I do not want to have two different statements for Oracle and
SqlServer

Please do not tell me that these tables are not normalized, it's just an
example!

Thanks for any hints.

Jan van VeldhuizenThe ANSI Standard syntax supported by both products is

UPDATE Table1
SET city_id =
(SELECT T2.id
FROM Table2 AS T2
WHERE T2.city = Table1.city) ;

Depending on requirements you may want to include a WHERE EXISTS (equivalent
to the proprietary INNER JOIN syntax)

UPDATE Table1
SET city_id =
(SELECT T2.id
FROM Table2 AS T2
WHERE T2.city = Table1.city)
WHERE EXISTS
(SELECT *
FROM Table2 AS T2
WHERE T2.city = Table1.city) ;

--
David Portas
SQL Server MVP
--|||Like most new ideas, the hard part of understanding what the relational
model is comes in un-learning what you know about file systems. As
Artemus Ward (William Graham Sumner, 1840-1910) put it, "It ain't so
much the things we don't know that get us into trouble. It's the things
we know that just ain't so."

If you already have a background in data processing with traditional
file systems, the first things to un-learn are:

(0) Databases are not file sets.
(1) Tables are not files.
(2) Rows are not records.
(3) Columns are not fields.

Modern data processing began with punch cards, or Hollerith cards used
by the Bureau of the Census. Their original size was that of a United
States Dollar bill. This was set by their inventor, Herman Hollerith,
because he could get furniture to store the cards from the United States
Treasury Department, just across the street. Likewise, physical
constraints limited each card to 80 columns of holes in which to record
a symbol.

The influence of the punch card lingered on long after the invention of
magnetic tapes and disk for data storage. This is why early video
display terminals were 80 columns across. Even today, files which were
migrated from cards to magnetic tape files or disk storage still use 80
column records.

But the influence was not just on the physical side of data processing.
The methods for handling data from the prior media were imitated in the
new media.

Data processing first consisted of sorting and merging decks of punch
cards (later, sequential magnetic tape files) in a series of distinct
steps. The result of each step feed into the next step in the process.

Relational databases do not work that way. Each user connects to the
entire database all at once, not to one file at time in a sequence of
steps. The users might not all have the same database access rights
once they are connected, however. Magnetic tapes could not be shared
among users at the same time, but shared data is the point of a
database.

Tables versus Files

A file is closely related to its physical storage media. A table may or
may not be a physical file. DB2 from IBM uses one file per table,
while Sybase puts several entire databases inside one file. A table is
a <i>set<i> of rows of the same kind of thing. A set has no ordering
and it makes no sense to ask for the first or last row.

A deck of punch cards is sequential, and so are magnetic tape files.
Therefore, a <i>physical<i> file of ordered sequential records also
became the <i>mental<i> model for data processing and it is still hard
to shake. Anytime you look at data, it is in some physical ordering.

The various access methods for disk storage system came later, but even
these access methods could not shake the mental model.

Another conceptual difference is that a file is usually data that deals
with a whole business process. A file has to have enough data in
itself to support applications for that business process. Files tend to
be "mixed" data which can be described by the name of the business
process, such as "The Payroll file" or something like that.

Tables can be either entities or relationships within a business
process. This means that the data which was held in one file is often
put into several tables. Tables tend to be "pure" data which can be
described by single words. The payroll would now have separate tables
for timecards, employees, projects and so forth.

Tables as Entities

An entity is physical or conceptual "thing" which has meaning be itself.
A person, a sale or a product would be an example. In a relational
database, an entity is defined by its attributes, which are shown as
values in columns in rows in a table.

To remind users that tables are sets of entities, I like to use plural
or collective nouns that describe the function of the entities within
the system for the names of tables. Thus "Employee" is a bad name
because it is singular; "Employees" is a better name because it is
plural; "Personnel" is best because it is collective and does not summon
up a mental picture of individual persons.

If you have tables with exactly the same structure, then they are sets
of the same kind of elements. But you should have only one set for each
kind of data element! Files, on the other hand, were PHYSICALLY
separate units of storage which coudl be alike -- each tape or disk file
represents a step in the PROCEDURE , such as moving from raw data, to
edited data, and finally to archived data. In SQL, this should be a
status flag in a table.

Tables as Relationships

A relationship is shown in a table by columns which reference one or
more entity tables. Without the entities, the relationship has no
meaning, but the relationship can have attributes of its own. For
example, a show business contract might have an agent, an employer and
a talent. The method of payment is an attribute of the contract itself,
and not of any of the three parties.

Rows versus Records

Rows are not records. A record is defined in the application program
which reads it; a row is defined in the database schema and not by a
program at all. The name of the field in the READ or INPUT statements
of the application; a row is named in the database schema.

All empty files look alike; they are a directory entry in the operating
system with a name and a length of zero bytes of storage. Empty tables
still have columns, constraints, security privileges and other
structures, even tho they have no rows.

This is in keeping with the set theoretical model, in which the empty
set is a perfectly good set. The difference between SQL's set model and
standard mathematical set theory is that set theory has only one empty
set, but in SQL each table has a different structure, so they cannot be
used in places where non-empty versions of themselves could not be used.

Another characteristic of rows in a table is that they are all alike in
structure and they are all the "same kind of thing" in the model. In a
file system, records can vary in size, datatypes and structure by having
flags in the data stream that tell the program reading the data how to
interpret it. The most common examples are Pascal's variant record, C's
struct syntax and Cobol's OCCURS clause.

The OCCURS keyword in Cobol and the Variant records in Pascal have a
number which tells the program how many time a record structure is to be
repeated in the current record.

Unions in 'C' are not variant records, but variant mappings for the same
physical memory. For example:

union x {int ival; char j[4];} myStuff;

defines myStuff to be either an integer (which are 4 bytes on most
modern C compilers, but this code is non-portable) or an array of 4
bytes, depending on whether you say myStuff.ival or myStuff.j[0];

But even more than that, files often contained records which were
summaries of subsets of the other records -- so called control break
reports. There is no requirement that the records in a file be related
in any way -- they are literally a stream of binary data whose meaning
is assigned by the program reading them.

Columns versus Fields

A field within a record is defined by the application program that reads
it. A column in a row in a table is defined by the database schema.
The datatypes in a column are always scalar.

The order of the application program variables in the READ or INPUT
statements is important because the values are read into the program
variables in that order. In SQL, columns are referenced only by their
names. Yes, there are shorthands like the SELECT * clause and INSERT
INTO <table name> statements which expand into a list of column names in
the physical order in which the column names appear within their table
declaration, but these are shorthands which resolve to named lists.

The use of NULLs in SQL is also unique to the language. Fields do not
support a missing data marker as part of the field, record or file
itself. Nor do fields have constraints which can be added to them in
the record, like the DEFAULT and CHECK() clauses in SQL.

Relationships among tables within a database

Files are pretty passive creatures and will take whatever an application
program throws at them without much objection. Files are also
independent of each other simply because they are connected to one
application program at a time and therefore have no idea what other
files looks like.

A database actively seeks to maintain the correctness of all its data.
The methods used are triggers, constraints and declarative referential
integrity.

Declarative referential integrity (DRI) says, in effect, that data in
one table has a particular relationship with data in a second (possibly
the same) table. It is also possible to have the database change
itself via referential actions associated with the DRI.

For example, a business rule might be that we do not sell products which
are not in inventory. This rule would be enforce by a REFERENCES clause
on the Orders table which references the Inventory table and a
referential action of ON DELETE CASCADE

Triggers are a more general way of doing much the same thing as DRI. A
trigger is a block of procedural code which is executed before, after or
instead of an INSERT INTO or UPDATE statement. You can do anything with
a trigger that you can do with DRI and more.

However, there are problems with TRIGGERs. While there is a standard
syntax for them in the SQL-92 standard, most vendors have not
implemented it. What they have is very proprietary syntax instead.
Secondly, a trigger cannot pass information to the optimizer like DRI.
In the example in this section, I know that for every product number in
the Orders table, I have that same product number in the Inventory
table. The optimizer can use that information in setting up EXISTS()
predicates and JOINs in the queries. There is no reasonable way to
parse procedural trigger code to determine this relationship.

The CREATE ASSERTION statement in SQL-92 will allow the database to
enforce conditions on the entire database as a whole. An ASSERTION is
not like a CHECK() clause, but the difference is subtle. A CHECK()
clause is executed when there are rows in the table to which it is
attached. If the table is empty then all CHECK() clauses are
effectively TRUE. Thus, if we wanted to be sure that the Inventory
table is never empty, and we wrote:

CREATE TABLE Inventory
( ...
CONSTRAINT inventory_not_empty
CHECK ((SELECT COUNT(*) FROM Inventory) > 0), ... );

it would not work. However, we could write:

CREATE ASSERTION Inventory_not_empty
CHECK ((SELECT COUNT(*) FROM Inventory) > 0);

and we would get the desired results. The assertion is checked at the
schema level and not at the table level.

--CELKO--
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Thanks. I'm going to test that.

That syntax will work with one column to be updated.
What if I have to columns?

I think the oracle sql will support something like:
UPDATE Table1
SET (city_id, another_column) =
(SELECT T2.id, other_column FROM etctera...

But that no standard SqlServer syntax as far as I know.

"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:qoednbGWLZwC-TvcRVn-1A@.giganews.com...
> The ANSI Standard syntax supported by both products is
> UPDATE Table1
> SET city_id =
> (SELECT T2.id
> FROM Table2 AS T2
> WHERE T2.city = Table1.city) ;
> Depending on requirements you may want to include a WHERE EXISTS
> (equivalent to the proprietary INNER JOIN syntax)
> UPDATE Table1
> SET city_id =
> (SELECT T2.id
> FROM Table2 AS T2
> WHERE T2.city = Table1.city)
> WHERE EXISTS
> (SELECT *
> FROM Table2 AS T2
> WHERE T2.city = Table1.city) ;
> --
> David Portas
> SQL Server MVP
> --|||On Fri, 26 Nov 2004 11:01:39 +0100, Jan van Veldhuizen wrote:

>Thanks. I'm going to test that.
>That syntax will work with one column to be updated.
>What if I have to columns?
>I think the oracle sql will support something like:
>UPDATE Table1
> SET (city_id, another_column) =
> (SELECT T2.id, other_column FROM etctera...
>But that no standard SqlServer syntax as far as I know.

Hi Jan,

That's right. Using ANSI-standard SQL, the only way to update multiple
columns with values from another table is to repeat the subquery:

UPDATE Table1
SET city_id = (SELECT T2.id FROM etcetera...)
, another_column = (SELECT other_column FROM etcetera...)
WHERE ...

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hugo Kornelis wrote:
> On Fri, 26 Nov 2004 11:01:39 +0100, Jan van Veldhuizen wrote:
>
>>Thanks. I'm going to test that.
>>
>>That syntax will work with one column to be updated.
>>What if I have to columns?
>>
>>I think the oracle sql will support something like:
>>UPDATE Table1
>> SET (city_id, another_column) =
>> (SELECT T2.id, other_column FROM etctera...
>>
>>But that no standard SqlServer syntax as far as I know.
>
> Hi Jan,
> That's right. Using ANSI-standard SQL, the only way to update multiple
> columns with values from another table is to repeat the subquery:
> UPDATE Table1
> SET city_id = (SELECT T2.id FROM etcetera...)
> , another_column = (SELECT other_column FROM etcetera...)
> WHERE ...
> Best, Hugo
I believe the ANSI standard allows:
UPDATE Table1
SET (city_id, another_column) = (SELECT T2.id, other column FROM etc
WHERE ...)
WHERE EXISTS(...)

Cheers
Serge|||On Fri, 26 Nov 2004 07:31:59 -0500, Serge Rielau wrote:

>I believe the ANSI standard allows:
>UPDATE Table1
> SET (city_id, another_column) = (SELECT T2.id, other column FROM etc
>WHERE ...)
>WHERE EXISTS(...)

Hi Serge,

Umm, yes. I believe you're right. Unfortunately, that part of ANSI sql is
not available in SQL Server 2000 (don't know about Oracle, thoug), so it
won't help Jan.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||"Jan van Veldhuizen" <jan@.van-veldhuizen.nl> wrote in message news:<41a6fed9$0$78279$e4fe514c@.news.xs4all.nl>...
> Thanks. I'm going to test that.
> That syntax will work with one column to be updated.
> What if I have to columns?
> I think the oracle sql will support something like:
> UPDATE Table1
> SET (city_id, another_column) =
> (SELECT T2.id, other_column FROM etctera...
> But that no standard SqlServer syntax as far as I know.

Jan,

The multi-column UPDATE you describe above is actually included in the
SQL-2003 standard. (The non-Core feauture T641 - "Multiple column
assignment")

Regards,
Jarl|||Hugo Kornelis wrote:
> On Fri, 26 Nov 2004 07:31:59 -0500, Serge Rielau wrote:
>
>>I believe the ANSI standard allows:
>>UPDATE Table1
>> SET (city_id, another_column) = (SELECT T2.id, other column FROM etc
>>WHERE ...)
>>WHERE EXISTS(...)
>
> Hi Serge,
> Umm, yes. I believe you're right. Unfortunately, that part of ANSI sql is
> not available in SQL Server 2000 (don't know about Oracle, thoug), so it
> won't help Jan.
> Best, Hugo

It does exist in Oracle. Too bad about SQL Server though.
--
Daniel A. Morgan
University of Washington
damorgan@.x.washington.edu
(replace 'x' with 'u' to respond)

Common SQL errors

Xref: TK2MSFTNGP08.phx.gbl microsoft.public.sqlserver.programming:548103
Hello,
Can someone recommend a good book that explains the various common design
and query errors that can happen in SQL? Things like fan and chasm traps,
circular references, etc.
Many Thanks.SQL PROGRAMMING STYLE|||Is the whole book in caps, or just the title :)
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1124756158.408802.294350@.g44g2000cwa.googlegroups.com...
> SQL PROGRAMMING STYLE
>|||Here is a small set
http://toponewithties.blogspot.com/...es.blogspot.com
"Bill George" <WovenPath@.frontiernet.net> wrote in message
news:101FE72.4F78%WovenPath@.frontiernet.net...
> Hello,
> Can someone recommend a good book that explains the various common design
> and query errors that can happen in SQL? Things like fan and chasm traps,
> circular references, etc.
> Many Thanks.
>

Common Objects in Management Studio?

I recently started using the SQL Server Management Studio that comes with SQL
Server 2005 in place of SQL Query Analyzer that comes with SQL Server 2000.
In SQL Query Analyzer's Object Explorer there is a set of Common Objects
under all of the DataBase Objects. These were very handy for me when I would
forget the syntax for a certain Transact-SQL function. It is more convenient
than looking it up in Books Online.
I can't seem to find the equivalent of the Common Objects in SQL Server
Management Studio. Anyone know where they are?
Thanks,
- Chase
Chase (Chase@.discussions.microsoft.com) writes:
> In SQL Query Analyzer's Object Explorer there is a set of Common Objects
> under all of the DataBase Objects. These were very handy for me when I
> would forget the syntax for a certain Transact-SQL function. It is more
> convenient than looking it up in Books Online.
> I can't seem to find the equivalent of the Common Objects in SQL Server
> Management Studio. Anyone know where they are?
Welcome to Management Studio! You will find that there is a lot of
functionality in Query Analyzer and Enterprise Manager that was not
brought over to Mgmt Studio. No, please don't ask me why! All I can suggest
is go to http://lab.msdn.microsoft.com/ProductFeedback/ and post a
suggestion for it to come back.
(I will have to admit that this is a feature of Query Analyzer that I
was not aware of myself.)
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
|||A lot of that functionality can be replaced by templates that you can add
yourself. Open Template Explorer and right-click on the top node, select New
> Template.
Also, if you are just looking for a quick syntax help, you should check
Dynamic Help window. To open it click Help > Dynamic Help menu option. Once
the window opens, you can dock it somewhere in the Management Studio shell.
As you type in an editor, you will see links to help topics that relate to
what you just typed, including syntax help for T-SQL.
Hope that helps.
Regards,
Maciek Sarnowicz
SQL Server SDE
This posting is provided "AS IS" with no warranties, and confers no rights
"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns9741F0113F282Yazorman@.127.0.0.1...
> Chase (Chase@.discussions.microsoft.com) writes:
> Welcome to Management Studio! You will find that there is a lot of
> functionality in Query Analyzer and Enterprise Manager that was not
> brought over to Mgmt Studio. No, please don't ask me why! All I can
> suggest
> is go to http://lab.msdn.microsoft.com/ProductFeedback/ and post a
> suggestion for it to come back.
> (I will have to admit that this is a feature of Query Analyzer that I
> was not aware of myself.)
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pro...ads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodinf...ons/books.mspx

Sunday, February 19, 2012

Commit, rollback...

Hello!
I have problmes wtih my litle(single prosessor raid-5, standard sql) sql
server. We have table with over 20 000 000 records and now A'am cleaning
it. I tryed to delete most of it with simple detele statement. (DELETE FROM
[Stat].[dbo].[Stat] WHERE id < 28449928) It tryes to tun it, but it stopts
becouse transactiong log becoms full... We do not have much of fre space for
transaction logs...
How do I disable rollback feature one time on my deletequery?
Or how do I disable it from hole database? Databese get's every day 200 000
new records and it has many transactions over the day. But data that is
strored is not critical so we would need more speed to our queries instead
of failssafe.
And another question. How do I speed up database table that has over 4 000
000 records? Mainly all queries are like queries or quesries against dates.
T
To minimize the log you can switch to the simple recovery mode.
For the delete operation, you could delete data in steps, perhaps using
rowvcount setting. That way, you can loop deletion of lets say 10000 records
until you dont have anything left to delete.
MC
"TLehtinen" <timo@.raa.to> wrote in message
news:43d4d775$0$7478$39db0f71@.news.song.fi...
> Hello!
> I have problmes wtih my litle(single prosessor raid-5, standard sql) sql
> server. We have table with over 20 000 000 records and now A'am cleaning
> it. I tryed to delete most of it with simple detele statement. (DELETE
> FROM [Stat].[dbo].[Stat] WHERE id < 28449928) It tryes to tun it, but it
> stopts becouse transactiong log becoms full... We do not have much of fre
> space for transaction logs...
> How do I disable rollback feature one time on my deletequery?
> Or how do I disable it from hole database? Databese get's every day 200
> 000 new records and it has many transactions over the day. But data that
> is strored is not critical so we would need more speed to our queries
> instead of failssafe.
> And another question. How do I speed up database table that has over 4 000
> 000 records? Mainly all queries are like queries or quesries against
> dates.
>
> T
>
|||"TLehtinen" <timo@.raa.to> wrote in message
news:43d4d775$0$7478$39db0f71@.news.song.fi...
> Hello!
> I have problmes wtih my litle(single prosessor raid-5, standard sql) sql
> server. We have table with over 20 000 000 records and now A'am cleaning
> it. I tryed to delete most of it with simple detele statement. (DELETE
> FROM [Stat].[dbo].[Stat] WHERE id < 28449928) It tryes to tun it, but it
> stopts becouse transactiong log becoms full... We do not have much of fre
> space for transaction logs...
> How do I disable rollback feature one time on my deletequery?
> Or how do I disable it from hole database? Databese get's every day 200
> 000 new records and it has many transactions over the day. But data that
> is strored is not critical so we would need more speed to our queries
> instead of failssafe.
> And another question. How do I speed up database table that has over 4 000
> 000 records? Mainly all queries are like queries or quesries against
> dates.
>
> T
>
Step 1.
To delete those rows, I would suggest that you do it in chunks so as not to
overload the transaction log.
For example:
DECLARE @.rowid int
SET @.rowid = 10000
WHILE @.rowid < 28449928
BEGIN
BEGIN TRAN
DELETE tablename
WHERE id <= @.rowid
BACKUP LOG <databasename> WITH TRUNCATE_ONLY
SET @.rowid = @.rowid + 10000
END -- Loop
Step 2
To speed up your queries...
Indexes, indexes, indexes...
Take the most often used queries that you are running, store them in a .sql
file and then use the Index Tuning Wizard to see what it suggests.
Rick Sawtell
MCT, MCSD, MCDBA
|||Ooops.
I forgot to stick a COMMIT in there.
DECLARE @.rowid int
SET @.rowid = 10000
WHILE @.rowid < 28449928
BEGIN
BEGIN TRAN
DELETE tablename
WHERE id <= @.rowid
IF @.@.Error <> 0
ROLLBACK
ELSE
COMMIT
BACKUP LOG <databasename> WITH TRUNCATE_ONLY
SET @.rowid = @.rowid + 10000
END -- Loop
|||I get this error from line BACKUP LOG stat WITH TRUNCATE_ONLY (stat is my
database)
Cannot perform a backup or restore operation within a transaction.
And transaction log is beeing filled up... And still this is very slow
delete procedure. Servers deletes about 1 000 000 recors in half hour...
"Rick Sawtell" <Quickening@.msn.com> kirjoitti
viestiss:O0cr8uCIGHA.3460@.TK2MSFTNGP12.phx.gbl...
> Ooops.
> I forgot to stick a COMMIT in there.
> DECLARE @.rowid int
> SET @.rowid = 10000
> WHILE @.rowid < 28449928
> BEGIN
> BEGIN TRAN
> DELETE tablename
> WHERE id <= @.rowid
> IF @.@.Error <> 0
> ROLLBACK
> ELSE
> COMMIT
> BACKUP LOG <databasename> WITH TRUNCATE_ONLY
> SET @.rowid = @.rowid + 10000
> END -- Loop
>
|||See posting 4 - the script was updated as Rick missed out a commit
Cheers
Steve L
|||Sill not working My scipt is here (17 000 000 is the start of my id):
DECLARE @.rowid int
SET @.rowid = 17000000
WHILE @.rowid < 28000000
BEGIN
BEGIN TRAN
DELETE dbo.stat
WHERE id <= @.rowid
IF @.@.Error <> 0
ROLLBACK
ELSE
COMMIT
BACKUP LOG stat WITH TRUNCATE_ONLY
SET @.rowid = @.rowid + 10000
END -- Loop
And still Transaction log is filled up and I get these error messages...
Cannot perform a backup or restore operation within a transaction.
"Steve L" <steve_lawrenson@.tiscali.co.uk> kirjoitti
viestiss:1138105823.735961.52530@.g44g2000cwa.goog legroups.com...
> See posting 4 - the script was updated as Rick missed out a commit
> Cheers
> Steve L
>
|||Sill not working My scipt is here (17 000 000 is the start of my id):
DECLARE @.rowid int
SET @.rowid = 17000000
WHILE @.rowid < 28000000
BEGIN
WHILE @.ROWCOUNT < 10001
BEGIN
DELETE dbo.stat
WHERE id = @.rowid
SELECT @.rowid = @.rowid+1, @.rowcount=@.rowcount+1
END
Select @.rowcount = 0
BACKUP LOG stat WITH TRUNCATE_ONLY
--SET @.rowid = @.rowid + 10000
END -- Loop
Using two loops - the inner one deletes the rows - one at a time though
- see how you get on - also test your backup log statement

Commit, rollback...

Hello!
I have problmes wtih my litle(single prosessor raid-5, standard sql) sql
server. We have table with over 20 000 000 records and now A'am cleaning
it. I tryed to delete most of it with simple detele statement. (DELETE FROM
[Stat].[dbo].[Stat] WHERE id < 28449928) It tryes to tun it, but
it stopts
becouse transactiong log becoms full... We do not have much of fre space for
transaction logs...
How do I disable rollback feature one time on my deletequery?
Or how do I disable it from hole database? Databese get's every day 200 000
new records and it has many transactions over the day. But data that is
strored is not critical so we would need more speed to our queries instead
of failssafe.
And another question. How do I speed up database table that has over 4 000
000 records? Mainly all queries are like queries or quesries against dates.
TTo minimize the log you can switch to the simple recovery mode.
For the delete operation, you could delete data in steps, perhaps using
rowvcount setting. That way, you can loop deletion of lets say 10000 records
until you dont have anything left to delete.
MC
"TLehtinen" <timo@.raa.to> wrote in message
news:43d4d775$0$7478$39db0f71@.news.song.fi...
> Hello!
> I have problmes wtih my litle(single prosessor raid-5, standard sql) sql
> server. We have table with over 20 000 000 records and now A'am cleaning
> it. I tryed to delete most of it with simple detele statement. (DELETE
> FROM [Stat].[dbo].[Stat] WHERE id < 28449928) It tryes to tun
it, but it
> stopts becouse transactiong log becoms full... We do not have much of fre
> space for transaction logs...
> How do I disable rollback feature one time on my deletequery?
> Or how do I disable it from hole database? Databese get's every day 200
> 000 new records and it has many transactions over the day. But data that
> is strored is not critical so we would need more speed to our queries
> instead of failssafe.
> And another question. How do I speed up database table that has over 4 000
> 000 records? Mainly all queries are like queries or quesries against
> dates.
>
> T
>|||"TLehtinen" <timo@.raa.to> wrote in message
news:43d4d775$0$7478$39db0f71@.news.song.fi...
> Hello!
> I have problmes wtih my litle(single prosessor raid-5, standard sql) sql
> server. We have table with over 20 000 000 records and now A'am cleaning
> it. I tryed to delete most of it with simple detele statement. (DELETE
> FROM [Stat].[dbo].[Stat] WHERE id < 28449928) It tryes to tun
it, but it
> stopts becouse transactiong log becoms full... We do not have much of fre
> space for transaction logs...
> How do I disable rollback feature one time on my deletequery?
> Or how do I disable it from hole database? Databese get's every day 200
> 000 new records and it has many transactions over the day. But data that
> is strored is not critical so we would need more speed to our queries
> instead of failssafe.
> And another question. How do I speed up database table that has over 4 000
> 000 records? Mainly all queries are like queries or quesries against
> dates.
>
> T
>
Step 1.
To delete those rows, I would suggest that you do it in chunks so as not to
overload the transaction log.
For example:
DECLARE @.rowid int
SET @.rowid = 10000
WHILE @.rowid < 28449928
BEGIN
BEGIN TRAN
DELETE tablename
WHERE id <= @.rowid
BACKUP LOG <databasename> WITH TRUNCATE_ONLY
SET @.rowid = @.rowid + 10000
END -- Loop
Step 2
To speed up your queries...
Indexes, indexes, indexes...
Take the most often used queries that you are running, store them in a .sql
file and then use the Index Tuning Wizard to see what it suggests.
Rick Sawtell
MCT, MCSD, MCDBA|||Ooops.
I forgot to stick a COMMIT in there.
DECLARE @.rowid int
SET @.rowid = 10000
WHILE @.rowid < 28449928
BEGIN
BEGIN TRAN
DELETE tablename
WHERE id <= @.rowid
IF @.@.Error <> 0
ROLLBACK
ELSE
COMMIT
BACKUP LOG <databasename> WITH TRUNCATE_ONLY
SET @.rowid = @.rowid + 10000
END -- Loop|||I get this error from line BACKUP LOG stat WITH TRUNCATE_ONLY (stat is my
database)
Cannot perform a backup or restore operation within a transaction.
And transaction log is beeing filled up... And still this is very slow
delete procedure. Servers deletes about 1 000 000 recors in half hour...
"Rick Sawtell" <Quickening@.msn.com> kirjoitti
viestiss:O0cr8uCIGHA.3460@.TK2MSFTNGP12.phx.gbl...
> Ooops.
> I forgot to stick a COMMIT in there.
> DECLARE @.rowid int
> SET @.rowid = 10000
> WHILE @.rowid < 28449928
> BEGIN
> BEGIN TRAN
> DELETE tablename
> WHERE id <= @.rowid
> IF @.@.Error <> 0
> ROLLBACK
> ELSE
> COMMIT
> BACKUP LOG <databasename> WITH TRUNCATE_ONLY
> SET @.rowid = @.rowid + 10000
> END -- Loop
>|||See posting 4 - the script was updated as Rick missed out a commit
Cheers
Steve L|||Sill not working My scipt is here (17 000 000 is the start of my id):
DECLARE @.rowid int
SET @.rowid = 17000000
WHILE @.rowid < 28000000
BEGIN
BEGIN TRAN
DELETE dbo.stat
WHERE id <= @.rowid
IF @.@.Error <> 0
ROLLBACK
ELSE
COMMIT
BACKUP LOG stat WITH TRUNCATE_ONLY
SET @.rowid = @.rowid + 10000
END -- Loop
And still Transaction log is filled up and I get these error messages...
Cannot perform a backup or restore operation within a transaction.
"Steve L" <steve_lawrenson@.tiscali.co.uk> kirjoitti
viestiss:1138105823.735961.52530@.g44g2000cwa.googlegroups.com...
> See posting 4 - the script was updated as Rick missed out a commit
> Cheers
> Steve L
>|||Sill not working My scipt is here (17 000 000 is the start of my id):
DECLARE @.rowid int
SET @.rowid = 17000000
WHILE @.rowid < 28000000
BEGIN
WHILE @.ROWCOUNT < 10001
BEGIN
DELETE dbo.stat
WHERE id = @.rowid
SELECT @.rowid = @.rowid+1, @.rowcount=@.rowcount+1
END
Select @.rowcount = 0
BACKUP LOG stat WITH TRUNCATE_ONLY
--SET @.rowid = @.rowid + 10000
END -- Loop
Using two loops - the inner one deletes the rows - one at a time though
- see how you get on - also test your backup log statement