Skip to main content

Posts

Showing posts from April, 2014

COL_LENGTH

Returns defined length in bytes of column. SYNTAX: Select (‘tablename’,’Columnname’) CREATE TABLE Tbl_emp (  ID INT IDENTITY ( 1 , 1 ) PRIMARY KEY ,  Name VARCHAR ( 50 ),  Department NVARCHAR ( 50 ) ) Example -1: SELECT   COL_LENGTH ( 'Tbl_emp' , 'Name' ) AS ColLength Example -2: SELECT   COL_LENGTH ( 'Tbl_emp' , 'Department' ) AS ColLength Example -3: SELECT   COL_LENGTH ( 'Tbl_emp' , 'Address' ) AS ColLength In above example 3 null value is returned .beacuase of Address column does not belongs to Tbl_emp table.

Relational Data Base Manangement System

DBMS: Ø   DBMS stands for Data base management system. Ø   DBMS is a set of programs in an operating system that creates and maintains a database. Ø   Allow user to store and restive data from database. (Data base management system) RDBMS: Ø   RDBMS stands for Relational for Data base management system. Ø   In Relational data base management system everything is maintained in table format. Ø   Now a day’s relational database management system is most powerful. Ø   In Relational database management system maintains relationship between among the tables. Ø   Relational database management system is developed by Dr.E.F Codd in 1970 . Ø   In picture demonstrates about a relational model. In relational database management system every data is stores in table. Ø   A table is combination of rows and columns . Ø   In relational database management system each Row is called as Tuple . Ø   In r...

Bulk Insert

IF   OBJECT_ID ( 'Employee' , 'U' )   IS   NOT   NULL DROP   TABLE  Employee Ceating the Emlployee table CREATE   TABLE  Employee (   NAME  VARCHAR ( 20 ),   SALARY  INT ) I alredy created the txt file with folliwing path and data  “E:\BulkInsert.txt”   rakesh,5000 madhu,6000 ali,7000 Run the script BULK INSERT  Employee FROM   'D:\BulkInsert.txt' WITH ( FIELDTERMINATOR   =   ',' , ROWTERMINATOR   =   '\n' ) (3 row(s) affected) FIELDTERMINATOR: In above text file each field  is separated with (,) comma . ROWTERMINATOR: In above text file each row is teminated    with (\n) new line charachter  SELECT   *   FROM  Employee .

How to insert values into IDENTITY column

Identity columns commonly used as primary keys in tables. These columns are automatically values are assigned when ever new record inserted into a table. IF OBJECT_ID ( 'Employee' , 'U' ) IS NOT NULL DROP TABLE Employee Ceating the Emlployee table CREATE TABLE Employee (   ID INT IDENTITY ( 1 , 1 ) PRIMARY KEY ,   NAME VARCHAR ( 20 ),   SALARY INT ) INSERT INTO Employee SELECT 'Rakesh' , 5000 UNION ALL SELECT 'Ramu' , 6000 UNION ALL SELECT 'Naresh' , 7000 SELECT * FROM Employee In below scenario trying to insert value into identity column. INSERT INTO Employee ( ID , NAME , SALARY ) VALUES ( 4 , 'Sravan' , 10000 ) When ever tring to insert value into idenity column  of ID we get follwing follwing error. Msg 544, Level 16, State 1, Line 1 Cannot insert explicit value for identity column in table 'Employee' when IDENT...

Stuff function

Stuff function is used for delete certain length of string to another string. Syntax: Select (expression varchar, starting_postion int , number_of_chars int, expression varchar) Example:  SELECT STUFF ( 'Microsft Sql Server' , 10 , 4 , 'Integration' ) Output: Microsft Integration Server                                                      Happy Coding !!

Coalesce function

Coalesce function returns the first non-null value among the arguments. Syntax: Coalesce (expression [,..n]) Here is example using Coalesce function Example 1 DECLARE @Str1 varchar ( 10 ), @str2 varchar ( 20 ), @Str3 varchar ( 20 ) SET @Str2 = 'Sql' , @Str3 = 'Server' SELECT COALESCE ( @Str1 , @str2 , @Str3 ) As [Coalesce] In above example @Str2 value is ‘Sql’ , @str3 value is ‘Server’  and @str1 values is Null because it not assigned any value . Output: It return’s “Sql” because Coalesce function return’s first non null value. Example 2: Coalesce in select statement. IF OBJECT_ID ( 'Employee' , 'U' ) IS NOT NULL DROP TABLE Employee CREATE TABLE Employee (   ID INT IDENTITY ( 1 , 1 ) PRIMARY KEY ,   NAME VARCHAR ( 20 ),   SALARY INT ) INSERT INTO Employee   ( NAME , SALARY ) VALUES ( 'Rakesh' , 5000 ),(NULL, 6000 ),( 'Naresh...