Monday, March 23, 2009

Get list of all tables in SQL and its approximate row count

Here's the SQL to do this.
SELECT
[TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U'
AND
si.id = OBJECT_ID(so.name)
GROUP BY
so.name
ORDER BY
2 DESC

Kewl, huh!?
Reference: here

Thursday, March 19, 2009

Bracket Plus Sign (+) in SQL

SELECT *
FROM TABLE1 a, TABLE2 b
WHERE a.CODE = b.CODE(+)


This bracket plus sign (+) indicates a LEFT OUTER JOIN. It includes all records from TABLE1 and from TABLE2 that has CODE field value match.

Click here for more information

Monday, March 16, 2009

Clear Browsing History in IE7

Create batch file (for example: New_IE.bat)

Fill the file with this:
C:\Progra~1\Intern~1\iexplore.exe
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

When we exit Internet Explorer, System will clear all the history.
This only works for IE 7.

anonymizer
nph-proxy: website that will not write the history to the proxy.
http://www.bpcd.net/cgi-bin/nph-proxy.cgi
enter URL on the site, open all sites, only that url will show in the nph-proxy

or you can use this so that won't keep the history.
chrome: incognito
ie8 (beta): sorry, forgot the name
firefox: there's an option to clear

Wednesday, March 11, 2009

Identity after inserting

How is exactly to get the identity after inserting in MS SQL?
If the table u are inserting have identity set to YES.
Hence you can use this.
declare @theid as bigint
insert into tablename select myvalue1, myvalue2
set @theid=@@IDENTITY


So the new ID is kept in the variable @theid now.

Reference: here

Tuesday, March 10, 2009

BCP function

You can use this BCP function easily to import/export from the MS SQL database.

usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"]

Here's an example to export the data from the database.
- with trusted connection
bcp "dbname.dbo.tablename" out "dev_tablename.bcp" -e error.log -c -S servername -T -k

- with username and password
bcp "dbname.dbo.tablename" out "dev_tablename.bcp" -e error.log -c -S servername -U username -P password -k


Here's an example to import the data to the database.
- with trusted connection
bcp "dbname.dbo.tablename" in "dev_tablename.bcp" -e error.log -c -S servername -T -k

- with username and password
bcp "dbname.dbo.tablename" in "dev_tablename.bcp" -e error.log -c -S servername -U username -P password -k

- with username and password and order clause
bcp "dbname.dbo.tablename" in "dev_tablename.bcp" -e error.log -c -S servername -U username -P password -k -h "ORDER (TheDate DESC)"