Sunday, December 23, 2007

SQL

Q) What is Primary Key?

A primary key is used to uniquely identify each row in a table. It can either be part of the actual record itself, or it can be an artificial field (one that has nothing to do with the actual record). A primary key can consist of one or more fields on a table. When multiple fields are used as a primary key, they are called a composite key.
Primary keys can be specified either when the table is created (using CREATE TABLE) or by changing the existing table structure (using ALTER TABLE).
Below are examples for specifying a primary key when creating a table:
MySQL: CREATE TABLE Customer (SID integer, Last_Name varchar(30), First_Name varchar(30), PRIMARY KEY (SID));
Oracle: CREATE TABLE Customer (SID integer PRIMARY KEY, Last_Name varchar(30), First_Name varchar(30));
SQL Server: CREATE TABLE Customer (SID integer PRIMARY KEY, Last_Name varchar(30), First_Name varchar(30));
Below are examples for specifying a primary key by altering a table:
MySQL: ALTER TABLE Customer ADD PRIMARY KEY (SID);
Oracle: ALTER TABLE Customer ADD PRIMARY KEY (SID);
SQL Server: ALTER TABLE Customer ADD PRIMARY KEY (SID);
Note: Before using the ALTER TABLE command to add a primary key, you'll need to make sure that the field is defined as 'NOT NULL' -- in other words, NULL cannot be an accepted value for that field.




Q] What is a Foreign Key?

A foreign key is a field (or fields) that points to the primary key of another table. The purpose of the foreign key is to ensure referential integrity of the data. In other words, only values that are supposed to appear in the database are permitted.
For example, say we have two tables, a CUSTOMER table that includes all customer data, and an ORDERS table that includes all customer orders. The constraint here is that all orders must be associated with a customer that is already in the CUSTOMER table. In this case, we will place a foreign key on the ORDERS table and have it relate to the primary key of the CUSTOMER table. This way, we can ensure that all orders in the ORDERS table are related to a customer in the CUSTOMER table. In other words, the ORDERS table cannot contain information on a customer that is not in the CUSTOMER table.
The structure of these two tables will be as follows:
Table CUSTOMER
column name
characteristic
SID
Primary Key
Last_Name

First_Name

Table ORDERS
column name
characteristic
Order_ID
Primary Key
Order_Date

Customer_SID
Foreign Key
Amount

In the above example, the Customer_SID column in the ORDERS table is a foreign key pointing to the SID column in the CUSTOMER table.
Below we show examples of how to specify the foreign key when creating the ORDERS table:
MySQL: CREATE TABLE ORDERS (Order_ID integer, Order_Date date, Customer_SID integer, Amount double, Primary Key (Order_ID), Foreign Key (Customer_SID) references CUSTOMER(SID));
Oracle: CREATE TABLE ORDERS (Order_ID integer primary key, Order_Date date, Customer_SID integer references CUSTOMER(SID), Amount double);
SQL Server: CREATE TABLE ORDERS (Order_ID integer primary key, Order_Date datetime, Customer_SID integer references CUSTOMER(SID), Amount double);
Below are examples for specifying a foreign key by altering a table. This assumes that the ORDERS table has been created, and the foreign key has not yet been put in:
MySQL: ALTER TABLE ORDERS ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);
Oracle: ALTER TABLE ORDERS ADD (CONSTRAINT fk_orders1) FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);
SQL Server: ALTER TABLE ORDERS ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);

unix

TCP Dump

- dump traffic on a network

- Tcpdump prints out the headers of packets on a network
interface that match the boolean expression
- Getting TCPdump to work on a UNIX system can be a chore. TCPdump must be able to put the interface (typically an Ethernet) into promiscuous mode to read all the network traffic. Currently supported systems include SunOS, Ultrix, and most BSDs. Linux is not supported, though there have been reports of a port.
- tcpdump [ -adeflnNOpqRStuvxX ] [ -c count ]
[ -C file_size ] [ -F file ]
[ -i interface ] [ -m module ] [ -r file ]
[ -s snaplen ] [ -T type ] [ -w file ]
[ -E algo:secret ] [ expression ]



