Create a database:
create database databasename
Drop a database:
Drop database databasename
Create a table in database:
create table tablename(i int,name varchar(20))
Drop a table in database:
drop table tablename
Update a column in a table:
UPDATE table_name
SET column_name = new_value
WHERE column_name = some_value
Delete a column in a table:
DELETE FROM table_name
WHERE column_name = some_value
Insert values into table:
insert into tablename values('20','suba','shshs')
Another Method:
insert tablename select('20','sjs','sss')
Backup database:
backup database databasename to disk ='e:data.bak'
Restore Database:
restore database databasename from disk ='e:data.bak'
Wait For Delay to Do the Transaction
begin tran
select * from tablename
waitfor delay '00:00:05'
select * from tablename1
commit
To get the current server time:
select Right (convert(varchar(20),getdate(),100),7)
Find Monday of the Current Week:
select dateadd(wk,datediff(wk,0,getdate()),0)Mondayofcurrentweek
Insert a .txt file in a table:
bulk
insert tablename
from 'e:\test.txt'
with
{
field terminator=','
row terminator='\n'
}
Rename a column name in table:
sp_rename'tablename.[oldcolumnname]',newcolumnname,'column'
Rename a tablename:
sp_rename 'oldtablename', 'newtablename'
Find A particular table in database :
SELECT *
FROM sys.Tables
WHERE name LIKE '%tablename%'
No comments:
Post a Comment