Ms SQL Notes
Ms SQL Notes
Ms SQL Notes
nVARCHAR(50)
nVARCHAR(20) Float
nVARCHAR(20)
Delete Value
Delete From Employee Where [Name]=abc
Update Values
Update [Employee] Set [Name]=Lucky where [Employee Id]=2
Record Find
c
Add Column
Add [D O B] SmallDateTime
Delete Column
Alter Table [Employee]
-------------------------------------------------------------------------------------------------------------------
Select [Employee].[Emp id],[Employee].[Emp Name], [Employee Account]. [Salary] From [Employee] (first Table)
Inner Join [Employee Account] (Second Table) On [Employee].[Emp Id]=[Employee account].[Emp id] (column its same ,because give primary key)
Select [Employee].[Emp id],[Employee].[Emp Name], [Employee Account]. [Salary] From [Employee](first Table) , [Employee Account] (Second Table) where [Employee].[Emp Id]=[Employee account].[Emp id] (column its same ,because give primary key)
While joining any two table and to see a table in sequence order we use a key word order by .by this our entries in table will appear in an order..
Exp: Select [Employee].[Emp id],[Employee].[Emp Name], [Employee Account]. [Salary] From [Employee] (first Table),
[Employee Account] (Second Table) Where [Employee].[Emp Id]=[Employee account].[Emp id] Order by [employee].[emp id]
SUM () FUNCTION
The SUM() function returns the total sum of a numeric column. EXP: Select SUM(AMOUNT) FROM [SALE DETAIL}
DB-TABLE NAME
DB STANDS FOR DATABASE ,DB-TABLE NAME IS A DATABASE TABLE NAME IN WHICH OUR ENTRIES ARE STORED ..FOR A PARTICULAR TABLE ENTRY.AND EASY IN FINDING ENTRY IN DATABASE
DECLARE SALE_BILL CURSOR FOR SELECT BILLNO, BILLDATE FROM SALE ORDER BY BILLDATE
OPEN SALE_BILL
-- Perform the first fetch and store the values in variables. -- Note: The variables are in the same order as the columns -- in the SELECT statement.
UNION COMMAND
IT COMBINES DIFFERENT COLUMNS INTO ONE COLUMN ONLY.
EXP: select [Column name] from [table] union select [column name] from [table] union select [column name] from [table]
ORDER BY BILLDATE
OPEN SALE_BILL
-- Fetch the last row in the cursor. FETCH LAST FROM Sale_Bill
-- Fetch the row immediately prior to the current row in the cursor. FETCH PRIOR FROM Sale_Bill
-- Fetch the second row in the cursor. FETCH ABSOLUTE 2 FROM Sale_Bill
-- Fetch the row that is three rows after the current row. FETCH RELATIVE 3 FROM Sale_Bill
-- Fetch the row that is two rows prior to the current row. FETCH RELATIVE -2 FROM Sale_Bill
Power Command
Power command needs numeric value to show its result
SET @value = 2 SET @counter = 1 --checking status WHILE @counter < 5 BEGIN
--executes according to the value SELECT POWER(@value, @counter) SET NOCOUNT ON SET @counter = @counter + 1 SET NOCOUNT OFF END
(single file)
Alter Database kun11 add file ( name = kun11dat2, Filename = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\kun11dat2.ndf', size = 5MB, maxsize =50MB, filegrowth = 5MB )
Alter Database kun11 ADD file ( name = kun11dat2, Filename = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\kun11dat2.ndf', size = 5MB, maxsize =50MB, filegrowth = 5MB ),
( name = kun11dat3, Filename = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\kun11dat3.ndf', size = 5MB, maxsize =50MB, filegrowth = 5MB )
---------------------TO MODIFY A FILE IN DATABASE--------------------------------------------Alter database KUN11FG1 MODIFY FILEGROUP [ KUN11FG1] DEFAULT
It deletes the existing alues which are already present in a table. DELETE FROM [TABLE NAME] Exp: delete from [temp sale]
Exp: DECLARE @SaleType NVARCHAR(200),@BILLNO NVARCHAR(200), @BILLDATE SMALLDATETIME, @CHALLANNO FLOAT,@PARTYCODE NVARCHAR(200),@SALECODE NVARCHAR(200),@productcode nvarchar(200), @productname nvarchar(200),@units nvarchar(200),@amount float
DECLARE SALE_BILL CURSOR FOR SELECT [SALE TYPE],[BILLNO],[BILLDATE],[CHALLAN NO],[PARTYCODE], [SALECODE] FROM SALE ORDER BY BILLDATE
OPEN SALE_BILL
PRINT 'SALE: ' + @SALETYPE+@BILLNO+' '+ CAST(@BILLDATE AS NVARCHAR(200))+ CAST(@CHALLANNO AS NVARCHAR(200)) +@PARTYCODE+@SALECODE
declare saledetail_bill cursor for select [product code],[product name],[units],[amount] from [sale],[sale detail] where [sale].[sale type]=[sale detail].[sale type] and [sale].[billno]=[sale detail].[billno]
open saledetail_bill
END CLOSE saledetail_BILL DEALLOCATE saledetail_BILL FETCH NEXT FROM SALE_BILL INTO @SALETYPE,@BILLNO, @BILLDATE,@CHALLANNO,@PARTYCODE,@SALECODE
Group by:
It is used when we want to group each item of same kind only once. Syntax: select [column name1], sum(amount) from [table] group by [column name1]
Exp: 1.select [product code],sum(amount) as TAmt from [purchase detail] group by [product code]
2. select [product code],[product name], sum(amount) as TAmt from [purchase detail] group by [product code] Now it will show an error message [Column 'purchase detail.Product Name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.] now select [product code],[product name], sum(amount) as TAmt from [purchase detail] group by [product code] ,[product name]
Having
Having clause works same as where condition do
Syntax: SELECT select_list [ INTO new_table ] FROM table_source [ WHERE search_condition ] [ GROUP BY group_by_expression ] [ HAVING search_condition ]