netsat -rn

Shows routing information


Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
129.155.224.0 129.155.224.18 U 1 235606 ce1
10.21.0.0 10.21.0.10 U 1 677646 ce3
224.0.0.0 129.155.224.18 U 1 0 ce1
default 129.155.224.30 UG 1 233014
127.0.0.1 127.0.0.1 UH 6285962537 lo0


DTrace

Dynamic Tracing Framework

DTrace is a major new subsystem which has been integrated into Solaris 10. It gives you the ability to easily explore all of your system from the top of the application stack to the bowels of the kernel in an intuitive way. It allows you to generate concise answers to almost arbitrary questions giving you the ability to hone in on problem areas with extreme speed.

The main components of DTrace are the probe, the provider, the consumer and the D Programming Language.
Debugging tool we Use in SUN

Radiance
Device Path Decoder
Fatal-Reset Decoder
Sub-tool
Red State Exception Decoder
ASFR Decoder
Esyn Decoder for Enterprise Servers (E3000-E6500)


File System Commands

df -k (to check amount of space in mounted filesystem)

df -h (used as above but provides “human readable” size output – not available in older solaris)

df -oi (to check amount of inodes on a filesystem)

du -k (to check files on a filesystem)

du -h (Used as above, but provide human readable size output)

du -sh (to check amount of disk space used)



Virtual Memory

Virtual memory is an addressing scheme implemented in hardware and software that allows non-contiguous memory to be addressed as if it is contiguous. The technique used by all current implementations provides two major capabilities to the system:
1. Memory can be addressed that does not currently reside in main memory and the hardware and operating system will load the required memory from auxiliary storage automatically, without any knowledge of the program addressing the memory, thus allowing a program to reference more memory than actually exists in the computer.

2. In multi tasking systems, total memory isolation, otherwise referred to as a discrete address space, can be provided to every task except the lowest level operating system. This greatly increases reliability by isolating program problems within a specific task and allowing unrelated tasks to continue to process.






UNIX commands

top (shows processes running on the system and details about the process. Useful for degraded systems)

PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
61803 sb153159 25 49 0 106M 105M sleep 145:04 1.41% jre
7652 kb207768 22 59 0 91M 91M sleep 88:28 1.16% jre
41467 rs162348 20 49 0 83M 82M sleep 7:19 0.73% jre
51473 rs162348 8 49 0 114M 103M sleep 10:29 0.46% mozilla-bin



ps (reports process status)

ps -ef ( shows current process running, often used with grep to look for a certain processes by process name or user name )

kill (terminate or signal processes)
kill -N PID, where N is a signal number and PID is the Process Identification Number

Signal number 1, a hangup signal, is recommended because it should kill the process and, if it is an editor, save the buffer. This is the default if you do not specify a signal number. Signal number 9, a kill signal, is the surest way to kill a process and is recommended only as a last resort since it will not save editor buffers.
The interrupt and quit (keystroke) signals mentioned above can be sent to a process by replacing N with 2 and 3, respectively. There are many different signals that can be sent to a process via kill. Each of them conveys slightly different information but generally causes death, whence the name of the command.


xkill (kills a gui window and all of its children)


cal
This command will print a calendar for a specified month and/or year.
To show this month's calendar, enter:
cal
To show a twelve-month calendar for 2004, enter:
cal 2004
To show a calendar for just the month of June, 1970, enter:
cal 6 1970

cat
This command outputs the contents of a text file. You can use it to read brief files or to concatenate files together.
To append file1 onto the end of file2, enter:
cat file1 >> file2
To view the contents of a file named myfile, enter:
cat myfile
Because cat displays text without pausing, its output may quickly scroll off your screen. Use the less command (described below) or an editor for reading longer text files.

