GO Transact-SQL

GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor.

SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of SQL Server. The current batch of statements is composed of all statements entered since the last GO, or since the start of the ad hoc session or script if this is the first GO.

A Transact-SQL statement cannot occupy the same line as a GO command. However, the line can contain comments.

Users must follow the rules for batches. For example, any execution of a stored procedure after the first statement in a batch must include the EXECUTE keyword. The scope of local (user-defined) variables is limited to a batch, and cannot be referenced after a GO command.

Continue reading

@ManyToOne and @OneToMany Java Annotations

The Many-to-One link is the foundation of persistent relations. @ManyToOne relation links a source table to a destination with a database REFERENCES column.
Many-to-One adds two capabilities: SQL extensions for links and direct lookup of target beans through field references.

The @OneToMany relation adds collection extensions to the query language and provides a Java Collection containing the children.
@OneToMany represents a collection of children belonging to a parent, like students in Gryffindor house at Hogwarts school.

A Many-to-One relation links one source entity to another target entity. A one-to-many relation links the target entity back to the source entity.

Continue reading

SQL REFERENCES keyword

The REFERENCES keyword is used to create a foreign key when creating a table. The basic formula to use is:

ColumnName DataType REFERENCES ParentTableName(ForeignKeyCcolumn)

The REFERENCES keyword is required. In the ParentTableName placeholder, enter the name of the primary table that holds the information that will be accessed in the current table. In the parentheses of ParentTableName, enter the name of the primary column of the parent table. Here is an example:

CREATE TABLE Persons
(
    PersonID AUTOINCREMENT(1,1) NOT NULL,
    FirstName VARCHAR(20),
    LastName VARCHAR(20) NOT NULL,
    GenderID INTEGER REFERENCES Genders(GenderID),
    CONSTRAINT PK_Persons PRIMARY KEY(PersonID)
);

Useful SQL Where clauses

rows from mytable using a subquery in the where condition:

 WHERE id IN (
       SELECT id
         FROM mytable2
      );

rows from mytable using a list of values:

 WHERE id IN (
       value1,
       value2,
       value3
      );

Difference Between Update and Alter in SQL

Update statement is used to update existing records in a database. Update is a Data Manipulation Language (DML) statement.

UPDATE        tableName
SET           column1Name=value1, column2Name=value2,
WHERE         columnXName=someValue

Alter SQL command is used to modify, delete or add a column to an existing table in a database. Alter is a Data Definition Language (DDL) statement.

ALTER TABLE   tableName
ADD           newColumnName dataTypeOfNewColumn
ALTER TABLE   tableName
DROP COLUMN   columnName
ALTER TABLE   tableName
ALTER COLUMN  columnName newDataType

Alter command modifies the database schema, while update statement only modifies records in a database without modifying its structure.

Read more: http://www.differencebetween.com/difference-between-update-and-vs-alter/#ixzz244ZO0N9T