Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, September 17, 2011

Add / REMOVE Primary Key to existing table


CREATE TABLE WITHOUT PRIMARY KEY

CREATE TABLE JSSTUDTABLE (SNO NUMERIC(10) NOT NULL)

ADD PRIMARY KEY EXISTING TABLE

ALTER TABLE JSSTUDTABLE ADD  PRIMARY KEY (SNO);

REMOVE PRIMARY KEY EXISTING TABLE 

ALTER TABLE JSSTUDTABLE DROP  constraint  PK__JSSTUDTA__CA1EE06C63D8CE75

Thursday, September 8, 2011

“ COALESCE “ Method in Sql Server


 “ COALESCE “  Method in Sql Server
Table Have so many column like that
Name
HomeAddress
OfficeAddress
Temp_Address
Suthahar
Null
Null
Pudukkottai
Suresh
Pullanviduthi
Null
Null
Sumathi
Null
Alangudi
Null
Sujatha
Pullanviduthi
Pudukkottai
Trichy

If someone have home address or office address suppose if you display available first record means you can use coalesce method
CREATE TABLE devenvexe(Name  nvarchar(10),homeaddress nvarchar(10),officeaddress nvarchar(10), Temp_addressnvarchar(10))

Query :
SELECT name,COALESCE(homeaddree,officeaddress,temp_address) Addreess FROM devenvexe
Output:
Name
Address
Sutahhar
Pudukkottai
Suresh
Pullanviduthi
Sumathi
Alangudi
Sujatha
Pullanviduthi


Concatinate Column in Single Column

CREATE TABLE JS(SNAME NVARCHAR(10))

INSERT INTO JS VALUES('SUTHAHAR')
INSERT INTO JS VALUES('SURESH')
INSERT INTO JS VALUES('SUMATHI')
INSERT INTO JS VALUES('SUJATHA')


DECLARE @VAL NVARCHAR(1024)

SELECT @VAL=COALESCE(@VAL+',', '')+ SNAME FROM JS

SELECT JS= @VAL

Output:
Suthahar,Suresh,Sumathi,Sujatha

Sunday, May 15, 2011

View in Sql Server


View in Sql Server
  • ·        View is a virtual table
  • ·        It s contains columns and data in different table
  • ·        View does not contain any data directly. Its a set of select query
Table 1

Sno
Sname
Table 2
Sno
Lname

                              
View_table1_table2

Sname
Lname

Above drawing table 1 and table we will write join query after we can create view
Syntax
CREATE VIEW JS_VIEW_NAME
AS
[SELECT STATEMENT]
Why we are use View ?
·        View is used for security mechanism .if you restricted particular column for users .
Sql Server Syntex for View
CREATE VIEW
CREATE VIEW JS_VIEW
AS
SELECT *FROM STUD A,LIB L WHERE A.SNO=L.SON
ALTER VIEW
ALTER VIEW JS_VIEW
AS
SELECT *FROM STUDENTTABLE  A,LIB L WHERE A.SNO=L.SON

SELECT VIEW
SELECT*FROM JS_VIEW
DROP VIEW:
DROP VIEW JS_VIEW        

Trigger Interview Questions

How many types of triggers are there in Sql Server 2005?
There are two types of triggers
• Data Manipulation language (DML) triggers
• Data Definition language (DDL) triggers
DML triggers (implementation) will run when INSERT, UPDATE, or DELETE statements modify data in a specified table or view.
DDL triggers will run in response to DDL events that occur on the server such as creating, altering, or dropping an object, are used for database administration tasks
What are the different modes of firing triggers?
After Trigger: An AFTER trigger fires after SQL Server completes all actions successfully
Instead of Triggers: An INSTEAD OF trigger causes SQL Server to execute the code in the trigger instead of the operation that caused the trigger to fire.

Trigger In Sql Server


Trigger In Sql Server
·        Trigger is a special kind of Store procedure
·        Modifications to the table are made using INSERT,UPDATE OR DELETE  trigger will run
·        It is automatically run
·        Triggers prevent incorrect , unauthorized, or inconsistent changes to data.

Syntax in Trigger:

CREATE TRIGGER trigger_name ON table_name

FOR [INSERT/UPDATE/DELETE] AS

IF UPDATE(column_name)

[{AND/OR} UPDATE(COLUMN_NAME)...]

{ sql_statements }

Trigger Rules:

·        A table can have only three triggers action per table : UPDATE ,INSERT,DELETE.
·        Only table owners can create and drop triggers for the table.This permission cannot be transferred.
·        A trigger cannot be created on a view or a temporary table but triggers can reference them.
·        They can be used to help ensure the relational integrity of database.On dropping a table all triggers associated to the triggers are automatically dropped .

INSERT TRIGGER
·        When an INSERT trigger statement is executed ,new rows are added to the trigger table and to the inserted table at the same time.
·        The inserted table allows to compare the INSERTED rows in the table to the rows in the inserted table.
 DELETE TRIGGER
·        When a DELETE trigger statement is executed ,rows are deleted from the table and are placed in a special table called deleted table.
UPDATE TRIGGER
When an UPDATE statement is executed on a table that has an UPDATE trigger,

Wednesday, April 27, 2011

Avoid Temp Table use Table Data Type

Avoid Temp Table use Table Data Type
Micrsoft indroduced table data type in sql server altenative to using temporary  table
Table variables store a set of records, so naturally the declaration syntax looks very similar to a CREATE TABLE statement, as you can see in the following example:
DECLARE @Student TABLE
{
SNO INT ,SNAME NVARCAHR
}
IF YOU WANT INSERT RECORD
INSERT INTO  @ Student VALUES(2,’JSSUTHHAAR’)

OR
INSERT INTO @Student SELECT SNO,SNAME FROM STUDENT

List Of Table Name In Sql Server

List Of Table Name In Sql Server

SELECT *FROM INFORMATION_SCHEMA.TABLESWHERE

Or


 SELECT [name]FROM sys.tables;
table_type = 'BASE TABLE'