cd
This command changes your current directory location. By default, your Unix login session begins in your home directory.
To switch to a subdirectory (of the current directory) named myfiles, enter:
cd myfiles
To switch to a directory named /home/dvader/empire_docs, enter:
cd /home/dvader/empire_docs
To move to the parent directory of the current directory, enter:
cd ..
To move to the root directory, enter:
cd /
To return to your home directory, enter:
cd
chmod
This command changes the permission information associated with a file. Every file (including directories, which Unix treats as files) on a Unix system is stored with records indicating who has permission to read, write, or execute the file, abbreviated as r, w, and x. These permissions are broken down for three categories of user: first, the owner of the file; second, a group with which both the user and the file may be associated; and third, all other users. These categories are abbreviated as u for owner (or user), g for group, and o for other.
To allow yourself to execute a file that you own named myfile, enter:
chmod u+x myfile
To allow anyone who has access to the directory in which myfile is stored to read or execute myfile, enter:
chmod o+rx myfile
You can view the permission settings of a file using the ls command, described below.
Note: Be careful with the chmod command. If you tamper with the directory permissions of your home directory, for example, you could lock yourself out or allow others unrestricted access to your account and its contents.

cp
This command copies a file, preserving the original and creating an identical copy. If you already have a file with the new name, cp will overwrite and destroy the duplicate. For this reason, it's safest to always add -i after the cp command, to force the system to ask for your approval before it destroys any files. The general syntax for cp is:
cp -i oldfile newfile
To copy a file named meeting1 in the directory /home/dvader/notes to your current directory, enter:
cp -i /home/dvader/notes/meeting1 .
The . (period) indicates the current directory as destination, and the -i ensures that if there is another file named meeting1 in the current directory, you will not overwrite it by accident.
To copy a file named oldfile in the current directory to the new name newfile in the mystuff subdirectory of your home directory, enter:
cp -i oldfile ~/mystuff/newfile
The ~ character (tilde) is interpreted as the path of your home directory.
Note: You must have permission to read a file in order to copy it.
df
This command reports file system disk usage, (i.e., the amount of space taken up on mounted file systems). For each mounted file system, df reports the file system device, the number of blocks used, the number of blocks available, and the directory where the file system is mounted.
To find out how much disk space is used on each file system, enter the following command:
df
If the df command is not configured to show blocks in kilobytes by default, you can issue the following command:
df -k

du
This command reports disk usage (i.e., the amount of space taken up by a group of files). The du command descends all subdirectories from the directory in which you enter the command, reporting the size of their contents, and finally reporting a total size for all the files it finds.
To find out how much disk space your files take up, switch to your home directory with the cd command, and enter:
du
The numbers reported are the sizes of the files; on different systems, these sizes will be in units of either 512 byte blocks or kilobytes. To learn which is the case, use the man command, described below. On most systems, du -k will give sizes in kilobytes.
find
The find command lists all of the files within a directory and its subdirectories that match a set of conditions. This command is most commonly used to find all of the files that have a certain name.
To find all of the files named myfile.txt in your current directory and all of its subdirectories, enter:
find . -name myfile.txt -print
To look in your current directory and its subdirectories for all of the files that end in the extension .txt, enter:
find . -name "*.txt" -print
In these examples, the . (period) represents your current directory. It can be replaced by the full pathname of another directory to search. For instance, to search for files named myfile.txt in the directory /home/user/myusername and its subdirectories, enter:
find /home/user/myusername/ -name myfile.txt -print
On some systems, omitting the final / (slash) after the directory name can cause find to fail to return any results.
As a shortcut for searching in your home directory, enter:
find "$HOME/" -name myfile.txt -print

