Vous êtes sur la page 1sur 7

Jasjeet singh anand

Roll no 14

Q1. How to plan a good database? Using both SQL server


Management studio and T- SQL create a database using SQL
server 2005.

Ans The definition of a good database is relative to the requirements of


each customer because every situation is different. A good database is
determined as seen through the eyes of the customer, the end user, the
database administration team, and management. If all parties are happy
with the database, the allocation of resources to design a new database
might be unnecessary. On the other hand, if some of the parties involved
are unhappy about a few things, it might be worthwhile to begin designing a
new database. Keep in mind that there might not be an existing database in
place. If a database is not currently in use, it is still important to understand
the key principles of a "good" database before thinking about designing
one. The information is the meaning that we allocate to the data. For
example, a ten percent salary decrease is a piece of data. For the
employee, this is a bad thing (information), while for the boss it can be a
good thing (also information).

The most common, including:

Data storage needs having been met


Data is readily available to the end-user
Data being protected through database security
Data being accurate and easy to manage.

Database using SQL server 2005

When you launch SQL Server Management Studio, you are shown the
normal “Connect to Server” dialog. First, you need to change the Server
Type to “SQL Server Compact Edition”. Now in the Database File area, click
on the drop down and pick “<New Database…>”.
One of the supported types of analysis by SQL Enlight is the T-SQL script
analysis. It can be used validating the code for syntax errors as well as for
conforming to best practices or your own standards and requirements.

How to create using T-sql

As databases get bigger, the number of database objects increase and the
amount of business logic implemented using T-SQL code becomes quite
substantial, often even more critical than the application code; the
automation of the process of ensuring code quality is becoming more and
more important.
Static code analysis is a popular method for code verification and defect
detection in the .NET, C++ and Java development worlds, but very often left
behind and neglected by the SQL Server development community.SQL
Enlight is a tool for SQL Server that can automate and facilitate the T-SQL
code and database schema analysis. The tool works in a way similar to
the .NET focused tools like FxCop and StyleCop. It provides design-time
code, database schema and query plan analysis. The tool comes with about
70 out of the box analysis rules and also supports custom analysis rules.

T-SQL code aspects that can be checked are:

Deprecated syntax (old outer joins, IMAGE and TEXT data types, deprecated
stored procedures usage and etc.)

Naming conventions ( ‘sp_’ prefix, special characters or reserved keywords


in object names)
Not recommended statements, expressions and operators that can impact
maintenance, produce unwanted results or have a good chance to be
written by mistake.
Statements, expressions and operators that may have impact on the query
performance

Q2. Create a table showing all the constraints of SQL Server 2005.
How can we set ‘schedule properties’ in SQL Server agent . Justify
your answer with suitable example.

Ans The following example creates a check_sale CHECK constraint


on an employee table:

CREATE TABLE employee(


EmployeeId INT NOT NULL,
LName VARCHAR(30) NOT NULL,
FName VARCHAR(30) NOT NULL,
Address VARCHAR(100) NOT NULL,
HireDate DATETIME NOT NULL,
Salary MONEY NOT NULL CONSTRAINT check_sale CHECK (salary > 0)
)

You can add constraints to an existing table by using the ALTER TABLE
statement. The following example adds a pk_employee primary key
constraint on an employee table:

ALTER TABLE employee

ADD CONSTRAINT pk_employee PRIMARY KEY (EmployeeId)


You can add the primary or unique key constraint into an existing table only
when there are no duplicate rows in the table. You can drop constraints in
an existing table by using the ALTER TABLE statement.

Example drops the pk_employee primary key constraint in the


employee table:

ALTER TABLE employee.


DROP CONSTRAINT pk_employee.

Q3. Create a temporary table for storing results of mathematical


functions?

Ans Create table temp

Select floor (-28.5)

Select abs(-49)

Select ceil(-59.8)

Select * from temp

Go

Output

29

49

59

Q4. How can we modify the structure of a table? Can we add or


remove attributes from a table after its creation?

Ans Once a table is created in the database, there are many occasions
where one may wish to change the structure of the table. Yes we add or
remove attributes from a table after its creation In general,we can do
through ALTER TABLE command

ALTER TABLE "table_name"

Alter specification
Alter specification is dependent on the type of alteration we wish to
perform. We list a number of common changes below:

