Registered member login:
Register Now
Altirigos » Altiris Administrators » SQL » SQL Basics Part I

» Current Poll
Do you leave the Aclient enabled?
YES - 82.31%
107 Votes
NO - 17.69%
23 Votes
Total Votes: 130
You may not vote on this poll.
» Stats
Members: 9,499
Threads: 11,754
Posts: 55,313
Top Poster: Nick (4,981)
Welcome our newest member, anthony.hardy
» Online Users: 36
0 members and 36 guests
No Members online
Most users online at once 294, 06-30-2007 at 12:24 PM.
» March 2010
S M T W T F S
28 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 123
Reply
Old 10-15-2005, 01:18 AM   #1 (permalink)
 
Nick's Avatar
 
Status: Altiris Architect (Site Founder)
Join Date: 01-01-2005
Location: RDU, North Carolina, USA
Posts: 4,981


SQL Basics Part I

I thought I would try to start offering up some basic SQL query information in layman terms. It is my hopes this will help others to better retrieve information from their database. Please provide feedback, comments or corrections so that others may benefit.

SQL Basics

By Nick Graham



The SELECT Statement

The SELECT statement forms the foundation of any information gathering you want to accomplish from a database. When you use a SELECT statement, you are “querying” or “asking” the database to show you information based on the parameters you define.

A SELECT statement is composed of several keywords, known as clauses, but for this particular discussion I am going to focus on one..the FROM clause. For this example I will use the vcomputer table from the Altiris Notification Server database. Below is some sample data that is representative of what you would find.

Note: This table does not accurately reflect columns and data from the vcomputer table.

Table: vComputer
Name Domain User OS Name OS Version IP Address
Computer1 Altiris Jim Window XP 5.1 192.168.0.1
Computer2 Altiris Andrew Windows 2000 5.0 192.168.15.4

As with any request for information you have to describe what you want and where to get it. The SELECT portion of a query tells the database “Hey, I want information!”. Here is a very basic SQL query structure:

SELECT <column name> FROM <table name>


Lets use our vComputer table above to try it out.

SELECT Name FROM vComputer

This query is asking the database to give you every record from the Name column in the vComputer table. This query would return the following results:



Name
Computer1
Computer2


This information is good but is not very useful by itself. If we modify the SELECT statement a bit we can gather more information. Lets give it a try.

SELECT Name, User FROM vComputer

This query is exactly like the first but we added a second column name User. You will want to take note that the column names are separated by a comma. You will need to separate each column with a comma remembering that the last column prior to the FROM clause will NOT require a comma. This query would return the following results from our vComputer table.

Name User
Computer1 Jim
Computer2 Andrew

You can add as many columns requests as you would like to the SELECT statement as long as that column exists in the table you are wanting to retrieve data from. You may be saying… “Nick, I want to retrieve everything from the table. Do I have to enter every column name in a SELECT statement?” The answer is no. You can use the asterick in place of the column name to get all the information from a table. Lets look at the SELECT structure for this with the results.

SELECT * FROM vComputer

Using that statement would give you the following information.

Name Domain User OS Name OS Version IP Address
Computer1 Altiris Jim Window XP 5.1 192.168.0.1
Computer2 Altiris Andrew Windows 2000 5.0 192.168.15.4


AS you can see the SELECT statement with the FROM clause gives you access to all the information that a table within your database contains. This concludes the first part of SQL Basics. I will follow up next time with the WHERE clause which will define a search condition.

*My apologies for the poor formatting of the tables. I'll work on making it more presentable.
__________________
Scire potentia est (knowledge is power)
Nick is offline   Reply With Quote
Old 10-15-2005, 11:11 AM   #2 (permalink)
Ray
 
Ray's Avatar
 
Status: Altiris Engineer (Patch Prodigy)
Join Date: 02-17-2005
Location: Houston, Texas, USA
Age: 36
Posts: 333


I like the idea Nick. Keep the info coming I for one appreciate it a ton.
__________________
Ramon Delgado
Ramondelgado@gmail.com
www.altirigos.com
Ray is offline   Reply With Quote
Old 02-17-2006, 03:21 PM   #3 (permalink)
 
dominique's Avatar
 
Status: Sticky...
Join Date: 03-04-2005
Location: Culver City, CA
Age: 53
Posts: 3,394


Hell,

I am also working on this.
I have already added a field to the screen. The basic steps are:
1) Create a folder custom_worker
2) Create a folder custom inside the custom_worker
copy the profile files you want to update (winuser, worker, etc...) to the folder custom_worker
you should have:
web.config
default.aspx
NSDashBorad.aspx
Folder.aspx

