0% found this document useful (0 votes)
22 views

Lab Exercised Bms

Uploaded by

ramehoinama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Lab Exercised Bms

Uploaded by

ramehoinama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Create new database: create database mydb;


2. Delete a database: drop database mydb;
3. Rename a database:
exec sp_renamedb 'olddb', 'newdb';
or,
alter database olddb modify name=newdb;
4. Select a database: use mydb;
5. Check server name: select @@servername
6. Check SQL Server version: select @@version
7. Create/delete/rename table
8. Create table with primary key and identity
column
CREATE TABLE TableName
(
Id INT IDENTITY(1,1) PRIMARY KEY,
Name Nvarchar(500),
Age INT
)
9. Add new columns to an existing table.
10. Remove a column from an existing table.
11. Insert values into a table
INSERT INTO TableName (Name,Age) VALUES
('Max',30);
12. Insert multiple rows in a single query:
INSERT INTO TableName (Name,Age)
VALUES ('Max',30),('John',28),('Jack',31);
13. Update single record:
UPDATE TableName SET NAME='Max Payne'
WHERE Id=1
14. Update all records:
UPDATE TableName SET AGE=31
15. Delete single/all records from a table
16. Select all columns from a table: Select * from
TableName
17. Select specific columns: SELECT
ColumnName1,ColumnName2 from TableName
18. Create/alter/drop View
19. Create/alter/drop stored procedure
20. Create/alter/drop functions
21. Create/alter/drop/disable/enable triggers
22. List all databases/tables/views/stored
precedures/triggers
Select name from sys.databases;
select name from sys.tables;
select name from sys.views;
select name from sys.procedures;
select name from sys.triggers;
23. Select records within two dates:
SELECT * FROM EMPLOYEE WHERE
CONVERT(date, CreatedOn) BETWEEN
'1/1/2015' AND '12/31/2016'

24. Check SQL Server version: SELECT


@@version
25. Backup Database :BACKUP DATABASE
DataBaseName TO
DISK='d:\NameOfBackupFile.bak'
26. Restore Database :RESTORE DATABASE
DataBaseName TO
DISK='d:\NameOfBackupFile.bak'
27. Left Outer Join/Right Outer Join/Full Outer
Join
28. CASE Expression :
SELECT CASE Name
WHEN 'max' THEN 'Name is max'
WHEN 'jack' THEN 'Name is max'
ELSE ' You have selected other user'
END AS Result
FROM TableName
29. Select Query with:
i. Distinct/Where/And/Or/Not/Order
By/Top/Like/In/Between/As/
30. Aggregate functions: min/max/avg/sum/count
31. Wildcards: _ and %
32. Self join
33. Union/Except/Intersect
34. SQL comments: single line and multiline
35. SQL Operators:
36. Exists/Any/All/Some
37. Group By/Having
38. SQL Constraints: not null, unique, foreign key,
check, default, primary key
39. Create clustered and non-clustered index
40. Comparing null values in SQL

You might also like