Showing posts with label Sql Server. Show all posts
Showing posts with label Sql Server. Show all posts

Thursday, July 22, 2010

ResolveUrl in Javascript

ResolveUrl in Javascript


This is something that is super easy, yet I get asked about it quite often.

Here’s how you do it:

In the master page for the site, put this:

<script type="text/javascript">
        var baseUrl = "<%= ResolveUrl("~/") %>";
</script>

 

Then, in your javascript file, put this function:

function ResolveUrl(url) {
    if (url.indexOf("~/") == 0) {
        url = baseUrl + url.substring(2);
    }
    return url;
⁞}

You could have put the function right in the master page, but then you wouldn’t get intelli-sense on it for the rest of your code.

Wednesday, July 21, 2010

Stellar intros Stellar Phoenix SQL recovery v3.0

Recovery tool

Stellar intros Stellar Phoenix SQL recovery v3.0


The new offering provides user with the option to search tables in the scan result and databases in the computer Tuesday, July 20, 2010

NEW DELHI, INDIA: Soluton provider for database recovery & repair tools, Stellar information Systems Ltd. has announced the launch of Stellar Phoenix SQL Recovery v3.0 software, an easy to use application designed for corrupted Microsoft SQL (.mdf) files.

The software has been developed keeping the users’ availability of time and data in mind.

According to the release, the new offering, which is designed to recover and repair corrupted Microsoft SQL Database File, also restores damaged .mdf files in case of any virus attacks or unexpected system shutdown or media read error and so on.

 

"If you are losing your defaults, stored procedures, triggers, views, rules, NDF database files, then it is the best suited software for you. Is it difficult for you to understand the operation of various data recovery software; then try this Software for the better understanding and easy working.” commented Manoj Dhingra, director-domestic business, Stellar Information Systems.

The new version, which supports MS SQL 7.0, 2000, 2005 and 2008, recovers tables, views and rules and retrieves stored procedure and triggers as well. In addition to, it also recovers defaults, default constraints, user defined functions, user-defined data types, primary key, foreign keys, unique keys, identity, indexes, check constraints and .ndf database files said a press release.

Users can visit the company site to download demo version for an ovierview.

©CIOL Bureau

SQL Server Error Codes

 

The following table lists the SQL error codes. These codes are returned as the SQLCODE variable. 


SQL Error Codes

