How can i turn a INT to VARCHAR in SQL [closed] - mysql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm working on a database for my database class.
I have been trying to change the INT from SUBJECT_ID to VARCHAR.
This is the code I have been using but it keeps giving me errors:
ALTER TABLE COURSE
ALTER COLUMN SUBJECT_ID VARCHAR(11);
I also tried this:
SELECT CONVERT(VARCHAR(11),SUBJECT_ID) FROM COURSE;
and this is the table I'm working with:
CREATE TABLE COURSE
(COURSE_ID INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
SUBJECT_ID INT(11) NOT NULL,
COURSE_GRADE_LEVEL CHAR(2) NOT NULL,
FAC_ID INT NOT NULL,
FOREIGN KEY(FAC_ID) REFERENCES FACULTY(FAC_ID));
Any suggestions will be appreciated. Thanks.

Try:
ALTER TABLE COURSE MODIFY SUBJECT_ID VARCHAR(11);

select cast(subject_id as varchar(11)) as subject_id_str from course

Related

how to assign several columns names, having similar characteristics, in sql? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 26 days ago.
Improve this question
I want to create a table.
I'm having long and hard time about naming columns.
If there are 3 columns having same characteristics.
ex) tag_1, tag_2, tag_3
->
CREATE TABLE BOARD (
BOARD_ID bigint not null
primary key,
TAG_1 varchar(10) null,
TAG_2 varchar(10) null,
TAG_3 varchar(10) null
)
Is it a best practice to naming like examples above?
It should be something like this:
CREATE TABLE BOARDS
(
BOARD_ID BIGINT
,name ...
,description ...
);
CREATE TABLE TAGS
(
TAG_ID INT
,TAG VARCHAR(10)
);
CREATE TABLE BOARDSTAGS
(
BOARD_ID BIGINT
,TAG_ID INT
);
You have one table for describing board properties and one of tag properties. Some of the tags can be shared across many boards. So, we need third table for telling which board, which tags has.
In this case, when you need additional tags, you do not need to add new column in the board table.
Nothing wrong with your notation. However, as your columns look really identical, you might wanna take a look into normalizing them. It might make sense in many cases and it will keep your schema cleaner.

Can I use DEFAULT constraint with multiple values in MySQL? Can I add more default values in the example below? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
CREATE TABLE Employee (
Code int NOT NULL,
Last_Name varchar(25) NOT NULL,
First_Name varchar(25),
Age int(2),
City varchar(30) DEFAULT 'KAJI'
);
If I am following you correctly then you are talking about the following line:
...
City varchar(30) DEFAULT 'KAJI'
...
It is not allowed to provide multiple default values for a single column.
If multiple default values are allowed then which value will be used as the default(How DB will decide it)? That's why it is very obvious that there should be only one default value. I Hope, I am clear.

Why is there an Statment Error in MySQL [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have following Statment in MySQL and become every time this error(Screenshot):
CREATE TABLE orderstatus
(
OStatusID int NOT null PRIMARY KEY AUTO_INCREMENT,
OStatus varchar(30) null
(
I dont know why I become this error
Can you help me, please?
enter image description here
the close bracket is wrong, it should be ')'
try this
CREATE TABLE orderstatus
(
OStatusID int NOT null PRIMARY KEY AUTO_INCREMENT,
OStatus varchar(30) null
)
Below is right code Tested Successfully..
CREATE TABLE orderstatus
(
OStatusID int NOT null PRIMARY KEY AUTO_INCREMENT,
OStatus varchar(30) null
)[enter image description here][1]

MYSQL SELECT statements [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I made a table and I want to select certain data from the table using select statements.
I want to see all the book titles that were published in May.
How can I go about doing this?
Here is the table
CREATE TABLE titles
(
title_id CHAR(3) NOT NULL,
title_name VARCHAR(40) NOT NULL,
type VARCHAR(10) ,
pub_id CHAR(3) NOT NULL,
pages INTEGER ,
price DECIMAL(5,2) ,
sales INTEGER ,
pubdate DATE ,
contract SMALLINT NOT NULL,
CONSTRAINT pk_titles PRIMARY KEY (title_id)
)ENGINE = InnoDB;
I tried this:
SELECT * FROM titles
WHERE pubdate LIKE '%%%%-05-%%';
It displays the whole column, how can I get it to only display the books title?
Try this:
SELECT title_name FROM titles WHERE MONTH(pubdate) = '5'

Why can't I create this table? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Creating tables in MySQL confuses me. Sometimes I'm able to get it just fine, other times it seems to yell at me for things I've done before successfully. I'm attempting to create this table with 3 columns. When I try to save the column, it tells me to please enter a valid length. I've used these lengths on these column types before, so why is it yelling at me now? I'm using a form on MySQL, so I don't know the actual SQL syntax for this, but the following is what I'm trying to do.
Create Table: Families
(
`Id` Int(11) Auto_Incriment Primary Key,
`Family` CHAR (255) Unique,
`Species` CHAR (255),
);
Why is it telling me to enter a valid length?
Remove the : after table and the , before the last ) and you misspelled auto_increment
Create Table Families
(
`Id` Int(11) auto_increment Primary Key,
`Family` CHAR (255) Unique,
`Species` CHAR (255)
);
You could "debug" such things on your own if you use a SQL tool that highlights such erros like MySQL Workbench.
Modify It as follow:
Create Table Families
(
`Id` Int(11) AUTO_INCREMENT Primary Key,
`Family` CHAR (255) Unique,
`Species` CHAR (255)
);
You should create a sql query that looks something like this, also make sure you spell attributes correctly:
Create Table: Families
(
`Id` Int(11) AUTO_INCREMENT Primary Key,
`Family` CHAR (255) Unique,
`Species` CHAR (255),
);
In the future please use the mysql guide in this link:
http://dev.mysql.com/doc/refman/5.6/en/