Professional Documents
Culture Documents
Open a file?
SELECT 'hello world'
User Creation?
select user (To see user)
select * from sys.server_principals
create user Umesh identified by dbo
Create Database?
create database sample
Creation of Table?
create table Excel (id int, name varchar(50), dept varchar (50), mob int , address varchar (50))
Update table?
update Excel set name = 'Bimu' where id = 1
update Excel set name = 'lilly' where id = 1 or id 2
update Excel set name = 'lilly' where id = 1 and id 2
Delete statement/data?
delete from sample where id = 7
Add coloum in table?
alter table sample add phone int
alter table sample drop column salary
alter table sample alter column name nchar (5)
Delete table?
truncate table sample (it will delete entire data in table)
drop table sample (it will delete entire table)
delete from sample where id is null (it will delete pritucular value in table)
Primary Key?
It will help to avoid duplicate records.
create Table Excel_2 (id int not null primary key, name varchar(50))
foreign Key?
create Table Excel_2 (id int not null primary key, name varchar(50), Dept int , foreign key references Room int )
foreign key references
create Table Excel_3 (City int not null primary key, name varchar(50), dept varchar (50), mob int ,Address varchar (50) , Id int foreign key
references Excel_2 (Id) )
Unique /Check ?
create table Excel_4 (Std int Unique , Name varchar(50), check (Std >0) )
where operator?
select* from Excel_1 where Address =181
and/or operator?
select* from Excel_1 where Id =1 and Address =185
select* from Excel_1 where Id =1 or Address =185
between/not between operator?
select* from Excel_1 where Id between 1 and 5
select* from Excel_1 where Address not between 184 and 186
select* from Excel_1 where Address not between 184 and 186 and not Name in ('Balu')
Coalesce function?
This function return non null values.
select Id, Coalesce (FirstName,MiddleName,LastName) as Fullname from Excel_5
Union/Union All? It will help to aviod duplicats in table
In Union we can avoid duplicats
select * from Excel_India
Union
select * from Excel_US
In Union All we can see all inclute with duplicats
select * from Excel_India
Union
select * from Excel_US
TOP/WILDCARD
INNER JOIN
SYNTAX 1.
SYNTAX 2.
DATA FORMATE : Returns a datetime value containing the date and time of the computer on which the instance
of SQL Server runs
USE AdventureWorks2019;
GO
CREATE TABLE dbo.EmployeeSales
( BusinessEntityID varchar(11) NOT NULL,
SalesYTD money NOT NULL
);
GO
INSERT INTO dbo.EmployeeSales
SELECT BusinessEntityID, SalesYTD
FROM Sales.SalesPerson;
GO
----------------------------------------------------------------------------------------------------------------------------------------------------------------
COPY TABLE FORM ONE DB TO ANOTHER DB