SQLCODE Error Code Meaning
-11002 WinSock: Nonauthoritative host not found
-11001 WinSock: Host not found
-10093 WinSock: Successful WSASTARTUP not yet performed
-10092 WinSock: WINSOCK DLL version out of range
-10091 WinSock: Network subsystem is unavailable
-10070 WinSock: Stale NFS file handle
-10065 WinSock: No route to host
-10064 WinSock: Host is down
-10061 WinSock: Connection refused
-10060 WinSock: Connection timed out
-10058 WinSock: Cannot send after socket shutdown
-10057 WinSock: Socket is not connected
-10056 WinSock: Socket is already connected
-10055 WinSock: No buffer space available
-10054 WinSock: Connection reset by peer (due to timeout or reboot)
-10052 WinSock: Net dropped connection or reset
-10051 WinSock: Network is unreachable
-10050 WinSock: Network is down
-500 Fetch row count limit reached
-471 Duplicate cursor name
-470 Option value changed
-469 Driver not capable
-468 Fetch type out of range
-467 Column type out of range
-466 Invalid parameter number
-465 Invalid string or buffer length
-464 Function sequence error
-463 Invalid column number
-462 Memory allocation failure
-461 Communication link failure
-460 General error
-453 Error in User Initialization Code
-452 Message sequencing error
-451 Unable to receive server message
-450 Unable to send client message
-430 Cannot initialize procedure context
-429 Invalid number of input/output parameters for Stored Procedure
-428 Stored Procedure Not Found
-427 Invalid Stored Procedure Name
-426 Error preparing Stored Procedure
-425 Error processing Stored Procedure request
-422 SELECT request processed via ODBC, JDBC, or Dynamic SQL cannot contain an INTO clause
-421 Warning: UPDATE or DELETE statement does not contain a WHERE clause
-415 Fatal error occurred within the SQL filer
-411 No stream object defined for field
-410 Invalid Directory
-409 Invalid server function
-408 Unable to start server
-407 Unable to Write to Server Master
-406 Unable to Write to Server
-405 Unable to read from communication device
-402 Invalid Username/Password
-401 Fatal Connection error
-400 Fatal error occurred
-374 Cannot alter the datatype of a field to/from a stream type when the table contains data
-373 An extrinsic function call may not call a % routine
-372 Support for extrinsic function calls are disabled
-371 :HVar = CALL ... Specified for a Procedure which does not return a value
-370 Embedded SQL CALL Statement can only be used for Method Procedures
-366 Schema name mismatch between trigger name and table name
-365 Trigger name not unique
-364 Trigger with same EVENT, TIME, and ORDER already defined
-363 Trigger not found
-362 Specified query or stored procedure not found
-361 More than one query or stored procedure found that matches your specification
-359 SQL Function (function Stored Procedure) not found
-358 SQL Function (function Stored Procedure) name not unique
-333 No such index defined
-325 Index cannot be dropped because it is the IDKEY index and the table has data
-324 Index with this name already defined for this table
-320 Cannot DROP table — One or more Foreign Key constraints reference this table
-319 Referenced table has no primary key defined
-317 Cannot DROP Constraint — One or more Foreign Key constraints reference this Unique constraint
-315 Constraint or Key not found
-314 Foreign key references non-unique key/column collection
-311 Foreign key with same name already defined for this table
-310 Foreign key references non-existent table
-307 Primary key already defined for this table
-306 Column with this name already exists
-305 Attempt to make field required when the table has one or more rows where the column value is NULL
-304 Attempt to add a NOT NULL field with no default value to a table which contains data
-300 DDL not allowed on this table definition
-201 Table or View name not unique
-137 View's WITH CHECK OPTION validation failed in UPDATE
-136 View's WITH CHECK OPTION validation failed in INSERT
-135 After Delete trigger failed
-134 Before Delete trigger failed
-133 After Update trigger failed
-132 Before Update trigger failed
-131 Before Insert trigger failed
-130 Before Insert trigger failed
-127 FOREIGN KEY Constraint failed referential check upon creation of the constraint
-125 UNIQUE or PRIMARY KEY Constraint failed uniqueness check upon creation of the constraint
-124 FOREIGN KEY Constraint failed referential check upon DELETE of row in referenced table
-123 FOREIGN KEY Constraint failed referential check upon UPDATE of row in referenced table
-122 FOREIGN KEY Constraint failed referential check upon UPDATE of row in referencing table
-121 FOREIGN KEY Constraint failed referential check upon INSERT of row in referencing table
-120 UNIQUE or PRIMARY KEY Constraint failed uniqueness check upon UPDATE
-119 UNIQUE or PRIMARY KEY Constraint failed uniqueness check upon INSERT
-118 Unknown or non-unique User or Role
-115 Cannot INSERT/UPDATE/DELETE on a read only table
-114 One or more matching rows is locked by another user
-113 %THRESHOLD Violation
-112 Access violation
-111 Cannot INSERT into a 'Default Only' RowID or RowID based on field
-110 Locking conflict in filing
-109 Cannot find the row designated for UPDATE
-108 Required field missing; INSERT or UPDATE not allowed
-107 Cannot UPDATE RowID or RowID based on Fields
-106 Row to DELETE not found
-105 Field validation failed in UPDATE
-104 Field validation failed in INSERT
-103 Positioned UPDATE or DELETE attempted, but the cursor is not positioned on any row
-102 Operation (FETCH/CLOSE/UPDATE/DELETE/...) attempted on an unopened cursor
-101 Attempt to open a cursor that is already open
-99 Privilege Violation
-97 Duplicate select-list names found
-96 Specified level of isolation is not supported
-95 Operation Disallowed by Operation Table
-94 Multi-Conditional OUTER JOINs are not supported
-93 Number of conditions for the DIAGNOSTICS SIZE must be exact numeric
-92 Level of isolation cannot be READ UNCOMMITTED if READ WRITE specified
-91 Transaction mode cannot be specified more than once
-90 Invalid view name
-89 Invalid index name
-88 Invalid field name
-87 Invalid table name
-86 Invalid field definition, no datatype defined
-85 Multiple table %ROUTINE definitions found
-84 Multiple table %NUMROWS definitions found
-83 Multiple table %FILE definitions found
-82 Multiple table %DESCRIPTION definitions found
-81 Column Constraint expected
-80 Integer expected
-79 Referencing key and referenced key must be the same size
-78 Invalid transaction state
-77 Qualified column reference not allowed in this JOIN context
-76 Cardinality mismatch between the SELECT-list and INTO-list
-75 Trim spec and/or trim char required before FROM in TRIM function
-74 Duplicate select-list alias names found
-73 Aggregates not supported in ORDER BY clause
-72 Multi-Line Field not valid in ORDER BY clause
-71 Multi-Line Field must be the Left operand of the Comparison
-70 Multi-Line Field only valid for LIKE, Contains ([), or NULL Comparison
-69 SET file = value-expression not allowed with WHERE CURRENT OF cursor
-68 DISTINCT not valid in subquery of FROM clause
-67 Aggregate not valid in subquery of FROM clause
-66 Redundant Fields Found in SELECT list
-65 Positive integer constant or variable expected
-64 Incompatible SELECT list is used in INSERT
-63 Data Exception - invalid escape character
-62 Additional new values expected for INSERT/UPDATE
-61 Cursor not updateable
-60 An action (%ALTER, SELECT, UPDATE, etc.) expected
-59 Cannot have more than one field
-58 Duplicate field found in trigger UPDATE of <fieldlist> clause
-57 Trigger specifies WHEN clause when trigger language not SQL
-56 Action not applicable to an object of this type
-55 Invalid GRANT role TO or REVOKE role FROM
-54 Array designator (last subscript omitted) expected after VALUES
-53 Constant or variable expected as new value
-52 Cursor (Already/Was Not) DECLAREd
-51 SQL statement expected
-50 Trigger specifies UPDATE OF <fieldlist> clause when trigger language not SQL
-49 Trigger REFERENCING clause cannot be specified when trigger language not SQL
-48 Invalid trigger REFERENCING clause for the trigger's event
-47 Illegal characteristic keyword for this type of create operation
-46 Missing EXECUTE or FETCH
-45 Duplicate query methods within the same statement
-44 Duplicate characteristics when creating a query, method, or procedure
-42 Closing quotes ("") missing following pattern match
-41 An extrinsic function call must have the form '$$tag^routine(...)'
-39 No RowID field for table
-38 No master map for table
-37 SQL Scalar/Aggregate/Unary function not supported for Stream fields
-36 WITH CHECK OPTION (CHECKOPTION class parameter) not allowed for a non-updatable view
-35 INSERT/UPDATE/DELETE not allowed for non-updatable view
-34 %INORDER: FROM order inconsistent with outer join order
-33 No field(s) found for table
-32 Outer-join symbol ( =* or *= ) must be between two fields
-31 Field not (Found/Mapped/Unique) in Table(s)
-30 Table or View not found
-29 Field ambiguous/not found
-28 Host variable name must begin with either % or a letter
-27 Ambiguous labels for field
-26 Missing FROM clause
-25 Input encountered after end of query
-24 Table or View not found
-23 Label is not listed in FROM
-22 ORDER must specify column names, not numbers, when after 'SELECT *'
-20 Name conflict in the FROM list over label
-19 An aggregate function cannot be used in a WHERE clause
-18 IS (or IS NOT) NULL predicate can be applied only to a field
-17 A for-condition expected after the ( in the for-expression
-16 A qualifier SOME or ALL expected after the FOR in the for-expression
-15 A condition expected after NOT
-14 A comparison operator is required here
-13 An expression other than a subquery expected here
-12 A term expected, beginning with one of the following: identifier, constant, aggregate, $$, :, (, +, -, %ALPHAUP, %UPPER, %STRING, or %EXACT
-11 A scalar expression expected, not a condition
-10 The SELECT list of the subquery must have exactly one item
-9 Incompatible SELECT lists used in UNION
-8 Invalid DATEPART code for DATEPART(), DATENAME(), DATEADD(), or DATEDIFF()
-7 ORDER column is not in the SELECT list
-6 ORDER must specify column number, not names, when after UNION
-5 Column number specified in ORDER does not match SELECT list
-4 A term expected, beginning with one of the following: identifier, constant, aggregate, %ALPHAUP, %UPPER, %STRING, %EXACT, $$, :, +, -, (, NOT, EXISTS, or FOR
-3 Closing quote (") missing
-2 Exponent digits missing after 'E'
-1 Invalid SQL statement
0 Successful Completion
100 No (more) data

SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT

SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT

 

 

SELECT @@IDENTITY

It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.

@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.

SELECT SCOPE_IDENTITY()

It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.

SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.

SELECT IDENT_CURRENT(‘tablename’)

It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.

IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.

To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.

Thursday, July 8, 2010

SQL: INSERT Statement

SQL: INSERT Statement


The INSERT statement allows you to insert a single record or multiple records into a table.

The syntax for the INSERT statement is:

INSERT INTO table
(column-1, column-2, ... column-n)
VALUES
(value-1, value-2, ... value-n);


Example #1 - Simple example

Let's take a look at a very simple example.

INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(24553, 'IBM');

This would result in one record being inserted into the suppliers table. This new record would have a supplier_id of 24553 and a supplier_name of IBM.

Example #2 - More complex example

You can also perform more complicated inserts using sub-selects.

For example:

INSERT INTO suppliers
(supplier_id, supplier_name)
SELECT account_no, name
FROM customers
WHERE city = 'Newark';

By placing a "select" in the insert statement, you can perform multiples inserts quickly.

With this type of insert, you may wish to check for the number of rows being inserted. You can determine the number of rows that will be inserted by running the following SQL statement before performing the insert.

SELECT count(*)
FROM customers
WHERE city = 'Newark';


Frequently Asked Questions

Question: I am setting up a database with clients. I know that you use the "insert" statement to insert information in the database, but how do I make sure that I do not enter the same client information again?

Answer: You can make sure that you do not insert duplicate information by using the EXISTS condition.

For example, if you had a table named clients with a primary key of client_id, you could use the following statement:

INSERT INTO clients
(client_id, client_name, client_type)
SELECT supplier_id, supplier_name, 'advertising'
FROM suppliers
WHERE not exists (select * from clients
where clients.client_id = suppliers.supplier_id);

This statement inserts multiple records with a subselect.

If you wanted to insert a single record, you could use the following statement:

INSERT INTO clients
(client_id, client_name, client_type)
SELECT 10345, 'IBM', 'advertising'
FROM dual
WHERE not exists (select * from clients
where clients.client_id = 10345);

The use of the dual table allows you to enter your values in a select statement, even though the values are not currently stored in a table.

Learn more about the EXISTS condition.

Question: How can I insert multiple rows of explicit data in one SQL command in Oracle?

Answer: The following is an example of how you might insert 3 rows into the suppliers table in Oracle.

INSERT ALL
INTO suppliers (supplier_id, supplier_name) VALUES (1000, 'IBM')
INTO suppliers (supplier_id, supplier_name) VALUES (2000, 'Microsoft')
INTO suppliers (supplier_id, supplier_name) VALUES (3000, 'Google')
SELECT * FROM dual;

Source :- http://www.techonthenet.com/sql/insert.php

Wednesday, July 7, 2010

Computing table content differences with Oracle SQL

Computing table content differences with Oracle SQL


The question "what is the difference between two tables? is simple to ask, but difficult to code. It's like an "anti-union" where we seek only the unique rows within each table.

Tropashko has a great analysis of this common SQL problem from both a mathematical perspective and a practical Oracle perspective. It also shows an undocumented technique for improving execution speed for querying the non-intersection of two tables.

Vadim notes that the _convert_set_to_join parameter can be used when comparing the contents of two tables. This type of SQL query is called a "semantic difference", or an "anti-union" operation. Tropashko depicts the table comparison problem below:

In the above figure we read the "/" as "not in" and the "∪" as "union". In sum, we want the table comparison SQL to find:

Rows in table A that are not in table B
plus
Rows in table B that are not in table A

Vadim notes that the obvious solution van have poor performance:

The figure 1 with the expressions (A \ B) ∪ (B \ A) and (A ∪ B) \ (A ∩ B) pretty much exhaust all the theory involved. It is straightforward to translate them into SQL queries. Here is the first one:

(select * from A
minus
select * from B) -- Rows in A that are not in B
union all
(
select * from B
minus
select * from A
) -- rows in B that are not in A

In practice, however, this query is a sluggish performer. With a naïve evaluation strategy, the execution flow and the operators are derived verbatim from the SQL which we have written. First, each table has to be scanned twice. Then, four sort operators are applied in order to exclude duplicates. Next, the two set differences are computed, and, finally, the two results are combined together with the union operator. . .

SQL Server - Temporary Table

SQL Server - Temporary Table

Creating a temporary table is virtually the same as creating a normal table. The main exception is the naming of the table. A hash ('#') character as the first character in the table name denotes that it is a temporary table.

There are two types of temporary tables, local and global.

A local temporary table has a single hash ('#') at the start of its name. A local temporary table is visible only to the user who created it and is destroyed automatically when that user disconnects.

A global temporary table is denoted by a name starting with two hashes (i.e. '##'). A global temporary table is visible to all users and is deleted automatically when the last user who has referenced the table disconnects.

An example of creating a local temporary table:

create table #foo
(
CarIndex smallint,
CarType varchar(20)
)

An example of creating a global temporary table:

create table ##baz
(
CarIndex smallint,
CarType varchar(20)
)

Popular Posts