Sometimes we need to change the data type of a column. To do this, we


use the ALTER TABLE Modify Column command. For Oracle and MySQL, the
SQL syntax for ALTER TABLE Modify Column is,

ALTER TABLE "table_name"


MODIFY "column 1" "New Data Type"
For SQL Server, the syntax is,
ALTER TABLE "table_name"
ALTER COLUMN "column 1" "New Data Type".

Data
Name
Type
First_Na
char(50)
me
Last_Nam
char(50)
e
Address char(50)
City char(50)
Country char(25)
Birth_Dat
Date
e

Name Data Type


First_Name char(50)
Last_Name char(50)
Address char(50)
City char(50)
Country char(25)
Birth_Date Date

Our goal is to alter the data type of the "Address" column to char(100). To
do this, we key in:
Resulting table structure:

Table customer

Column Name Data Type


First_Name char(50)
Last_Name char(50)
Address char(100)
City char(50)
Country char(25)

Column Data
Name Type
First_Name char(50)
Last_Name char(50)
char(100
Address
)
City char(50)
Country char(25)

Q5. How can we modify data of a table? Give details to implement


manual job execution in SQL server agent.

Ans Modify data of a table

Suppose we want to change data in a single MySQL table cell. In order to


achieve this you need to know the name of the column that contains the
cell, the row number, or some trait that can uniquely identify that cell.
Normally, a complete row in a MySQL table is a complete record and this
record is distinguished by a unique record ID, let is say, “rec_id”. Suppose
the cell you want to change belongs to rec_id 678 and the name of the cell
is “first_name”. Let the MySQL table be “students”. This is how you change
the first_name:

update students set first_name=’Suba’ where rec_id=678;

Creating a SQL Server Agent Job

1. From the "SQL Server Agent" node, right click on the "Jobs" node, and
select "New Job":

2. Complete the details in the "General" tab:

3. Complete the details in the "General" tab:

4. From the "Steps" tab, click "New"


5. Complete the details for this step. In this example, we are using the
dtsrun utility to execute a DTS package:

6. From the "Schedules" tab, click "New Schedule"


7. Give this schedule a name and specify the schedule type:

8. If you need to set a recurring schedule, click "Change" (from the previous
screen).

Modifying your SQL Agent Job


You can view your SQL Agent Job under the "Jobs" node. If you need to
modify your SQL Agent Job, you can do so by right clicking on the job, then
selecting "Properties". You can also run your job (by selecting "Start Job"),
view its history, disable it, and more.

Implementation of manual job execution in SQL server agent

To know under which security context your job step will be run, go ahead
and read the following:

The job step is a T-SQL


If the job owner is an account that is in the sysadmin fixed server role, than
your step will be executed under the account used by the Sql Server Agent
service.
Otherwise will be executed by the account set as the job owner, no matter
who is starting the job.

The job step is a CmdExec or ActiveXScript job step

If the job owner is an account that is in the sysadmin fixed server role, than
your step will be executed under the account used by the Sql Server Agent
service.
Otherwise the step will be executed under the security account of the Proxy
Account if enabled and configured (look under Sql Server Agent properties,
Job System tab). If that proxy account is not configured the step will fail.

Be advised that when you schedule a DTS Package the job step that will run
that package is a CmdExec step. So pay attention when you use the
Integrated Authentication in your DTS Packages since when the DTS will be
run from the job, the account used depends from the job owner as stated
above....and so you may find that if run manually your DTS works perfectly
(since uses *your* account credentials), while running it from the job will
bring you a failure.

Q6. Create two tables studentMaster and StudentDetail with


Primary key and foreign key constraints. Design Data diagram of
these two tables showing relationship between them.

Ans create table studentMaster(student_name(15),student_ID


varchar(15)primary key,class varchar(9));
insert into studentMaster values (‘paras’,1011,'Mca');
insert into studentMaster values (‘jassi’,1012,'Mca');
insert into studentMaster values (‘rana’,1013,'Mca');
create table stuDentDetail(student_ID varchar(10) foreign key references
studentMaster(student_ID),stu_address varchar(50) );
select*from studentMaster;
insert into stuDentDetail values (’delhi');
insert into stuDentDetail values (‘up');
insert into stuDentDetail values ('bihar');

select*from stuDentTable;

Vous aimerez peut-être aussi