jobs
This command reports any programs that you suspended and still have running or waiting in the background (if you had pressed Ctrl-z to suspend an editing session, for example). For a list of suspended jobs, enter:
jobs
Each job will be listed with a number; to resume a job, enter % (percent sign) followed by the number of the job. To restart job number two, for example, enter:
%2
This command is only available in the csh, bash, tcsh, and ksh shells.
kill
Use this command as a last resort to destroy any jobs or programs that you suspended and are unable to restart. Use the jobs command to see a list of suspended jobs. To kill suspended job number three, for example, enter:
kill %3
Now check the jobs command again. If the job has not been cancelled, harsher measures may be necessary. Enter:
kill -9 %3
less and more
Both less and more display the contents of a file one screen at a time, waiting for you to press the Spacebar between screens. This lets you read text without it scrolling quickly off your screen. The less utility is generally more flexible and powerful than more, but more is available on all Unix systems while less may not be.
To read the contents of a file named textfile in the current directory, enter:
less textfile
The less utility is often used for reading the output of other commands. For example, to read the output of the ls command one screen at a time, enter:
ls -la less
In both examples, you could substitute more for less with similar results. To exit either less or more, press q. To exit less after viewing the file, press q.
Note: Do not use less or more with executables (binary files), such as output files produced by compilers. Doing so will display garbage and may lock up your terminal.
lpr and lp
These commands print a file on a printer connected to the computer network. The lpr command is used on BSD systems, and the lp command is used in System V. Both commands may be used on the UITS systems.
To print a file named myfile on a printer named lp1 with lpr, enter:
lpr -Plp1 myfile
To print the same file to the same printer with lp, enter:
lp -dlp1 myfile
Note: Do not print to a printer whose name or location is unfamiliar to you.

ls
This command will list the files stored in a directory. To see a brief, multi-column list of the files in the current directory, enter:
ls
To also see "dot" files (configuration files that begin with a period, such as .login), enter:
ls -a
To see the file permissions, owners, and sizes of all files, enter:
ls -la
If the listing is long and scrolls off your screen before you can read it, combine ls with the less utility, for example:
ls -la less

man
This command displays the manual page for a particular command. If you are unsure how to use a command or want to find out all its options, you might want to try using man to view the manual page.
For example, to learn more about the ls command, enter:
man ls
To learn more about man, enter:
man man
If you are not sure of the exact command name, you can use man with the -k option to help you find the command you need. To see one line summaries of each reference page that contains the keyword you specify, enter:
man -k keyword

mkdir
This command will make a new subdirectory.
To create a subdirectory named mystuff in the current directory, enter:
mkdir mystuff
To create a subdirectory named morestuff in the existing directory named /tmp, enter:
mkdir /tmp/morestuff
Note: To make a subdirectory in a particular directory, you must have permission to write to that directory.

mv
This command will move a file. You can use mv not only to change the directory location of a file, but also to rename files. Unlike the cp command, mv will not preserve the original file.
Note: As with the cp command, you should always use -i to make sure you do not overwrite an existing file.
To rename a file named oldname in the current directory to the new name newname, enter:
mv -i oldname newname
To move a file named hw1 from a subdirectory named newhw to another subdirectory named oldhw (both subdirectories of the current directory), enter:
mv -i newhw/hw1 oldhw
If, in this last operation, you also wanted to give the file a new name, such as firsthw, you would enter:
mv -i newhw/hw1 oldhw/firsthw
ps
The ps command displays information about programs (i.e., processes) that are currently running. Entered without arguments, it lists basic information about interactive processes you own. However, it also has many options for determining what processes to display, as well as the amount of information about each. Like lp and lpr, the options available differ between BSD and System V implementations. For example, to view detailed information about all running processes, in a BSD system, you would use ps with the following arguments:
ps -alxww
To display similar information in System V, use the arguments:
ps -elf
For more information about ps refer to the ps man page on your system. Also see the Knowledge Base document In Unix, what do the output fields of the ps command mean?
pwd
This command reports the current directory path. Enter the command by itself:
pwd

rm
This command will remove (destroy) a file. You should enter this command with the -i option, so that you'll be asked to confirm each file deletion. To remove a file named junk, enter:
rm -i junk
Note: Using rm will remove a file permanently, so be sure you really want to delete a file before you use rm.
To remove a non-empty subdirectory, rm accepts the -r option. On most systems this will prompt you to confirm the removal of each file. This behavior can be prevented by adding the -f option. To remove an entire subdirectory named oldstuff and all of its contents, enter:
rm -rf oldstuff
Note: Using this command will cause rm to descend into each subdirectory within the specified subdirectory and remove all files without prompting you. Use this command with caution, as it is very easy to accidently delete important files. As a precaution, use the ls command to list the files within the subdirectory you wish to remove. To browse through a subdirectory named oldstuff, enter:
ls -R oldstuff less

