Skip to main content

Insert Data Into The Table SQL SERVER

 First we have to create table with the table name Student with the following fields in which we are going to insert records.

Column Name
Data Type
Length
Std_Name
Varchar
50
Address
Varchar
50
City
Varchar
50
Age
Numeric
8
DOB
DateTime
8
Class
Varchar
10

Insert Data Into The Table for execution of queries open the new query window from the Microsoft Sql Server Management Studio.



Select SQL Server from the drop down combo if you are using the client else in case of server enter (local) like above. Select window authentication or SQL Server authentication according to your system installation and click on OK. Query window will appear as you click on New Query marked as first red. Select your database from the combo displaying at the toolbar above on the screen. Now write down the following query in the displaying window.

·          The syntax for insertion is –
Insert into table name values (‘String value’, numeric value)

Use single quotes for passing the character value and numeric value will be passed with out quotes. Date time will be passed with single quotes using “MM/DD/YYYY” format.

·          For passing the data in all fields of the above table
Insert into student values (‘Ram’,’Saheed Nagar’, ‘AGRA’, 21, ‘12/25/1987’, ‘10’)

·          For passing the data in specified fields of the above table
Insert into student (std_name, Address, city, age) values (‘Ram’,’Saheed Nagar’, ‘AGRA’, 21)

·          For passing the complete table in another table with same data structure.
Insert into second Table Name select * from first Table Name

·          For passing the complete table in another table with different data structure.
Insert into second Table Name select field1, field2, field3 from first Table Name

·          INSERT with DEFAULT VALUES
INSERT student DEFAULT VALUES
                INSERT employee VALUES ('KLT91469F', 'Katrina', 'L', 'Thompson', DEFAULT, DEFAULT, DEFAULT, '01/14/95')



When inserting rows, these rules apply:
 
·          Inserting an empty string (' ') into a varchar or text column inserts a single space. All char columns are right-padded to the    defined length. All trailing spaces are removed from data inserted into varchar columns, except in strings that contain only spaces. These strings are truncated to a single space.
·          If an INSERT statement violates a constraint, default, or rule, or if    it is the wrong datatype, the statement fails and SQL Server displays    an error message. Constraints are defined with either the CREATE TABLE    or ALTER TABLE statement. Defaults are created with the CREATE DEFAULT statement and rules are created with the CREATE RULE statement.
·          Inserting a null value into a text or image column does not create a    valid text pointer, nor does it pre-allocate a 2K text page. For details    on inserting text and image data, see the text and image Manipulation    topic.
·           An INSERT statement must follow the rules for a batch. For details, see the Batches topic.
 
 
When you specify values for only some of the columns in the column list, one of three things can happen to the columns that have no values:
 
·          A default value is entered if the column has a DEFAULT constraint, if a default is bound to the column, or a default is bound to the underlying user-defined datatype.
 
·          NULL is entered if the column allows NULLs and no default value exists for the column.
 
·          An error message is displayed and the row is rejected if the column    is defined as NOT NULL and no default exists.



Comments

Popular posts from this blog

UP TET 2011 Exam Application,UPTET 2011 Result | UPTET 2011 Revised Result

UPTET 2011 Result | UPTET 2011 Revised Result | UPTET 2011 Updated Result |Board of High School and Intermediate Education Uttar Pradesh, Allahabad UP TET Advertisement 2011 and Exam Detail/Admit Card/Call Letter Download UP TET 2011 FORM & DETAILS  GET LATEST DETAIL ABOUT 72825 Primary Teacher Merit List UP TET 2011 Application form submission last date is 18-Oct-2011.Forms will be distributed from PNB bank all over UP.According to latest news Appearing B.Ed student also eligible for TET exam 2011 so they can also submit their forms to concern District.There is no requirement for Rojgar Registration No and Bank receipt within the application form.UP TET 2011 exam results will be avail on http://www.uptet2011.com . Now you can easily get Application from from the P.N.B bank Branches. UPTET 2011 Result | UPTET 2011 Revised Result | UPTET 2011 Updated Result |  Board of High School and Intermediate Education Uttar Pradesh, Al...

DataView Rowfilter With Like % in C#.Net

DataView RowFilter Syntax in C#,ASP.Net Example This example describes syntax of DataView.RowFilter expression. It shows how to correctly build expression string (without "SQL injection" ) using methods to escape values. Column names If a column name contains any of these special characters ~ ( ) # \ / = > < + – * % & | ^ ' " [ ], you must enclose the column name within square brackets [ ]. If a column namecontains right bracket ] or backslash \, escape it with backslash (\] or \\). [C#] dataView.RowFilter = "id = 10″; // no special character in column name " id " dataView.RowFilter = "$id = 10″; // no special character in column name " $id " dataView.RowFilter = "[#id] = 10″; // special character " #" in column name "#id" dataView.RowFilter = "[[id\]] = 10″; // special characters in column name " [id] " Literals String values are enclosed within single qu...

UP Primary Teacher Recruitment 2011 – 72825 vacancy filled by jan 2012,Up Basic Education Primary Teacher Result, Up Basic Education Primary Teachers DIET wise Merit List, Primary Teachers Vacancy ,Teachers Vacancy in UP

Uttar Pradesh Government will recruit 72,825 Primary Teachers in schools of Basic Education council. This decision has been approved in the cabinet of UP. There are total 3,86,726 posts of teachers in the state out of which 2,84,391 posts have already been created. Currently only 1,87,155 teachers are working. There are 1,99,571 vacant posts of primary teachers  and the Government is planning to fill up 72,825 posts. Details of eligibility and application process are following: Eligibility : Educational Qualification –  Minimum 50% in Graduation ( BA / B.Sc /B.Com) with B.Ed degree Have to qualify Teacher Eligibility Test ( UP TET) Age  should be 18 to 35 years ( as on 1 st  July,2011  Applicaton fee  – Rs. 500 for General Candidates, Rs. 200 for SC, ST . There is no application fee for PH candidates. Interested candidates who are living in UP for last five years can apply from five districts of their...