background preloader

Sql

Facebook Twitter

MongoDb

Sql Server Reference. Retrieve – Select Only Date Part From DateTime – Best Practice. 2008 – Introduction to Table-Valued Parameters with Example. Failed to generate a user instance of SQL Server. Why audit logging with triggers in MySQL is bad for replication. September 29, 2008 by Ewen Fortune10 Comments Recently I was tasked with investigating slippage between master and slave in a standard replication setup.

Why audit logging with triggers in MySQL is bad for replication

The client was using Maatkit’s mk-table-checksum to check his slave data was indeed a fair copy of that of the master. mk-table-checksum --algorithm=BIT_XOR h=hostname.local,u=root,p=xxx --replicate=checksum.checksum --emptyrepltbl --chunksize=500000 --databases mydb --sleep 1 He could then examine the checksum.checksum table and see all was well, however there were various tables with different crc values. Sql Server. Triggers 2 - Creating Audit Trails - Author Nigel Rivett. CREATE INDEX (Transact-SQL) The CREATE INDEX statement is optimized like any other query.

CREATE INDEX (Transact-SQL)

To save on I/O operations, the query processor may choose to scan another index instead of performing a table scan. The sort operation may be eliminated in some situations. On multiprocessor computers CREATE INDEX can use more processors to perform the scan and sort operations associated with creating the index, in the same way as other queries do. For more information, see Configure Parallel Index Operations. The create index operation can be minimally logged if the database recovery model is set to either bulk-logged or simple. Indexes can be created on a temporary table. Indexes support extended properties. Clustered Indexes. Index (database) Usage[edit] Support for fast lookup[edit] Most database software includes indexing technology that enables sub-linear time lookup to improve performance, as linear search is inefficient for large databases.

Index (database)

Suppose a database contains N data items and it is desired to retrieve one of them based on the value of one of the fields. A naïve implementation would retrieve and examine each item until a match was not found. A successful lookup would retrieve half the objects on average; an unsuccessful lookup all of them for each attempt. An index is any data structure that improves the performance of lookup. Policing the database constraints[edit] Indexes are used to police database constraints, such as UNIQUE, EXCLUSION, PRIMARY KEY and FOREIGN KEY. James Gregory » SQL Server Object Exists Function. Update: Added separate versions for SQL Server 2000 and SQL Server 2005, due to the differences in the system objects tables.It may just be me, but when writing migration/create scripts for use with SQL Server I get quite agitated at having to write an ugly, long-winded, drop statement at the start of every object definition.

James Gregory » SQL Server Object Exists Function

The support for dropping objects is one of the few things I would say MySQL has SQL Server over the barrel for.Baring in mind that if you try to drop an object that doesn’t exist, you’ll get an execution error; here’s how to drop a table in MySQL: Here’s how to drop the same table, if you’re using SQL Server: As always, when something annoys you enough and you’re in the middle of something else, it’s about time you wrote that solution. So I’ve created a simple user-defined function that checks if an object exists then returns a BIT 0 or 1 depending.

Common Object Types: Sql - How to SELECT * INTO [temp table] FROM [Stored Procedure] Select from a Stored Procedure. Thank you for your quick reply visakh, Yep, I did not explain myself very well did I lol - sorry!

Select from a Stored Procedure

