Posts

Showing posts with the label Sql Server

Create Table with primary key In SQL

creating a table with a primary key to store the pdf path and some of the details.  Here is a query to create a table in SQL and oracle CREATE TABLE TBL_ITG_PDF_DOCUMENT_LIBRARY   (    ID int NOT NULL PRIMARY KEY ,    PolicyName varchar ( 500 ) ,     Description varchar ( max ),      DocumentPath nvarchar ( max ),      UploadedBy varchar ( 100 ),    UploadedDate date ,     );

insert data into database in asp.net c#

Here is the simple insert query to insert data into database using mssql server. protected void Button1_Click( object sender, EventArgs e)         {             string constr = ConfigurationManager .ConnectionStrings[ "ApplicationServices" ].ConnectionString;             SqlConnection con = new SqlConnection (constr);             SqlCommand cmd = new SqlCommand ( "insert into tbl_view values(@Name,@EmailID,@view,@Activity,@DateTime)" );             cmd.CommandType = CommandType .Text;   

how to insert datetime in database in asp.net c#

Insert date time in database using datetime.now you can see the line of code. cmd.Parameters.AddWithValue("@DateTime", DateTime.Now);

Like Operator In Sql Server

Like operator used in where clause it’s use to search exact word from table. There are two wildcards in Like operator. _  - Underscore perform a single character % - Percent sign Perform for zero, multiple and for one character  Note: You can mix underscore and percent in query Like Operator Example Example 1 SELECT  *  FROM  Employee WHERE  Emp_Name  LIKE   'T%' ; [The following query returns all data where Emp_name starts with T] Example 2 SELECT  *  FROM  Employee WHERE  Emp_Name  LIKE   'a%i' ; [The following query selects al data and where Emp_Name starts with A and ends with I] Example 3 SELECT  *  FROM  Employee WHERE  Emp_Name  LIKE   '%T' ; [The following query returns all data with Emp_name where all Employee Name end with T] Example 4 SELECT  *  FROM  Employee WHERE  Emp_Name  LIKE   '%or%' ; ...

Select distinct value from data table in SQL

SELECT DISTINCT query is used to return different values from data table. In database there are so many duplicate values and if you want to select only different data and row from table use distinct statement. SELECT DISTINCT QUERY SELECT   DISTINCT   Emp_name ,  Emp_City, FROM  your_ table_name ; Now will show you the difference between SELECT and SELECT DISTINCT  SELECT Example Following Sql Query select all duplicate rows from column Emp_name from table SELECT   Emp_name FROM  Employee_table; SELECT DISTINCT Example Following Sql query select only distinct value from column Emp_name From Employee_table SELECT DITINCT   Emp_name FROM  Employee_table; Example Following SQL query selects and counts the different rows SELECT   COUNT ( DISTINCT   Emp_name )  FROM  Employee_table;

Where Clause in sql server

WHERE clause statement is used to filter records. WHERE clause is use to retrieve those records which matches a predefined condition. Where clause not only use for retriveation also use for update and delete Where Clause Query Select * from table_name where condition_here Where clause Example       Select * from employee where Emp_Name=’Sid’;       Select * from employee where emp_Id =1; NOTE Use double quote if you are using text value in where clause and don’t use quotes for numeric field. You can see the example. Operators in where clause These are the operators use in where clause. Operator = Equal <>   Not equal >   Greater than <   Less than >= Greater than or equal <= Less than or equal BETWEEN Between LIKE ...

Insert Update Delete and Other Important SQL Commands in MS SQl SERVER

For Fresher it’s important to know few important commands before starting coding You should remember all the commands how and why use. Firstly you should know that commands are not case sensitive, and after ending your any query it’s important to put semicolon (;). It separates the every sql commands. Here is the important Sql Commands in sql. SELECT : Select Command use to take out all data from you database. UPDATE: Update data of database. DELETE:   To delete data from table. INSERT INTO : Inserts new data and new rows into a database CREATE DATABASE : It use to create a new database. ALTER DATABASE: Modifies a database CREATE TABLE : To creates a new table ALTER TABLE : It use to modify and delete in table DROP TABLE: Use to delete a table from database CREATE INDEX : Use to create index in table it retrieves data very fast from database. Index use to speedup searches. DROP INDEX : Use to delete ...

AND, OR and NOT Conditions in Where clause SQL SERVER

Image
We can combined AND, OR, and NOT Conditions in where clause. And and OR Condition are used to retrieve data using multiple conditions ·          And Condition shows data if condition is divide by and in where clause OR condition retrieve rows if conditions are divided by OR Not Condition shows a data if condition is not true AND Query SELECT   * FROM  your_table_name WHERE   condition_1   AND   condition _2   AND   condition_3 ; OR Query SELECT   * FROM  your_ table_name  WHERE   condition _ 1   OR   condition _ 2   OR   condition_3 ; NOT Syntax SELECT   * FROM  your_ table_name WHERE   NOT   condition ; Well this was the syntax now will show you some examples of And, OR and NOT Example AND Condition The Following query returns all rows where “FirstName” is “Nancy” and “LastName” is “Davolio” ...

Select query in MS SQL Server

We use Select Query to select data from database which is stored in table, here is the simple select query example using SQL. Select Query Examples Example 1: Select * from Your_table_name; The following Query use to select all columns from a row, (*) this symbol select all rows and column from a table. Example 2: Select column_1, column_2 from your_table_name; If you want select few columns or want to select any particular column from a table so here is the query. This query is to select single, multiple or any columns from a table.