Skip to main content

Posts

Showing posts from May, 2013

Taking Backup of database in one server and restoring in other via sql commands

Database YourDB has full backup YourBaackUpFile.bak. It can be restored using following two steps. Step 1:  Retrive the Logical file name of the database from backup. RESTORE  FILELISTONLY  FROM DISK =  'D:BackUpYourBaackUpFile.bak' GO Step 2:  Use the values in the LogicalName Column in following Step. Step 2.1: ----Checking if the drive exist(for ldf n mdf files) in this particular server EXEC master.dbo.xp_fileexist 'YourLDFLogicalName'  EXEC master.dbo.xp_fileexist ' YourMDFLogicalName It will give 3 columns, for file, directory and root directory. Check if it exist or not for both LDF and MDF files. Step 2.2 ---If not then change the file path using these lines --For data file SELECT TOP 1 ms . physical_name FROM master . sys . master_files ms WHERE ms . file_id = 2 ORDER BY ms . database_id DESC --For log file SELECT TOP 1 ms . physical_name FROM master . sys . master_files ms WHERE m...

SQL Joins

Follow @harshit_parshii SQL JOIN The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables. Tables in a database are often related to each other with keys. A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table FULL OUTER JOIN A JOIN is made matching a column on a table to a column on the other table. After a FULL OUTER JOIN, for a given value (red), for a given row with this value on one table ([ red | 9999 ]), one row is created for each row that matches on the other table ([ red | OOOOOO ] and [ red | LLLLLL ]). If a value exists in only one table, then a row is created and is completed with NULL columns. FROM table_1 FULL OUTER JOIN table_2 ON table_1...