473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Create Table & Provide Default Value

I want to use SQL code to Create a Table & Provide a Default Value for
Each Column.

Here is the code I am using:

CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50) default 'Unknown',
City char(50) default 'Mumbai',
Country char(25),
Birth_Date date)

What can I do to make this work with MS Access?

Thanks!,

zufie

Mar 23 '07 #1
3 25712
On 23 Mar, 14:28, "zufie" <john.marru...@illinois.govwrote:
I want to use SQL code to Create a Table & Provide a Default Value for
Each Column.

Here is the code I am using:

CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50) default 'Unknown',
City char(50) default 'Mumbai',
Country char(25),
Birth_Date date)

What can I do to make this work with MS Access?

Thanks!,

zufie

TTBOMR one must use ALTER TABLE as in

"ALTER TABLE customer ALTER COLUMN FirstName SET DEFAULT 'Bubba'"

My own opinion is that when a default value is needed, it's best to
set this in the form or other user interface, or insert query.

Mar 23 '07 #2
In article <1174674510.412904.62590
@y66g2000hsf.googlegroups.com>, jo***********@illinois.gov
says...
I want to use SQL code to Create a Table & Provide a Default Value for
Each Column.

Here is the code I am using:

CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50) default 'Unknown',
City char(50) default 'Mumbai',
Country char(25),
Birth_Date date)

What can I do to make this work with MS Access?

Thanks!,

zufie

This is by way of example. You might want to look at SQL
Programming Style by Joe Celko for guidance on column names and
data types.

Notice that I was able to insert a record with 3 NOT NULL
columns missing. This was thanks to the default values.

Sub CreateTables()

With CurrentProject.AccessConnection
.Execute _
"CREATE TABLE customer" & _
" (First_Name VARCHAR(50)," & _
" Last_Name VARCHAR(50)," & _
" Mail_Address VARCHAR(50) DEFAULT Unknown," & _
" City_Name VARCHAR(50) DEFAULT Mumbai," & _
" Country_Name VARCHAR(25) DEFAULT Unknown," & _
" Birth_Date DATE," & _
" UNIQUE (Last_Name, First_Name, Birth_Date))"

.Execute _
"INSERT INTO customer" & _
" ( First_Name, Last_Name, Birth_Date )" & _
" VALUES ('Larry', 'Smith', #11/29/1985#);"

End With

End Sub
Mar 24 '07 #3
On Mar 24, 6:37 am, Mike Gramelspacher <grame...@psci.netwrote:
In article <1174674510.412904.62590
@y66g2000hsf.googlegroups.com>, john.marru...@illinois.gov
says...
I want to use SQL code to Create a Table & Provide a Default Value for
Each Column.
Here is the code I am using:
CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50) default 'Unknown',
City char(50) default 'Mumbai',
Country char(25),
Birth_Date date)
What can I do to make this work with MSAccess?
Thanks!,
zufie

This is by way of example. You might want to look at SQL
Programming Style by Joe Celko for guidance on column names and
data types.

Notice that I was able to insert a record with 3 NOT NULL
columns missing. This was thanks to the default values.

Sub CreateTables()

With CurrentProject.AccessConnection
.Execute _
"CREATE TABLE customer" & _
" (First_Name VARCHAR(50)," & _
" Last_Name VARCHAR(50)," & _
" Mail_Address VARCHAR(50) DEFAULT Unknown," & _
" City_Name VARCHAR(50) DEFAULT Mumbai," & _
" Country_Name VARCHAR(25) DEFAULT Unknown," & _
" Birth_Date DATE," & _
" UNIQUE (Last_Name, First_Name, Birth_Date))"

.Execute _
"INSERT INTO customer" & _
" ( First_Name, Last_Name, Birth_Date )" & _
" VALUES ('Larry', 'Smith', #11/29/1985#);"

End With

End Sub- Hide quoted text -

- Show quoted text -
I suppose my statement would make sense if I had used DDL like this:

..Execute _
"CREATE TABLE customer" & _
" (Customer_id IDENTITY (1,1) NOT NULL PRIMARY KEY, " & _
" First_Name VARCHAR(50) NOT NULL," & _
" Last_Name VARCHAR(50) NOT NULL," & _
" Mail_Address VARCHAR(50) DEFAULT Unknown NOT NULL," & _
" City_Name VARCHAR(50) DEFAULT Mumbai NOT NULL," & _
" Country_Name VARCHAR(25) DEFAULT France NOT NULL," & _
" Birth_Date DATE NOT NULL," & _
" UNIQUE (Last_Name, First_Name, Birth_Date))"

I guess you customers will always be persons and will never refuse to
disclose their birth date.

Mar 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Glutinous | last post by:
I've been studying this for hours, searching the www & usenet, and still can't figure out why 'each' returns an array of four key/value pairs, when it looks like just two pairs would suffice... ...
1
by: dawnunder | last post by:
eg. Someone fills out 3 fields. (There will be more but this is just to give you an idea) 1. Country? 2. State? 3. City I want this script to generate a web page and list the people by
2
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks (...
4
by: Max | last post by:
Hello everyone, and thank you in advance for all of your help! I have a tblPrint table in Access 2002. Its structure is as follows: tblPrint ------------------ Name, Text Address1, Text...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
2
by: groupy | last post by:
Hello all, my question might be trivial but since my background isn't DB i'll dare to ask it any way: how to create a real (not virtual) table from view1 & view2 ni sql server? what should i...
6
by: Peter Nurse | last post by:
For reasons that are not relevant (though I explain them below *), I want, for all my users whatever privelige level, an SP which creates and inserts into a temporary table and then another SP...
4
by: TinaF | last post by:
I want to set a default value in a table called "Quotes" for a field called "Source." The "Source" field uses a lookup table called "Source" which looks like this: Sourceabbrev Sourcename...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.