Print this Page

General SQL Commands

General SQL Commands

How to create tables in SQL Server?

Syntax: Create Table

CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50) default ‘Unknown’,
City char(50) default ‘Delhi’,
Country char(25),
Birth_Date date)

 

How to define Primary Key in SQL Server.

Primary Key#

CREATE TABLE Products
(PID integer PRIMARY KEY,
ProductName varchar(30),
Manufacturer varchar(30))

How to define Unique Key in SQL Server?

Unique:

CREATE TABLE Customer

(SID integer Unique,
Last_Name varchar (30),
First_Name varchar(30));

How to use CHECK in SQL Server?

CHECK:

CREATE TABLE Customer
(SID integer CHECK (SID > 0),
Last_Name varchar (30),
First_Name varchar(30)

How to use References in SQL Server?

References

CREATE TABLE ORDERS
(Order_ID integer primary key,
Order_Date datetime,
Customer_SID integer references CUSTOMER(SID),
Amount double);

How to alter a table in SQL Server?

ALTER

ALTER TABLE TBLORDERS
ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);

Permanent link to this article: http://www.techxpress.in/general-sql-commands/

SQL Select

How to write Select statement in SQL?: The SELECT keyword allows us to grab all information from a column (or columns) on a table. This, of course, necessarily mean that there will be redundancies. What if we only want to select each DISTINCT element? This is easy to accomplish in SQL. All we need to do is to add DISTINCT after SELECT. …

View page »

SQL Distinct

How to use DISTINCT SQL function?   The SELECT keyword allows us to grab all information from a column (or columns) on a table. This, of course, necessarily mean that there will be redundancies. What if we only want to select each DISTINCT element? This is easy to accomplish in SQL. All we need to do is …

View page »

SQL Where

How to use where clause in SQL? We may want to only retrieve stores with sales above $1,000. To do this, we use the WHERE keyword. The syntax is as follows: SELECT “column_name” FROM “table_name” WHERE “condition” For example, to select all stores with sales above $1,000 in Table Store_Information, Table Store_Information store_name Sales Date …

View page »

SQL And|OR

And OR In the previous section, we have seen that the WHERE keyword can be used to conditionally select data from a table. This condition can be a simple condition (like the one presented in the previous section), or it can be a compound condition. Compound conditions are made up of multiple simple conditions connected …

View page »

SQL Between

How to use SQL Between in SQL? Whereas the IN keyword help people to limit the selection criteria to one or more discrete values, the BETWEEN keyword allows for selecting a range. The syntax for the BETWEEN clause is as follows: SELECT “column_name” FROM “table_name” WHERE “column_name” BETWEEN ‘value1′ AND ‘value2′ This will select all rows whose column has a value between …

View page »

IN

IN In SQL, there are two uses of the IN keyword, and this section introduces the one that is related to the WHERE clause. When used in this context, we know exactly the value of the returned values we want to see for at least one of the columns. The syntax for using the IN …

View page »

Like

LIKE is another keyword that is used in the WHERE clause. Basically, LIKE allows you to do a search based on a pattern rather than specifying exactly what is desired (as in IN) or spell out a range (as in BETWEEN). The syntax for is as follows: SELECT “column_name” FROM “table_name” WHERE “column_name” LIKE {PATTERN} …

View page »

Count

Another arithmetic function is COUNT. This allows us to COUNT up the number of row in a certain table. The syntax is, SELECT COUNT(“column_name”) FROM “table_name” For example, if we want to find the number of store entries in our table, Table Store_Information store_name Sales Date Los Angeles $1500 Jan-05-1999 San Diego $250 Jan-07-1999 Los …

View page »

Leave a Reply

Bookmark this page