Add to columns to a table then check the table structure : Add Column « Table « SQL Server / T-SQL






Add to columns to a table then check the table structure

 

3>
4>
5>    CREATE TABLE Employees
6>    (
7>       EmployeeID       int           IDENTITY  NOT NULL,
8>       FirstName        varchar(25)             NOT NULL,
9>       MiddleInitial    char(1)                 NULL,
10>       LastName         varchar(25)             NOT NULL,
11>       Title            varchar(25)             NOT NULL,
12>       SSN              varchar(11)             NOT NULL,
13>       Salary           money                   NOT NULL,
14>       PriorSalary      money                   NOT NULL,
15>       LastRaise AS Salary - PriorSalary,
16>       HireDate         smalldatetime           NOT NULL,
17>       TerminationDate  smalldatetime           NULL,
18>       ManagerEmpID     int                     NOT NULL,
19>       Department       varchar(25)             NOT NULL
20>    )
21>    GO
1>
2>
3> EXEC sp_help Employees
4> GO
Name                                                                                                                             Owner
                                                          Type                            Created_datetime
-------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------
--------------------------------------------------------- ------------------------------- -----------------------
Employees                                                                                                                        dbo
                                                          user table                      2008-08-17 13:06:15.063


Column_name                                                                                                                      Type
                                                          Computed                            Length      Prec  Scale Nullable                            TrimTrailingBlanks                  FixedLenNu
llInSource                Collation
-------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------
--------------------------------------------------------- ----------------------------------- ----------- ----- ----- ----------------------------------- ----------------------------------- ----------
------------------------- --------------------------------------------------------------------------------------------------------------------------------
EmployeeID                                                                                                                       int
                                                          no                                            4 10    0     no                                  (n/a)                               (n/a)
                          NULL
FirstName                                                                                                                        varchar
                                                          no                                           25             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS
MiddleInitial                                                                                                                    char
                                                          no                                            1             yes                                 no                                  yes
                          SQL_Latin1_General_CP1_CI_AS
LastName                                                                                                                         varchar
                                                          no                                           25             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS
Title                                                                                                                            varchar
                                                          no                                           25             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS
SSN                                                                                                                              varchar
                                                          no                                           11             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS
Salary                                                                                                                           money
                                                          no                                            8 19    4     no                                  (n/a)                               (n/a)
                          NULL
PriorSalary                                                                                                                      money
                                                          no                                            8 19    4     no                                  (n/a)                               (n/a)
                          NULL
LastRaise                                                                                                                        money
                                                          yes                                           8 19    4     yes                                 (n/a)                               (n/a)
                          NULL
HireDate                                                                                                                         smalldatetime
                                                          no                                            4             no                                  (n/a)                               (n/a)
                          NULL
TerminationDate                                                                                                                  smalldatetime
                                                          no                                            4             yes                                 (n/a)                               (n/a)
                          NULL
ManagerEmpID                                                                                                                     int
                                                          no                                            4 10    0     no                                  (n/a)                               (n/a)
                          NULL
Department                                                                                                                       varchar
                                                          no                                           25             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS

Identity                                                                                                                         Seed                                     Increment
           Not For Replication
-------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------- ------------------------------
---------- -------------------
EmployeeID                                                                                                                                                              1
         1                   0

RowGuidCol
--------------------------------------------------------------------------------------------------------------------------------
No rowguidcol column defined.

Data_located_on_filegroup
--------------------------------------------------------------------------------------------------------------------------------
PRIMARY

The object 'Employees' does not have any indexes, or you do not have permissions.

No constraints are defined on object 'Employees', or you do not have permissions.

No foreign keys reference table 'Employees', or you do not have permissions on referencing tables.
Table is referenced by views
--------------------------------------------------------------------------------------------------------------------------------
1>    ALTER TABLE Employees
2>       ADD
3>          DateOfBirth     datetime   NULL,
4>          LastRaiseDate   datetime   NOT NULL
5>             DEFAULT '2000-01-01'
6>
7> GO
1>
2> EXEC sp_help Employees
3> GO
Name                                                                                                                             Owner
                                                          Type                            Created_datetime
-------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------
--------------------------------------------------------- ------------------------------- -----------------------
Employees                                                                                                                        dbo
                                                          user table                      2008-08-17 13:06:15.063


Column_name                                                                                                                      Type
                                                          Computed                            Length      Prec  Scale Nullable                            TrimTrailingBlanks                  FixedLenNu
llInSource                Collation
-------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------
--------------------------------------------------------- ----------------------------------- ----------- ----- ----- ----------------------------------- ----------------------------------- ----------
------------------------- --------------------------------------------------------------------------------------------------------------------------------
EmployeeID                                                                                                                       int
                                                          no                                            4 10    0     no                                  (n/a)                               (n/a)
                          NULL
FirstName                                                                                                                        varchar
                                                          no                                           25             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS
MiddleInitial                                                                                                                    char
                                                          no                                            1             yes                                 no                                  yes
                          SQL_Latin1_General_CP1_CI_AS
LastName                                                                                                                         varchar
                                                          no                                           25             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS
Title                                                                                                                            varchar
                                                          no                                           25             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS
SSN                                                                                                                              varchar
                                                          no                                           11             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS
Salary                                                                                                                           money
                                                          no                                            8 19    4     no                                  (n/a)                               (n/a)
                          NULL
PriorSalary                                                                                                                      money
                                                          no                                            8 19    4     no                                  (n/a)                               (n/a)
                          NULL
LastRaise                                                                                                                        money
                                                          yes                                           8 19    4     yes                                 (n/a)                               (n/a)
                          NULL
HireDate                                                                                                                         smalldatetime
                                                          no                                            4             no                                  (n/a)                               (n/a)
                          NULL
TerminationDate                                                                                                                  smalldatetime
                                                          no                                            4             yes                                 (n/a)                               (n/a)
                          NULL
ManagerEmpID                                                                                                                     int
                                                          no                                            4 10    0     no                                  (n/a)                               (n/a)
                          NULL
Department                                                                                                                       varchar
                                                          no                                           25             no                                  no                                  no
                          SQL_Latin1_General_CP1_CI_AS
DateOfBirth                                                                                                                      datetime
                                                          no                                            8             yes                                 (n/a)                               (n/a)
                          NULL
LastRaiseDate                                                                                                                    datetime
                                                          no                                            8             no                                  (n/a)                               (n/a)
                          NULL

Identity                                                                                                                         Seed                                     Increment
           Not For Replication
-------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------- ------------------------------
---------- -------------------
EmployeeID                                                                                                                                                              1
         1                   0

RowGuidCol
--------------------------------------------------------------------------------------------------------------------------------
No rowguidcol column defined.

Data_located_on_filegroup
--------------------------------------------------------------------------------------------------------------------------------
PRIMARY

The object 'Employees' does not have any indexes, or you do not have permissions.

constraint_type                                                                                                                                    constraint_name
                                                                            delete_action update_action status_enabled status_for_replication constraint_keys











-------------------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------
--------------------------------------------------------------------------- ------------- ------------- -------------- ---------------------- ----------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------
DEFAULT on column LastRaiseDate                                                                                                                    DF__Employees__LastR__0F0E1094
                                                                            (n/a)         (n/a)         (n/a)          (n/a)                  ('2000-01-01')












No foreign keys reference table 'Employees', or you do not have permissions on referencing tables.
Table is referenced by views
--------------------------------------------------------------------------------------------------------------------------------
1>    drop table Employees;
2>    GO
1>

 








Related examples in the same category

1.Alter table to add column
2.Add columns to a table