Skip to main content

Posts

Showing posts from May, 2014

IDENTITY COLUMNS

Identity column specifies when ever new value is inserted into table. Identity column automatically inserted value into column. Identity Column can be specified at the time of creation of table. CREATE TABLE Employee (  EMPID INT IDENTITY ( 1 , 1 ),  EMPNAME VARCHAR ( 50 ),  SALARY INT ) In above table creation script EMPID column specifies IDENTITY property i.e., whenever a new row inserted into a Employee table EMPID Column will automatically value is inserted. INSERT INTO Employee ( EMPNAME , SALARY ) VALUES ( 'RAKESH' , 7000 ) INSERT INTO Employee ( EMPNAME , SALARY ) VALUES ( 'ALI' , 12000 ) SELECT * FROM Employee When u run above select statement is the following result is if u are trying insert value into identify columns .it will give error. INSERT INTO Employee ( EMPID , EMPNAME , SALARY ) VALUES ( 1 , 'RAKESH' , 7000 ) Msg 5...

INFORMATION_SCHEMA.TABLES

--Script for list of tables in database SELECT * FROM INFORMATION_SCHEMA . TABLES WHERE TABLE_TYPE = 'BASE TABLE' --Script for list of tables count in database SELECT   COUNT (*) FROM INFORMATION_SCHEMA . TABLES WHERE TABLE_TYPE = 'BASE TABLE' --Script for list of tables particular schema level SELECT * FROM INFORMATION_SCHEMA . TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'dbo'

UNION AND UNION ALL OPERATORS

Union and union all is in sql server used to combining the result sets of two or more select statements. I have created the two tables with the following data Create Student_A Table CREATE TABLE Student_A (  ID INT IDENTITY ( 1 , 1 ),  NAME VARCHAR ( 10 ),  MARKS INT ) Inserting the data into Student_A table INSERT INTO Student_A ( NAME , MARKS ) VALUES ( 'Dave' , 500 ) INSERT INTO Student_A ( NAME , MARKS ) VALUES ( 'Rakesh' , 400 ) INSERT INTO Student_A ( NAME , MARKS ) VALUES ( 'Ramu' , 300 ) Create Student_B Table  CREATE TABLE Student_B (  ID INT IDENTITY ( 1 , 1 ),  NAME VARCHAR ( 10 ),  MARKS INT ) Inserting the data into Student_B table INSERT INTO   Student_B ( NAME , MARKS ) VALUES ( 'Dave' , 500 ) INSERT INTO Student_B ( NAME , MARKS ) VALUES ( 'Raju' , 300 ) INSERT INTO Student_B ( NAME , MARKS ) VALUES ( 'Nani' , 350 ) Selecti...

PRIMARY KEY CONSTRAINT WHEN TABLE CREATING

1.     Primary key is a filed in a table which uniquely identifies each row / record. 2.     When we create primary key on columns it follows two conditions. A.     Primary key column is uniquely identifies each row / record. B.     Primary key column not allow NULL values. Column level : CREATE TABLE Tbl_emp_Pk (   ID INT PRIMARY KEY ,   NAME VARCHAR ( 10 ),   SALARY INT NOT NULL ) Table level : CREATE TABLE Tbl_emp_Pk (    ID INT ,   NAME VARCHAR ( 10 ),   SALARY INT NOT NULL   CONSTRAINT pk_ID PRIMARY KEY ( ID ) ) To check list of primary key constraints SELECT * FROM SYS . KEY_CONSTRAINTS   WHERE   type = 'PK' Here inserting the some sample data INSERT INTO Tbl_emp_Pk ( ID , NAME , SALARY ) VALUES ( 1 , 'Rakesh' , 7000 ) INSERT INTO Tbl_emp_Pk ( ID , NAME , SALARY ) VALU...

ISDATE FUNCTION

ISDATE function is determines whether the input expression is valid date. Syntax: ISDATE (Expression) Returns: ISDATE function returns integer value. 1- Returns the weather input expression is valid date or time. 0- Returns the weather input expression is not valid date or time. Example -1 SELECT ISDATE ( GETDATE ()) AS [ISDATE] Output: In above example returns 1 because Getdate is valid date. Example -2 SELECT ISDATE ( 'SQL SERVER' ) AS [ISDATE] Output: In above example returns 0 because not valid date.

HOW TO FIND SOME VALUE IN STORED PROCEDURE TEXT

METHOD-1: SELECT SO . name AS [ProcName] , SC . text AS [Text] FROM SYS . OBJECTS SO JOIN SYSCOMMENTS SC ON SO . object_id = SC . id WHERE TYPE = 'P' and [text] like '%SearchValue%' METHOD-2: SELECT name AS [ProcName] , OBJECT_DEFINITION ( object_id ) AS [Text] FROM SYS . OBJECTS WHERE TYPE = 'P' AND OBJECT_DEFINITION ( object_id ) LIKE '%SearchValue%'