i am having trouble running a create table query in sql view. the data type is integer with a field size of 8. the query will only run if i enter a field size of "not null" how do i limit the field size to 8?
Eight answers:
2008-02-25 04:07:01 UTC
CREATE TABLE `person` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 64 ) NOT NULL ,
`age` INT( 8 ) NOT NULL ,
UNIQUE (
`id`
)
) ENGINE = innodb;
Simple example that works for me.
mark
2008-02-25 04:09:20 UTC
In MS-SQL Server Integer's don't have sizes as such. It's worked out from the data type. If you want to change the size use Bigint, smallint or tinyint.
You'll need the NOT NULL if you don't have a default value...
2008-02-25 05:41:13 UTC
Integers are the size the database uses for integers - you can't define the size of an integer (in a SQL database or in a programming language).
CommonSense
2008-02-25 06:15:15 UTC
You can't limit the size of an integer field in the table definition. You will have to limit it in either your business or client layer.
nigel r
2008-02-25 06:15:30 UTC
You could create something like numeric(8,0) in SQL Server or number(8,0) in Oracle. These create floating point numbers which only allow 8 digits with no decimal places.
Nige
foutz
2016-10-20 13:33:15 UTC
in case you make the main of a remote places places key with a various constraint, you have have been given in uncomplicated words a million get acceptable of get right of entry to to with a null cost.. working occasion CREATE table type ( identity INT NULL oftentimes used KEY ) CREATE table SubCategory ( CategoryID INT now no longer NULL remote places places KEY REFERENCES (type.identity) ) you could insert records on SubCategory with a null cost for CategoryID, yet a million get acceptable of get right of entry to to on type would have the identity null
Jappy man
2008-02-25 04:04:26 UTC
write a trigger to check the lenght of the entered data
steve_mapes
2008-02-25 06:11:37 UTC
CREATE mytable (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
anum INT UNSIGNED NOT NULL DEFAULT 0
)
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.