Basic Structured Queru Language
Basic Structured Queru Language
Basic Structured Queru Language
STEP 2: Double click on the setup.exe file. After a few seconds a dialog box appears:
This will disappear from the screen and then the main installation page appears:
STEP 4 : Click on the "New Server stand-alone installation" link on the right side of the
screen:
The following dialog appears on the screen whilst the install program prepares for installation:
After a minute or so (the timing will vary according to your system), the following screen
appears:
STEP 9: Setup Support Rules. If all is well, the following screen appears:
For most installations, keep the default settings. Click on the Next button.
Click on Next.
STEP 13: Server Configuration. This step allows you to set up the service accounts that will be
used to run SQL Server. If you have created Windows NT or Active Directory accounts for use
with services, use these.
If not, then just to get the installation up and working, use the built-in Network Service account
for all three services listed (this account does not require a password).
This allows SQL Server to start up after installation. However, it can be easily changed later to
another account through the Services applet (Control Panel -> Administrator Tools -> Services):
Change the Authentication Mode to Mixed Mode unless you are certain you only need
Windows-only authentication.
Many third party applications rely on SQL Server logins to operate correctly, so if
you are setting up a server for a third party application, rather than one developed
in-house, enabling Mixed Mode authentication is a good idea.
If you pick Mixed Mode security, you must also enter a password for the sysadmin account (sa).
Enter and confirm a secure password for the sa account and keep it somewhere safe.
Note that you MUST also provide a Windows NT account on the local machine as a SQL Server
administrator. If you do not want Windows system administrators to be able walk up to the box
and login to SQL Server, create a new, local, dummy Windows user and add this account
Change the directories to specify which drives in your system will be used for the various types
of database files.
Generally it’s advisable to put the User database directory and User log directory on separate
physical drives for performance, but it will depend on how Windows has been configured and
how many disk drives you have available.
If you are installing on a single drive laptop or desktop, then simply specify:
Data root directory C:\Program Files\Microsoft SQL Server
User database
C:\Data
directory
User log directory C:\Logs
Temp DB directory C:\TempDB
Temp Log
C:\TempDB
directory
Backup directory C:\Backups
Click boxes if you want to help Microsoft help you. Click on Next again…
STEP 16: Installation Rules
This screen simply checks if there are any processes or other installations running which will
stop the installation of SQL Server 2008.
…followed by:
It may be worth clicking on the installation log at the top of the screen to check everything’s
gone as expected. Not that this is MUCH smaller than the usual SQL Server installation log files
of old.
Finally, click on the Close button. The following dialog will appear:
Check 2: Does Management Studio Work? Check Management Studio works by firing it up.
- To create the database by accepting all default values, click OK; otherwise, continue with
the following optional steps.
. Deleting a database
You can delete database by executing the DROP DATABASE statement.
Example: DROP DATABASE <database name>
Exercises: 1. Create a database called library.
2. Delete the database that you have already created.
The INSERT statement allows the user to specify explicit attribute names that correspond to the
values provided in the INSERT command. This is useful if a relation has many attributes.
Syntax: Insert into<TABLE_NAME>(column1,column2,column3)
values('value1'<for_column 1>,'value2'<for_column 2>'value
3'<for_column 3);
- The SET clause is used to assign new values to one or more columns.
- The search condition (WHERE clause) specifies which rows in the table are to be updated.
If no search condition is specified, all rows will be updated.
Example: UPDATE PROJECT
SET PLOCATION = 'Tana beles', DNUM = 5
WHERE PNUMBER=10;
Updating a primary key value may propagate to the foreign key values of records in other
relations if such a referential triggered action is specified in the referential integrity constraints.
How you update a table name without affecting stored values in the table?
sp_RENAME 'OldTable_name','Newtable_name'
Note: - The SELECT INTO statement selects data from one table and inserts it into a different
table.
- The SELECT INTO statement is most often used to create backup copies of tables.
1.6. Combining table Expressions
With the help of set operators, the results of individual table expressions can be combined. This
type of combination is called UNION. SQL supports other set operators besides the UNION
operator.
Here is the complete list:
UNION
UNION ALL
INTERSECT
INTERSECT ALL
EXCEPT
EXCEPT ALL
Note: The UNION operator selects only distinct values by default. To allow duplicate values,
use UNION ALL.
1.8. Rules for using UNION
If two table expressions are combined with the UNION ALL operator, the end result consists of the
resulting rows from both of the table expressions. The only difference between UNION and UNION
ALL is that when you use UNION, the duplicate rows are automatically removed, and when you
use UNION ALL, they are kept.
1.12. Set operators and NULL values
SQL automatically removes duplicate rows from the result if the set operators UNION,
INTERSECT, and EXCEPT are specified. That is why the following (somewhat peculiar) SELECT
statement produces only one row, even if both individual table expressions have one row as their
intermediate result:
SELECT PLAYERNO, LEAGUENO
FROM PLAYERS
having clause
Use the HAVING clause on columns or expressions to set conditions on the groups included in a
result set.
The HAVING clause sets conditions on the GROUP BY clause in much the same way that the
WHERE clauses interacts with the SELECT statement.
Example: SELECT dnum ,count(*)'number of employee' FROM EMPLOYEE
WHERE exists (SELECT dname FROM DEPARTEMENT
WHERE EMPLOYEE.Dnum =DEPARTEMENT.Dnumber)
group by Dnum
having COUNT(*)>2
4.4. Correlated subqueries
In a SQL database query, a correlated sub-query (also known as a synchronized subquery) is a
sub-query (a query nested inside another query) that uses values from the outer query in its
WHERE clause.
- Correlated subquery is one that is executed after the outer query is executed. So
correlated subqueries take an approach opposite to that of the normal subqueries.
- In a correlated subquery, the inner query uses information from the outer query and
executes once for every row in the outer query.
- A practical use of a correlated subquery is to transfer data from one table to another.
Syntax for correlated subquery: select column_list from table_name a