Friday, December 24, 2004

Get the primary key(ID) of the last inserted record in Access and SQL Server

(Obtener la clave primaria(ID) del ultimo registro insertado en Access y SQL Server)

One of the most common things that you have to do when you are working with databases is taking the primary key of the last inserted record. Usually, after making the insert, you make another query with the same parameters that you use in the insert for taking the primary key of the inserted record.

There is 3 solutions:

1) SELECT @@IDENTITY(MS Access and SQL Server)

I have tested it in MS Access and SQL Server with a desktop app and with some store procedures having the correct values in both cases, BUT it doesn't work well in any other cases, because 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. So if you made 2 inserts and you want get the id of the first one, Select @@identity returns to you the id of the second insert. Another problem is if you insert a value in a table, and this insertion throws a trigger which makes an insert in another one table. In this case SELECT @@IDENTITY returns the ID of this second table.

2) SELECT IDENT_CURRENT('tablename')(only SQL Server 2000)
This new function 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.

3) SELECT SCOPE_IDENTITY()(only SQL Server 2000)
This new function 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.

For more information read http://www.databasejournal.com/features/mssql/article.php/3307541



Permalink: Get the primary key(ID) of the last inserted record in Access and SQL Server 

Friday, December 10, 2004

DOCTYPE and XML declarations. Headers and document definitions

(DOCTYPE y declaraciones XML. Cabeceras y definiciones de documentos)

Via this web I found a lot DOCTYPEs of markup languages(I have added someone).

If you have fought with mobile phones, you have found a lot of problems with this.

Let's see the rest of the page and the following pages, it's excellent. It has an interesting relationship about how tags must be used in those languages.

A lot of work waiting for you!!!


WML 1.1
<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml11.dtd"><wml>

WML 1.2
<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd"><wml>

WML 1.3
<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"><wml>

WML 2.0
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD WML 2.0//EN" "http://www.wapforum.org/dtd/wml20.dtd" ><html xmlns="http://www.w3.org/1999/xhtml" xmlns:wml="http://www.wapforum.org/2001/wml">

XHTML 1.0
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

XHTML Basic
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"><html xmlns="http://www.w3.org/1999/xhtml xml:lang="en" lang="en">

XHTML-MP-WAP
<?xml version="1.0" encoding="UTF-8"?>lt;!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml">

HTML 4.01
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><HTML>

HTML 4 Mobile
<!DOCTYPE HTML SYSTEM "-//W3C//DTD HTML 4.0//EN" "html40-mobile.dtd"><HTML>

cHTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD Compact HTML 1.0 Draft//EN"><HTML>

i-mode 3.0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD Compact HTML1.0 Draft//EN"><HTML>

Palm Web Clipping
<!DOCTYPE HTML PUBLIC "-//POS//DTD Palm OS HTML 3.2 Final//EN"><HTML>



Permalink: DOCTYPE and XML declarations. Headers and document definitions