:( Rewriting Stored Procedures as Functions. This topic describes how to determine whether to rewrite existing stored procedure logic as user-defined functions.

Rewriting Stored Procedures as Functions

For example, if you want to invoke a stored procedure directly from a query, repackage the code as a user-defined function. In general, if the stored procedure returns a, single, result set, define a table-valued function. If the stored procedure computes a scalar value, define a scalar function. Sql server - How to call Stored Procedure in a View. Table-Valued Parameters in SQL Server 2008. Transactions and Locks in SQL Server « SQLDBPOOL.COM. I 32 Votes A database transaction is a unit of work performed against a database management system or similar system that is treated in a coherent and reliable way independent of other transactions.

Transactions and Locks in SQL Server « SQLDBPOOL.COM

A database transaction, by definition, must be atomic, consistent, isolated and durable. These properties of database transactions are often referred to by the acronym ACID. T-SQL Enhancements in SQL Server 2005 > SNAPSHOT Isolation. SQL Server changes the state of a database by performing a transaction on it.

T-SQL Enhancements in SQL Server 2005 > SNAPSHOT Isolation

Each transaction is a unit of work consisting of one or more steps. A "perfect" transaction is ACID, meaning it is atomic, consistent, isolated, and durable. In short, this means that the result of performing two transactions on a database, even if they are performed simultaneously by interleaving some of the steps that make them up, will not corrupt the database. Atomic means that a transaction will perform all of its steps or fail and perform none of its steps.

Consistent means that the transaction must not leave the results of a partial calculation in the database; for example, if a transaction is to move money from one account to another, it must not terminate after having subtracted money from one account but not having added it to another. SELECT FOR UPDATE with SQL Server.

Transact-SQL User's Guide. Using temporary tables Temporary tables are created in the tempdb database. To create a temporary table, you must have create table permission in tempdb. create table permission defaults to the Database Owner. To make a table temporary, use the pound sign (#) or "tempdb.. " before the table name in the create table statement. There are two kinds of temporary tables: Tables that can be shared among Adaptive Server sessionsYou create a shareable temporary table by specifying tempdb as part of the table name in the create table statement.

If you do not use the pound sign or "tempdb.. " before the table name, and you are not currently using tempdb, the table is created as a permanent table. 5 subtle ways you’re using MySQL as a queue, and why it’ll bite you. Note: This guest post is from our friends at Percona about using MySQL as a job queue.

5 subtle ways you’re using MySQL as a queue, and why it’ll bite you

I work for Percona, a MySQL consulting company. To augment my memory, I keep a quick-reference text file with notes on interesting issues that customers ask us to solve. One of the categories of frequent problems is attempts to build a job queue in MySQL. I have so many URLs under this bullet point that I stopped keeping track anymore. Customers have endless problems with job queues in their databases.

Many people realize the difficulties in building a good job queue or batch processing system, and try not to create one inside MySQL. Here are some of the most common ways I've seen the job-queue design pattern creep into an application's database. As you can see, queues are sly; they slip into your design without you realizing it. Let's dive a little bit into why job queues can cause trouble, and then I'll show you some ways to help reduce the chance it'll happen to you.

Polling. Microsoft SQL Server Product Samples: Database - Download: SQL Server 2008 SR4. How to determine the version and edition of SQL Server and its components. Step-by-Step: Installing SQL Server Management Studio 2008 Express after Visual Studio 2010 - Beth Massi - Sharing the goodness that is VB. UPDATE 7/31/2012 – Since this post new versions of SQL Server & Visual Studio have been released.

Step-by-Step: Installing SQL Server Management Studio 2008 Express after Visual Studio 2010 - Beth Massi - Sharing the goodness that is VB

To install the latest version of SQL Server see SQL Server Install. For more information on working with SQL Server Local DB in Visual Studio 2012 see Working with SQL Server LocalDB in Visual Studio 2012 and the MSDN Library SQL Server 2012 Express LocalDB. One of the first things I always do after installing Visual Studio is to install SQL Server Management Studio (SSMS). Visual Studio 2010 installs SQL Server 2008 Express on your machine but doesn’t include SSMS. Although you can use Visual Studio to create/connect/design databases, I like having SSMS around for advanced management. Okay the first thing you need is to make sure you get the right version of SSMS. STEP 1: Download Microsoft® SQL Server® 2008 Management Studio Express and select either SQLManagementStudio_x64_ENU.exe or SQLManagementStudio_x86_ENU.exe depending on your machine’s OS bit-ness. STEP 16: Complete!

Enjoy! A co-Relational Model of Data for Large Shared Data Banks. Erik Meijer and Gavin Bierman, Microsoft Contrary to popular belief, SQL and noSQL are really just two sides of the same coin. Editor's note: Some of the characters in this article will not display properly in some browsers. Joe Celko The SQL Apprentice. Sql - Recursive CTE to find parent records. Recursive Queries Using Common Table Expressions. A common table expression (CTE) provides the significant advantage of being able to reference itself, thereby creating a recursive CTE. Sql server 2005 - How to self JOIN recursively in SQL.