rmdir
This command will remove a subdirectory. To remove a subdirectory named oldstuff, enter:
rmdir oldstuff
Note: The directory you specify for removal must be empty. To clean it out, switch to the directory and use the ls and rm commands to inspect and delete files.
set
This command displays or changes various settings and options associated with your Unix session.
To see the status of all settings, enter the command without options:
set
If the output scrolls off your screen, combine set with less:
set less
The syntax used for changing settings is different for the various kinds of Unix shells; see the man entries for set and the references listed at the end of this document for more information.
vi
This command starts the vi text editor. To edit a file named myfile in the current directory, enter:
vi myfile
The vi editor works fairly differently from other text editors. If you have not used it before, you should probably look at a tutorial, such as the Knowledge Base document How do I use the vi text editor? Another helpful document for getting started with vi is A quick reference list of vi editor commands.
The very least you need to know to start using vi is that in order to enter text, you need to switch the program from command mode to insert mode by pressing i. To navigate around the document with the cursor keys, you must switch back to command mode by pressing Esc. To execute any of the following commands, you must switch from command mode to ex mode by pressing : (the colon key): Enter w to save; wq to save and quit; q! to quit without saving.
w and who
The w and who commands are similar programs that list all users logged into the computer. If you use w, you also get a list of what they are doing. If you use who, you also get the IP numbers or computer names of the terminals they are using.

SORT- sorts ASCII files

The three most important options of Unix soft are -n (numeric keys sorting), +n (sorting using n-th field, counting from zero) and -r (sort in reverse).



Sed

Sed is the ultimate stream editor. If that sounds strange, picture a stream flowing through a pipe

AWK

awk is a programming language designed to search for, match patterns, and perform actions on files. awk programs are generally quite small, and are interpreted. This makes it a good language for prototyping.

awk scans input lines one after the other, searching each line to see if it matches a set of patterns or conditions specified in the awk program.
For each pattern, an action is specified. The action is performed when the pattern matches that of the input line.
Thus, an awk program consists of a number of patterns and associated actions. Actions are enclosed using curly braces, and separated using semi-colons.

pattern { action }
pattern { action }

what is the use of /log or /bin or /usr folder?

The directory structure of a typical UNIX system is
/ root directory
/bin Unix utilities
/dev special devices
/etc administrative programs and tables
/lib language libraries
/tmp temporary files
/usr user sub-directory area
/usr/bin Unix utilities
/usr/include include files used by language processors
/usr/lib archive libraries, text processing macros
/usr/news news
/usr/spool spool files for printing
/usr/tmp temporary files
AFS:

AFS is a distributed file system. It uses the client/server model,
where all the files are stored on file server machines. Files are
transferred to client machines as necessary and cached on local disk.
The server part of AFS is called the AFS File Server, and the client
part of AFS is called the AFS Cache Manager. AFS provides Access
Control Lists (ACLs) which provide for more control and flexibility
than standard UNIX file permissions.




Ps not found

Refresh path variable in pre and post scripts, so you can use all the unix commands
export PATH=$PATH:/usr/bin:/usr/sbin/


Extended Post

An extended boot is also know as a diagnostic boot.

You go to the OBP also known as the OK> prompt and change some variables
to do extended diagnostics when the system reboots.

At the OK> prompt you need to do the following commands:

setenv diag-level max
setenv diag-switch? true
setenv auto-boot? false
Some people will do the commmand reset-all at this point.

Or you can use the command
power-off


Diamond Operator (<>) in Perl

Another way to read input is with the diamond operator: <>. This works like in that it returns a single line in a scalar context (undef if all the lines have been read) or all remaining lines if used in a list context. However, unlike , the diamond operator gets its data from the file or files specified on the command line that invoked the Perl program. For example, you have a program named kitty, consisting of
#!/usr/bin/perl
while (<>) {
print $_;
}
and you invoke kitty with
kitty file1 file2 file3
then the diamond operator reads each line of file1 followed by each line of file2 and file3 in turn, returning undef only when all of the lines have been read. As you can see, kitty works a little like the UNIX command cat, sending all the lines of the named files to standard output in sequence. If, like cat, you don't specify any filenames on the command line, the diamond operator reads from standard input automatically.
Technically, the diamond operator isn't looking literally at the command-line arguments; it works from the @ARGV array. This array is a special array initialized by the Perl interpreter to the command-line arguments. Each command-line argument goes into a separate element of the @ARGV array. You can interpret this list any way you want.[2] You can even set this array within your program and have the diamond operator work on that new list rather than the command-line arguments, like so:
@ARGV = ("aaa","bbb","ccc");
while (<>) { # process files aaa, bbb, and ccc
print "this line is: $_";
}