3) Then choose the template you want to update in the templates folder
subWorkItemFind.ascx

4) create a custom.config file containing the redirection you need to access custom_worker\custom, etc...
<?xmlversion="1.0"encoding="utf-8"?>
<custom.configuration>
<!-- BEGIN Custom commands ================================================== === -->
<!-- Customization For HelpDesk - DD 02/13/2006 -->
<filespath="~/Custom_Worker/Custom/">
<fileid="subWorkItemFind"file="subWorkItemFind.ascx"/>
</files>
<!-- END Custom commands ================================================== ===== -->
</custom.configuration>

5) Update the files subWorkItemFind.ascx with the function you want to have in your Find Incidents.

6) you will need to write a query which will fill the form you updated.
(I am working on this part now and do not have all details yet)

You van look also at the documentation Helpdesk there is a part for customization.

I hope it helps,
Thanks,
Dom
dominique is offline   Reply With Quote
Old 02-17-2006, 03:44 PM   #4 (permalink)
 
Mike's Avatar
 
Status: Altiris Engineer (Super Mod)
Join Date: 02-22-2005
Location: South Jordan, Utah, USA
Posts: 1,196


I can contribute a little here. Let me know what the topic of "SQL Basics, Part 2" should be and I'll put in my 2 cents.

I'm guessing the "Where" clause will be next, then followed by the "Join" statement and then subqueries (In, Not in)?
__________________
______________________
Mike Ainsworth

Mike is offline   Reply With Quote
Old 02-17-2006, 03:50 PM   #5 (permalink)
 
Nick's Avatar
 
Status: Altiris Architect (Site Founder)
Join Date: 01-01-2005
Location: RDU, North Carolina, USA
Posts: 4,981


HERE you go Mike.

Yeah the next step was to start talking about Joins etc. Feel free to put something together to extend it. I've fallen behind miserably on continuing the series.
__________________
Scire potentia est (knowledge is power)
Nick is offline   Reply With Quote
Old 02-17-2006, 03:52 PM   #6 (permalink)
 
dominique's Avatar
 
Status: Sticky...
Join Date: 03-04-2005
Location: Culver City, CA
Age: 53
Posts: 3,394


you are worth more than 2cts Mike it has been a Power Ball value.... for me all your help.

For this part we need to think about several type of updated tables:
- workitem by adding a column and populating the column through Insert into query
insert into query (name, expression, cache_results)
values (N'List_Name', N'SELECT * FROM table name, views...

- tag by adding a column to an existing definition of grid (I do not have any clue on this update as i am getting # types of errors, maximum length 128, access violation, etc... with this SQL:
exec sp_addtag @tag_collection_id = '0', @new_name = subWorkItemTable_columns,
@new_value = "<cols><col id='' name='sidColNumber' dataField='workitem_number'
dataFormatString='{0} displayOptional='False' sortExpression='' visible='True'
width='50'><map /></col><col id='' name='sidColTitle' dataField='workitem_title'
dataFormatString='{0}' displayOptional='False' sortExpression='' visible='True'
width=''><map /></col><col id='' name='sidColAssigned' dataField='assigned_to_worker_name'
dataFormatString='{0}'displayOptional='False' sortExpression='' visible='True' width='100'><map />
</col><col id=''name='csidColContact' dataField='modified_by_worker_contact_name'
dataFormatString='{0}'displayOptional='False' sortExpression='' visible='True'
width='100'><map /></col><col id='' name='' dataField='workitem_priority_lookup_ordinal'
dataFormatString='{0}' displayOptional='False' sortExpression='' visible='False' width=''><map /></col>
<col id='' name='sidColPriority' dataField='workitem_priority_lookup_value' dataFormatString='{0}'
displayOptional='False' sortExpression='workitem_priority_lookup_ordinal' name='sidColCategory'
dataField='workitem_category_tree_value' dataFormatString='{0}' displayOptional='True'
sortExpression='' visible='True' width='110'><map /></col><col id='' name='sidColModified'
dataField='workitem_modified_on' dataFormatString='{0}' displayOptional='True' sortExpression=''
visible='True' width='110'><map /></col></cols>"
GO


Thanks,
Dom
dominique is offline   Reply With Quote
Old 02-17-2006, 08:52 PM   #7 (permalink)
 
Mike's Avatar
 
Status: Altiris Engineer (Super Mod)
Join Date: 02-22-2005
Location: South Jordan, Utah, USA
Posts: 1,196


oh thanks!
__________________
______________________
Mike Ainsworth

Mike is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Powered by vBadvanced CMPS v3.0 RC2

All times are GMT -4. The time now is 07:32 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
vB.Sponsors
Altirigos