Category Archives: SQL-SERVER

Create New Database in SQL-Server Management Studio 2008.

Create New database in sql server management studio 2008. create table in sql database in sql server management studio 2008.

Create Stored Procedure in SQL-Server.

Stored Procedure in SQL Server - Create new Stored Procedure in SQL-Server management studio 2008. how to write sql stored procedure in database.

Copy one Table with Data to another Table in SQL-Server

create and copy new table from an existing table in sql server management studio. How to copy all the columns with data from one table to another table in sql server management studio 2008.

CHAR, VARCHAR and NVARCHAR Data Type Difference.

SQL Datatype difference : Difference Between Sql Server CHAR, VARCHAR and NVARCHAR Data Type.

How to Create Stored Procedure in SQL-Server?

How to Create Stored Procedure in SQL-Server?

Stored Procedure is write SQL Query in Specific format in SQL Server and call them from your application, instead of writing queries inside your program code.
Stored Procedures are precompiled Transact-SQL statements which is stored in a SQL Server database.
Stored procedure is a simple SQL Statement, which is precompiled.

STEP 1 – Open the SQL Server management studi0

STEP 2 – Create a New Database

STEP 3 – Expand the DataBase name, Select the Programmability folder —> Stored Procedure. read more

Create XML using SQL Query in SQL Server 2008

Here, we will learn how to create XML using Query:

SELECTTOP1000 [Code]
      ,[Name]
      ,[Price]
  FROM[Temp].[dbo].[Product]
  FORXML RAW ('Product'),
  ROOT ('Products');
Here SQL statement “FOR XML RAW” creates one XML node for every corresponding row in database and columns will be created as attributes of that XML node. Results:
<Products>
<ProductCode="1"Name="Computer"Price="100.0000"/>
<ProductCode="2"Name="Mobile"Price="250.0000"/>
</Products>
SQL ELEMENTS create Elements instead of Attributes in xml

SELECTTOP1000 [Code]
      ,[Name]
      ,[Price]
  FROM[Temp].[dbo].[Product]
  FORXML RAW ('Product'),
ROOT ('Products'),
ELEMENTS;
read more

What is Key in SQl-Server?

=&0=&

  • The field must be unique within it’s Column.
    Primary Key

  • A Combination of unique & not null.

  • A table has Only one Primary Key.
    Foreign Key

  • Define relationship between two Table.

  • Either one to one, one to many, many to many

    Candidate Key


  • A table may have more than one combination of columns that could uniquely identify the rows in a Table, each combination is a Candidate Key.
    OR
  • A candidate Key is one that can identify each rows of a table uniquely.
  • read more

    What is Stored Procedure in SQL-Server?

    What is Stored Procedure in SQL-Server?

  • Stored Procedure is write SQL Query in Specific format in SQL Server and call them from your application, instead of writing queries inside your program code. 
  • Stored Procedures are precompiled Transact-SQL statements which is stored in a SQL Server database. 
  • Stored procedure is a simple SQL Statement, which is precompiled. 
  • SP Increase the performance of your application.
    Create a Stored Procedure in SQL-Server

    CREATE PROCEDURE [STUDENT_SELECT]
      (


        //here is your parameter for insert/update/delete purpose.
      )
      AS


     BEGIN


         SELECT * FROM STUDENTMST


     END

  • read more

    What is SQL?

    =&0=&

  • SQL stands for Structured Query Language.

  • SQL is a globally accepted standard language that is used to handle database related activities for creating database schemas, updating/inserting/deleting of data, retrievieng data, and managing user roles and database activities.

     

  • SQL is used to communicate with a database.

     

  • it is the standard language for relational database management systems. SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database.
  • read more

    How to Create a Table in SQL?

     Create a Table in SQL

    • Below is the code / syntax to create a table in SQL,

    The SQL syntax for CREATE TABLE is

    CREATE TABLE “Table_Name”(“column 1” “datatype_for_column_1”,
    “column 2” “datatype_for_column_2”,
    … )

    • Create Table for Student, the Table name StudentMst with below Column.

    CREATE TABLE StudentMst
    (
    First_Name char(50),
    Last_Name char(50),
    Address char(50),
    City char(50),
    Country char(25),
    )

    • If you want to specify the Default values for some column then,

    CREATE TABLE StudentMst
    (
    First_Name char(50),
    Last_Name char(50),
    Address char(50) default ‘Meera Academy’,
    City char(50) default ‘Modasa’,
    Country char(25),
    ) read more

    What is DDL Command in SQL-Server?

    Data Definition Language (DDL)

      • DDL stands for Data Definition Language. 
      • DDL statements are used to define the database structure or schema. 
      • It is used to create and modify the structure of database objects in database.
      •  Examples

        CREATE, ALTER, DROP statements

        1. CREATE
          – For creating databases & database objects.

        Syntax for creating database:

        CREATE DATABASE DataBaseName


      Create DataBase Students

                     Syntax for creating Table:

        CREATE TABLE StudentsMst
      (
      StudentId int,|
      StudentName varchar(50),
      StudentCity varchar(50),
      )

       2. ALTER
         – For altering/modifying the exsisting tables.

           Syntax for Altering/Adding columns:

        Alter Table TableName Add Column1 datatype,Column2 datatype,…..

           Example

      Alter Table StudentsMst Add DateOfBirth datetime,SchoolName varchar(300) read more

    What is DML Command in SQL-Server?

    Data Manipulation Language(DML)

    DML Stands for Data Manipulation LanguageDML statements are used for managing data within schema objects. Some examples:  SELECT – Retrieve/Select data from the database
    This command is used to fetch/get a result set of records from a table.

    Syntax :- Select * from TableName

     

  • INSERT – insert data into a table
  • This command is used to add records to a table.

    Syntax :- Insert into TableName (Colmn1,Colmn2,…..) values (Value1,Value2,…..)

    Insert into StudemtMst (Name,Pincode) values (‘Meera’, ‘383315’)

     

  • UPDATE – updates existing data within the table 
  • This command is used to edit/Update the records of a table.

    Syntax :- Update Table TableName set Colmn1=’Values’
    Update Table StudentMst set Name=’Meera’ and Pincode=’383315′ read more