JAVA

What is Object-oriented programming



A type of programming in which programmers define not only the data type of a data structure, but also the types of operations (functions) that can be applied to the data structure. In this way, the data structure becomes an object that includes both data and functions. In addition, programmers can create relationships between one object and another. For example, objects can inherit characteristics from other objects.
One of the principal advantages of object-oriented programming techniques over procedural programming techniques is that they enable programmers to create modules that do not need to be changed when a new type of object is added. A programmer can simply create a new object that inherits many of its features from existing objects. This makes object-oriented programs easier to modify.
To perform object-oriented programming, one needs an object-oriented programming language (OOPL). Java, C++ and Smalltalk are three of the more popular languages, and there are also object-oriented versions of Pascal.

What's the difference between the methods sleep() and wait()
A. The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.





SQL Questions

Select - extracts data from a database table
Select LastName, FirstName from PERSONS
To check the content of a table: SELECT * from TableName

Join – Joins two tables with a common factor
Insert Into - inserts new data into a database table
INSERT INTO Persons
VALUES ('Hetland', 'Camilla', 'Hagabakka 24', 'Sandnes')
Delete - deletes rows from a database table

DELETE FROM table_name
WHERE column_name = some_value

DELETE from PERSONS where LastName = 'Nina'

Update - updates data in a database table
UPDATE table_name
SET column_name = new_value
WHERE column_name = some_value
UPDATE Person SET FirstName = 'Nina'
WHERE LastName = 'Rasmussen'
ORDER BY - The ORDER BY clause is used to sort the rows.
SELECT Company, OrderNumber FROM Orders
ORDER BY Company
MAX function - The MAX function returns the maximum value of an expression.
For example, you might wish to know the maximum salary of all employees.
SELECT MAX(salary) as "Highest salary" FROM employees;
CREATE TABLE - creates a new database table
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
.......
)


· ALTER TABLE - alters (changes) a database table
· DROP TABLE - deletes a database table
· CREATE INDEX - creates an index (search key)
· DROP INDEX- deletes an index

probe-scsi-all

The probe-scsi-all is a bootprom command that is not available in the Solaris operating enviroment. To use it, you must be at the ok prompt. To access this prompt, you must be consoled into the computer through a serial interface or the RSC (remote system control) card, if present.

Steps:
os# Sync; sync; init 0
ok> setenv auto-boot? False
ok> reset-all
ok> probe-scsi-all

The output of this command will show you all of the SCSI devices that the host system can see and their device paths, for example: /pci@1f,2000/scsi@1 Target 0 Unit 0 Removable Tape QUANTUM DLT7000 2150 Target 1 Unit 0 Removable Device type 8 HP C6280-7000 2.00 Before you reboot your system, you must reset the auto-boot? variable to true:

NETCOOL

Netcool/Impact is a set of runnable server components that work together to provide event management and integration functionality for the Netcool suite of products.
From a software perspective, you can best understand Netcool/Impact as a set of interrelated, runnable server components, each of which must be installed and configured separately. These components are:
· Netcool/Impact Server
· Netcool Security Manager
· Netcool GUI Server
· Netcool Common License Server


AutoSys

AutoSys is an application by Computer Associates that is used in large Enterprises for cross platform job scheduling.
Unicenter AutoSys Job Management is an industry-leading job management system that supports enterprise-wide mission-critical applications. Designed for distributed environments, it delivers event-driven scheduling, centralized real-time monitoring and programmable error recovery — all providing the reliability and scalability your production environment needs. In addition, it easily accommodates the massive processing of jobs required by eBusiness, thus providing rapid Internet job management.