Tuesday, August 28, 2012

List Extended Properties for all Tables and Columns

Extended Properties in SQL Server give you the ablility to attach a comment or description to an object in the database. When you use Management Studio to add a Description to a table or column, it is stored as an Extended Properties with the name of MS_Description, and the object it relates to.
You can use the fn_listextendedproperty() table function to return the extended properties for the database, or a specific table or column. But what if you want to return all comments for all column and tables in the database? Well you'll need to use the system tables directly to make that happen.
To select all the extended properties for all the columns and tables in the database, use this command:

SELECT OBJECT_NAME(EXP.major_id) AS TableName, 
       C.name                    AS ColumnName, 
       EXP.name                  AS PropertyName, 
       EXP.value                 AS PropertyValue
FROM   sys.extended_properties AS EXP
LEFT OUTER JOIN sys.columns AS C
ON    C.object_id = EXP.major_id
AND   C.column_id = EXP.minor_id
WHERE EXP.class_desc = 'OBJECT_OR_COLUMN'
 
http://www.julian-kuiters.id.au/article.php/extended-properties-all-tables-columns 

Associating editors with file types

To associate editors with various file types in the Workbench:

  Open the
 
  command link
  General > Editors > File Associations preference page.
  Select the file type from the File types list, or click Add
    to add a type that is not already on the list.
  In the Associated editors list, select the editor that you want
    to associate with that file type. To add an editor to the list:
   
      Click Add. The Editor Selection dialog box opens.
      Select Internal Editors or External Programs, depending on
          whether the editor that you want was built for the Workbench or runs outside the Workbench.
      If you select External Programs, you can click the Browse button to
          browse the file system.
      Select the editor from the list and click OK.
   
 
  Click  OK to finish associating the editor with the selected file type.


When you associate an internal editor with a file type, that editor opens in
the editor area of the Workbench. For example,  if you double-click a file in the
Project Explorer or an entry in the Bookmarks or Tasks view it opens in the editor area.


Windows only
Editors that support OLE document mode can also run in the editor area of the Workbench.


Tip: You can choose to override your default editor selections by
selecting Open With from the pop-up menu for any resource in one of the navigation views.

Monday, August 27, 2012

What are the differences between MSSQL, T-SQL, and SQL

SQL is the basic ANSI standard for accessing data in a relational database. When you see "MSSQL" it is referring to Microsoft SQL Server, which is the entire database architecture and not a language. T-SQL is the proprietary form of SQL used by Microsoft SQL Server. It includes special functions like cast, convert, date(), etc. that are not part of the ANSI standard.
You will also see things like plSQL, which is Oracle's version of SQL, and there are others as well (mySQL has its own version, for example, and Microsoft Access uses Jet SQL.)
It is important to note the the ANSI standard for SQL has different releases (for example, 92 or 99, representing the year it was released.). Different database engines will advertise themselves as "mostly ANSI-92" compliant or "fully ANSI-99" compliant, etc, and any exceptions will usually be documented.
So although "SQL is SQL", every engine uses its own "flavor" of it, and you do have to do a little reading on the particular platform before you just dive in.
A further note - the SQL extensions, like T-SQL, are generally considered full-fledged programming languages, complete with looping, if/then, case statements, etc. SQL itself is limited to simply querying and updating data and is not considered a true programming language.
Wikipedia has a decent article for an overview here: http://en.wikipedia.org/wiki/SQL

http://stackoverflow.com/questions/1301038/what-are-the-differences-between-mssql-t-sql-and-sql

Friday, August 24, 2012

What are some best practises and “rules of thumb” for creating database indexes?

Some of my rules of thumb:
  • Index ALL primary keys (I think most the RDBMS do this when creating it).
  • Index ALL foreign keys columns.
  • Create more indexes ONLY if:
    • Queries are slow.
    • You know the data volume are going to increase significantly.
  • Run statistics when populating a lot of data on tables.
If a query is slow, look for the execution plan and:
  • If the query for a table only uses few columns put all that columns on an index, then you can help the RDBMS to use only the index.
  • Don't waste resources indexing tiny tables (hundreds of records).
  • Index multiple columns in order from high cardinality to less. It means, first the columns with more distinct values followed by columns with few distinct values.
  • If a query needs to access more that 10% of the data, normaly is better a full scan that an index.
http://stackoverflow.com/questions/687986/what-are-some-best-practises-and-rules-of-thumb-for-creating-database-indexes

Windows equivilent to UNIX pwd

this prints it in the console
echo %cd% 
http://stackoverflow.com/questions/921741/windows-equivilent-to-unix-pwd 

What is the difference between a process and a thread

Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces.
I'm not sure what "hardware" vs "software" threads might be referring to. Threads are an operating environment feature, rather than a CPU feature (though the CPU typically has operations that make threads efficient).
Erlang uses the term "process" because it does not expose a shared-memory multiprogramming model. Calling them "threads" would imply that they have shared memory.

http://stackoverflow.com/questions/200469/what-is-the-difference-between-a-process-and-a-thread

Cheat Sheet for Windows Command Prompt

I got bored today, found some command line links that I had and decided to read them all. The following is my command prompt reference in case I forget any of it. This can also be used as a how-to guide if you are new to the Windows command line. You can open the your program and start testing out the features. Just make sure you don’t accidentally delete anything important.
Here’s the results: (if you are new to this, then first see cd and dir)
Feel free to leave feedback!

To open the Windows command prompt you may do one of the following:

- Click Start -> Programs -> Accessories -> Command Prompt
- Click Start (or hit the Windows key), type “cmd” in search, then hit [ENTER]
- Windows Key + R (#r, not the pound symbol) brings up Run. Then type “cmd” then [ENTER]
- SHIFT + right-click in any folder or desktop, then select “open command window here”

 

Basic Command Prompt Commands

x /? = provides syntax info and complete list of all parameters for x (a command, like “cd”)
cd = change directory
cd .. = move to the parent directory
cd\ = move to the root of current drive
cd x = move to the current\x directory
cd z: = change to the z root directory (as opposed to c:\)
copy x y = copy file x to directory y (Ex: D:\games\galaga.exe C:\programs[\awesome.exe]), [] = optional
copy file con = display file contents in console
copy con file.txt = create text file in the console window, end with ctrl+z (^z or F6)
date = change the date
del = delete/erase
del x = deletes all files/folders fitting x
del . = deletes all files within current directory
del *.* = deletes all files within current directory
dir = display contents of current directory (Ex: dir [c:][\programs]), [] = optional
dir *.txt = list all .txt files in current directory
dir *.? = list all files with extensions one character in length in current directory
dir /w /p *.* = display all contents one screen at a time
dir | more = display all contents one line at a time
dir /? = provides syntax info and complete list of all dir parameters
echo = send command line input to display (by default)
echo sometext >> somefile.txt = append line(s) of text to any file
echo sometext > somefile.txt = overwrites file with sometext
erase = delete/erase
exit = exit the command prompt
filename.txt = opens filename.txt in current directory in Notepad (or default .txt program)
format z: = format z drive [Ex: use to format a disc or flash drive]
mkdir x = make directory x in current directory
move x y = more or rename x to y
q = escapes sequential display of contents (i.e. the more parameter)
rd x = remove/delete directory x if it’s empty
ren x y = rename file x to y
time = change the time
type file = display the contents of the file ‘file’ (displays file contents in console)
type file |more = display the contents one line at a time

 

Advanced Command Prompt Commands

ipconfig [/all] = display network adapter information (advanced)
netstat –n = display local address and addresses you are connected to (advanced)
netstat –nb = above with name of foreign addresses (advanced) (this shows your private IP, if you are behind a router or proxy, then your public IP address will be different)
ping google.com = how long it takes for your computer to talk to google.com

 

Convert output of one process into the input of another process

Send contents of script.js to the system debug.exe file:
type script.js | c:\programs]debug.exe
programs\debug.exe < script.js

 

Send directory listing to a printer or file

dir > prn (theoretically to a printer)
dir > somefile.txt
dir *.mp3 > c:\Users\Dan\Desktop\musiclist.txt = print all .mp3 files in current directory to musiclist.txt

 

Customize the DOS command prompt

prompt /? = display prompt options
prompt $p$g = display current directory followed by a greater-than symbol (Windows default)
prompt $p$g$t = display time after the default prompt
prompt [%computername%][%username%] $g = display computer name followed by username
prompt = reset prompt to default
color 0a = change prompt color to matrix green and screen color to black
color 84 = change colors to red on grey
0 = black
1 = blue
2 = green
3 = cyan
4 = red
5 = magenta
6 = yellow
7 = white
8 = grey
9 = bright blue
a = bright green
b = bright cyan
c = bright red
d = bright magenta
e = bright yellow
f = bright white

 

Modify any file extension associations

[assoc .extension=fileType]
assoc /? = prints this information
assoc = display list of current file extensions recognized by your computer (any fileType value may be used)
assoc > fileextensions.txt = print list to somefile.txt in current directory
assoc .txt = displays current file association of .txt (.docx, .html, .zip, .htaccess, assoc textfile, et cetera)
assoc .txt= = will delete the association for the given file extension
File Extension Tips/Ideas:
- Windows by default doesn’t know the following extensions, but check anyways with “assoc .”, “assoc .htaccess” and “assoc .xml” anyways just to be sure. If the extension is defined already, then you may not need to change it.
assoc .=txtfile = associate extensionless files with Notepad
assoc .htaccess=txtfile = associate nameless .htaccess files with Notepad
assoc .xml=txtfile = associate XML files with Notepad

 

Miscellaneous

Acceptable characters: A-Z a-z 0-9 $ # & @ ! ( ) – { } ‘ ` _ ~
Unacceptable characters: | < > \ ^ + = ? / [ ] ” ; , * : %
? = wildcard for any single character
* = wildcard for any/all characters/files
> = redirects output to (overwrite) a file or device
>> = redirects output to (append to) a file or device
< = directs data from a file or device to a program or device
<< = directs additional data from a file or device to a program or device
nul = black hole

Environmental Variables via the DOS command prompt

  • System-generated upon Windows startup:
    %DATE% = Tue 08/02/2011
    %TIME% = 14:23:33.37
    %SYSTEMROOT% = C:\Windows
    %COMPUTERNAME% = DAN-PC
  • System-generated upon user login:
    %USERNAME% = Dan
    %USERDOMAIN% = Dan-PC
  • Local machine variables for all users:
    %PATH% = C:\Windows\system32
    %HOMEPATH% = \Users\Dan
    %HOMEDRIVE% = C:
    (Hint: Use echo)

 

Function Keys

F1 = Sequential, individual repeat of previously entered characters
F2 = Copies any number of characters from the previous command line
F3 = Repeats the contents of the previous command line
F4 = Deletes any number of characters from the previous command line
F5 = Return to the previous command line
F6 = Enters the characters ^z (CTRL+z), indicating “end of file”
F7 = Displays a history of command-line entries for the current session (50-line cache)
F8 = Sequentially displays previous command-line entries
F9 = Enables user to recall previous command lines by number (0 = first line)

http://blog.simplyadvanced.net/cheat-sheet-for-windows-command-prompt/