sql Command and constant
sql Command and constant
SQL is Structured Query Language, which is a computer language for storing, manipulating and
retrieving data stored in a relational database.
SQL is the standard language for Relational Database System. All the Relational Database
Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres and SQL
Server use SQL as their standard database language.
SQL Commands
• The standard SQL commands to interact with relational databases are CREATE, SELECT, INSERT,
UPDATE, DELETE and DROP. These commands can be classified into the following groups based on
their nature:
[email protected] 1
DCL - Data Control Language
SQL Server Management Studio (SSMS), is the client tool that can be used to write and execute SQL
queries.
To connect to the SQL Server Management Studio
1. Click Start
2. Select All Programs
3. Select Microsoft SQL Server 2005, 2008, or 2008 R2 (Depending on the version installed)
4. Select SQL Server Management Studio
2. Next you need to specify the Server Name. Here we can specify the name or the server or IP
Address . If you have SQL Server installed on your local machine, you can specify, (local) or just .
(Period) or 127.0.0.1 Server name = (local)
3. Now select Authentication. The options available here, depends on how you have installed SQL
Server. During installation, if you have chosen mixed mode authentication, you will have both
Windows Authentication and SQL Server Authentication. Otherwise, you will just be able to connect
using windows authentication.
4. If you have chosen Windows Authentication, you dont have to enter user name and password,
otherwise enter the user name and password and click connect.
[email protected] 2
Developer Machines 1,2,3 and 4 connects to the database server using SSMS.
Consistency constraints
The database system checks these constraints every time the database is updated. In general, a constraint can
be an arbitrary predicate pertaining to the database. The data values stored in the database must satisfy certain
Thus, database systems implement integrity constraints that can be tested with minimal overhead:
Domain Constraints. A domain of possible values must be associated with every attribute (for example,
integer types, character types, date/time types).
Referential Integrity. There are cases where we wish to ensure that a value that appears in one relation for a
given set of attributes also appears in a certain set of attributes in another relation (referential integrity).
Assertions . An assertion is any condition that the database must always satisfy. Domain constraints and
referential-integrity constraints are special forms of assertions. For example, “Every department must have at
least five courses offered every semester” must be expressed as an assertion.
Authorization. We may want to differentiate among the users as far as the type of access they are permitted
on various data values in the database.
SQL ─ Constraints
[email protected] 3
• CHECK Constraint: The CHECK constraint ensures that all the values in a column satisfies certain
conditions.
• INDEX: Used to create and retrieve data from the database very quickly.
DEFAULT Constraint
• The DEFAULT constraint provides a default value to a column when the INSERT INTO statement
does not provide a specific value.
UNIQUE Constraint
• The UNIQUE Constraint prevents two records from having identical values in a column. In the
CUSTOMERS table, for example, you might want to prevent two or more people from having an
identical age.
[email protected] 4
Primary Key
• A primary key is a field in a table which uniquely identifies each row/record in a database table.
Primary keys must contain unique values. A primary key column cannot have NULL values.
• A table can have only one primary key, which may consist of single or multiple fields.When multiple
fields are used as a primary key, they are called a composite key.
Foreign Key
• A foreign key is a key used to link two tables together. This is sometimes also called as a referencing
key.
• A Foreign Key is a column or a combination of columns whose values match a Primary Key in a
different table.
CHECK Constraint
• The CHECK Constraint enables a condition to check the value being entered into a record.
• If the condition evaluates to false, the record violates the constraint and isn't entered the table.
[email protected] 5
INDEX Constraint
• The INDEX is used to create and retrieve data from the database very quickly.
• An Index can be created by using a single or a group of columns in a table. When the index is created,
it is assigned a ROWID for each row before it sorts out the data.