Insert with default value : Insert « Insert Delete Update « SQL Server / T-SQL

SQL Server / T-SQL
1. Aggregate Functions
2. Analytical Functions
3. Constraints
4. Cursor
5. Data Set
6. Data Type
7. Database
8. Date Timezone
9. Index
10. Insert Delete Update
11. Math Functions
12. Select Query
13. Sequence
14. Store Procedure Function
15. String Functions
16. Subquery
17. System
18. Table
19. Table Joins
20. Transact SQL
21. Transaction
22. Trigger
23. View
24. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL » Insert Delete Update » Insert 
Insert with default value

 


2CREATE TABLE publishers2
3(
4>     pub_id        int            NOT NULL PRIMARY KEY IDENTITY,
5>     pub_name      varchar(40)    NULL DEFAULT ('Anonymous'),
6>     city          varchar(20)    NULL,
7>     state         char(2)        NULL,
8>     country       varchar(30)    NOT NULL DEFAULT('USA')
9)
10> GO
1>
2>
3INSERT publishers2 VALUES ('AAA Publishing', 'Vancouver', 'BC',
4>     'Canada')
5>
6INSERT INTO publishers2 VALUES ('Best Publishing', 'Mexico City',
7>     NULL, 'Mexico')
8>
9INSERT INTO publishers2 (pub_name, city, state, country)
10> VALUES ('Complete Publishing', 'Washington', 'DC', 'United States')
11>
12INSERT publishers2 (state, cityVALUES ('WA', 'Poulsbo')
13>
14INSERT publishers2 VALUES (NULL, NULL, NULL, DEFAULT)
15>
16INSERT publishers2 VALUES (DEFAULT, NULL, 'WA', DEFAULT)
17>
18INSERT publishers2 VALUES (NULL, DEFAULT, DEFAULT, DEFAULT)
19>
20INSERT publishers2 DEFAULT VALUES
21> GO

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)
1>
2> drop table publishers2;
3> GO
1>

 
Related examples in the same category
1. The order of the columns in the insert statement
2. Inserts one or more rows selected with a subquery
3. Leave column as NULL
4. Inserting Several Records in a Query Batch
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.