Showing posts with label server. Show all posts
Showing posts with label server. Show all posts

Thursday, 28 May 2015

copy tables with data from Current Database to another database in SQL Server Sytax

SCENARIO 
Suppose you have a table with some data in a Database A and you want to copy this data to a table in Database B .

then you should use the following syntax:

USE DatabaseB;

SELECT *
INTO NewTable
FROM DatabaseA.Schemaname.OldTable
Here NewTable and OldTable are two similar tables in different databases.
While handling different databases we must use fully qualified names
 to reach correct tables.





How to create table in SQL Server Management Studio using SQL query

In SQL Server Management Studio, Althogh there are many ways to create a table using GUI and using query written in SQL.
So simple SQL Query to create a table

SQL CREATE TABLE Syntax

CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);

for example: 
Create table Student(
StudentID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);

Wednesday, 27 May 2015

Convert a number to two decimal places in SQL Server Query

Many a times we get some number(float or double) from our sql query operation. But at the end we need a two decimal number. Then how can we achieve this