SQL - SQL Constraints

SQL constraint - the data table is added for limiting the type
    can be provided that constraints (by CREATE TABLE statement), or may be created in the following table (through the ALTER TABLE statement) when the table is created.
    NULL the NOT - mandatory constraint column does not accept NULL values.
    UNIQUE - constraint uniquely identifies each record in the database table. Each table can have multiple UNIQUE constraints, but each table can have only one PRIMARY KEY constraint.
        MySQL:
            the CREATE TABLE tableName
            (
                Id int the NOT NULL,
                UNIQUE (Id)
            )
        SQLServer / the Oracle:
            the CREATE TABLE tableName
            (
                Id int the NOT NULL UNIQUE
            )
        to be named UNIQUE constraint: MySql / SQLServer / the Oracle:
            the CREATE TABLE tableName
            (
                Id int the NOT NULL ,
                pwd VARCHAR (255) the NOT NULL,
                CONSTRAINT uniqueName UNIQUE (Id, pwd)
            )
        table has been created: ALTER TABLE tableName ADD UNIQUE (Id )
        to be named: ALTER TABLE tableName ADD CONSTRAINT uniqueName UNIQUE (Id, pwd)
        revocation UNIQUE constraint
            MySQL:
                the ALTER tableName the INDEX the uniqueName the DROP tABLE
            SQLServer / the Oracle:
                the ALTER tABLE tableName the DROP cONSTRAINT the uniqueName
    a pRIMARY kEY - primary key constraint constraint uniquely identifies each record in the database table. Primary keys must contain unique values. Primary key column can not contain a NULL value. Each table should have a primary key, and each table can have only one primary key.
        MySQL:
            the CREATE TABLE tableName
            (
                Id int the NOT NULL,
                PRIMARY KEY (Id)
            )
        SQLServer / the Oracle:
            the CREATE TABLE tableName
            (
                Id int the NOT NULL PRIMARY KEY
            )
        named PRIMARY KEY constraints, and to define a plurality of columns PRIMARY KEY constraints:
        the MySQL / SQLServer:
            the CREATE TABLE tableName
            (
                Id int the NOT NULL,
                pwd VARCHAR (255) the NOT NULL,
                cONSTRAINT pkName PRIMARY KEY (Id, pwd)
            )
       
        table has been created: ALTER tABLE tableName ADD PRIMARY KEY ( Id)
        named PRIMARY KEY constraint, and for multiple columns define PRIMARY KEY constraint:
            the ALTER tABLE tableName pkName the ADD cONSTRAINT PRIMARY KEY (Id , pwd)
            Note: If you use the ALTER TABLE statement to add a primary key must be declared as the primary key column does not contain a NULL value (when you first create the table).
        Undo PRIMARY KEY constraint
        To drop a PRIMARY KEY constraint, use the following SQL:
        MySQL:
            the ALTER TABLE tableName DROP PRIMARY KEY
        SQL Server / the Oracle:
            the ALTER TABLE tableName pkName DROP CONSTRAINT
    FOREIGN KEY - FOREIGN KEY in one table points to another table the PRIMARY KEY. Operation for preventing damage between the connection table. That must be one of the values in the table points.
        MySQL:
            the CREATE TABLE tablename1
            (
                Id1 int the NOT NULL,
                Id2 int,
                PRIMARY KEY (Id1),
                a FOREIGN KEY (Id2) the REFERENCES TableName2 (Id2)
            )
        SQL Server / the Oracle:
            TABLE tablename1 the CREATE
            (
            of Id1 int the NOT NULL a PRIMARY KEY,
            of Id2 the REFERENCES TableName2 int FOREIGN KEY (of Id2)
            )
        named FOREIGN KEY constraint, and a plurality of columns is defined FOREIGN KEY constraint:
            the CREATE TABLE tablename1
            (
                of Id1 int the NOT NULL,
                of Id2 int,
                a PRIMARY KEY (Id1),
                cONSTRAINT fkName FOREIGN KEY (Id2) the REFERENCES TableName2 (Id2)
            )
        table has been created:
            the ALTER tABLE tablename1 the ADD FOREIGN KEY (Id2) the REFERENCES TableName2 (Id2)
        name FOREIGN KEY constraint, and for multiple columns defined FOREIGN KEY constraint:
            ALTER TABLE tableName1 ADD CONSTRAINT fkName FOREIGN KEY (Id2) REFERENCES tableName2 (Id2)
        revocation FOREIGN KEY constraint
            the MySQL: the ALTER TABLE tablename1 the DROP FOREIGN KEY fkName
            SQLServer / the Oracle: the ALTER TABLE tablename1 the DROP CONSTRAINT fkName
   the CHECK - limit values for the constraint column It ranges. CHECK constraints defined in a single column, the column specific value only. CHECK constraints defined for a table, this constraint may limit the values in a particular column.
        CHECK constraints specified hereinafter "col1" column must contain only an integer greater than zero.
        SQL My:
            the CREATE TABLE tableName
            (
                col1 int the NOT NULL,
                CHECK (col1> 0)
            )
        SQL Server / the Oracle:
            the CREATE TABLE tableName
            (
                int the NOT NULL CHECK col1 (col1> 0)
            )
        named CHECK constraints, as well as the plurality of columns is defined CHECK constraints:
            the CREATE TABLE tableName
            (
                col1 int the NOT NULL,
                col2 VARCHAR (255),
                CONSTRAINT chkName CHECK (col1> col2 = 0 the AND ' Sandnes')
            )
        table already exists: ALTER tABLE tableName ADD CHECK (col1 > 0)
        named CHECK constraints, as well as the plurality of columns is defined CHECK constraints:
            the ALTER tABLE tableName chkName the ADD cONSTRAINT CHECK (col1> 0 the aND col2 = 'Sandnes')
        revocation CHECK constraints
        SQLServer / the Oracle: the ALTER TABLE DROP cONSTRAINT chkName tableName
        MySQL: the ALTER TABLE tableName DROP CHECK chkName
   the DEFAULT- means for inserting a default value to the column. If no other value is specified, then the default value will be added to all new records.
        TABLE tableName the CREATE
        (
            COL VARCHAR (255) the DEFAULT 'Sandnes'
        )
        by using a similar GETDATE () This function, DEFAULT constraint system can also be used to insert values:
        the CREATE TABLE the Orders
        (
        the OrderDate DATE the DEFAULT GETDATE ()
        )
        table already exists:
        the MySQL : the ALTER TABLE tableName the ALTER COL the SET DEFAULT 'SANDNES'
        SQL Server / the Oracle: the ALTER TABLE tableName the ALTER the COLUMN COL the SET DEFAULT 'SANDNES'
        withdrawal DEFAULT constraint:
        MySQL: the ALTER TABLE tableName the ALTER COL DROP DEFAULT
        SQL Server / the Oracle: the ALTER TABLE tableName the ALTER the COLUMN col DROP DEFAULT

Guess you like

Origin www.cnblogs.com/it-mh/p/12034623.html
SQL