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 8 years ago.
Improve this question
I want to design table for patient prescription it contains pat_id, date and more than one prescription prescribed by doctor
How to do this?
Give me a sample query to create table
This isn't really a good quetion and is a very likely candidate for someone down voting it.
Look here for an example schema
http://www.databaseanswers.org/data_models/patient_care/index.htm
Possible this be helpful for you -
CREATE TABLE dbo.Patient
(
PacientID INT IDENTITY(1,1) PRIMARY KEY
, FirstName VARCHAR(30)
, LastName VARCHAR(30)
)
GO
CREATE TABLE dbo.PatientPrescription
(
ID INT IDENTITY(1,1) PRIMARY KEY
, PacientID INT
, DoctorID INT
, [Descritpion] VARCHAR(500)
)
GO
CREATE TABLE dbo.Doctor
(
DoctorID INT IDENTITY(1,1) PRIMARY KEY
, FirstName VARCHAR(30)
, LastName VARCHAR(30)
)
GO
Related
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 8 days ago.
Improve this question
I have working on a project. i found that SQL code on internet. i have not familiar with SQL. anyone help me regarding this. I have facing difficulties to execute this query in SQL work bench after login as administration.
Line number 1, 4, 5 and 6 getting error. Please correct this code what things I need to correct or change.
create user reservation identified by manager;
grant dba to reservation;
commit;
connect reservation/manager;
create table admin6(uname varchar2(40) primary key,name varchar2(40),
pword varchar2(50),mail_id varchar2(60),phone_no varchar2(12));
create table train6(tr_no number(10) primary key,tr_name varchar2(70),
from_stn varchar2(20),to_stn varchar2(20),available number(5),fare number(5));
create table register(uname varchar2(40) primary key,pword varchar2(50),
fname varchar2(40),lname varchar2(40),
addr varchar2(100), phno varchar2(12), mailid varchar2(60));
insert into admin6 values('admin','admin','admin','admin#train.com','9874561230');
insert into admin6 values('shashi','shashi','admin','shashi#train.com','98323561230');
insert into train6 values(10101,'Jodhpur Exp','Howrah','Jodhpur',152,450);
insert into train6 values(10102,'Mumbai Mail','Gaya','Mumbai',182,650);
insert into register values('shashi','shashi','Shashi','Raj','Tekari, Gaya, Bihar',954745222,'shashiraj.972#gmail.com');
commit;
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 last year.
Improve this question
CREATE TABLE BILL
(TRANSACTION_ID VARCHAR2(10) NOT NULL ENABLE,
DATE_BILL DATE,
SERVICE_CHARGE NUMBER(10,2) AS (0.10*PRODUCT_PRICE*PRODUCT_QUANTITY) REFERENCES PRODUCT(PRODUCT_PRICE) AND PRODUCT(PRODUCT_QUANTITY),
TRANSACTION_AMOUNT NUMBER(10,2) AS ((PRODUCT_PRICE*PRODUCT_QUANTITY) + (0.10*PRODUCT_PRICE*PRODUCT_QUANTITY)) REFERENCES PRODUCT(PRODUCT_PRICE) AND PRODUCT(PRODUCT_QUANTITY),
TRANSACTION_TYPE VARCHAR2(45),
ORDER_ID VARCHAR2(45) REFERENCES ORDERS(ORDER_ID),
CUST_ID VARCHAR2(45) NOT NULL ENABLE,
PRIMARY KEY (TRANSACTION_ID)
USING INDEX ENABLE
);
Apart from the fact that syntax you "invented" doesn't even exist, you're trying to create virtual columns (service_charge and transaction_amount) that reference columns from another table(s), most probably product. Well, you can't.
Looks like you'd rather create a view.
Something like this (you didn't post how tables are related to each other so I'm just guessing):
CREATE TABLE bill
(
transaction_id VARCHAR2 (10) PRIMARY KEY,
date_bill DATE,
transaction_type VARCHAR2 (45),
order_id VARCHAR2 (45) REFERENCES orders (order_id),
cust_id VARCHAR2 (45)
);
CREATE OR REPLACE VIEW v_bill_product
AS
SELECT b.transaction_id,
b.date_bill,
b.transaction_type,
b.order_id,
b.cust_id,
--
0.1 * p.product_price * p.product_quantity AS service_charge,
1.1 * p.product_price * product_quantity AS transaction_amount
FROM bill b JOIN product p ON b.transaction_id = p.transaction_id;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I am very new to this. I have created this table and I had no problems doing it:
CREATE TABLE [dbo].[Urban_Rail] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Country] VARCHAR (50) NOT NULL,
[City] VARCHAR (50) NOT NULL,
[Type] VARCHAR (50) NOT NULL,
[Gauge] NCHAR (10) NULL,
[Year] NCHAR (10) NULL,
[Status] VARCHAR (50) NULL,
[Notes] VARCHAR (500) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
Now I am trying to fill in few thousand rows of data using this statement:
INSERT INTO Urban_Rail ('Id','Country','City','Type','Gauge','Year','Status','Notes') VALUES ('','Algeria','Algiers','Metro','1435','2011','Open','');
INSERT INTO Urban_Rail ('Id','Country','City','Type','Gauge','Year','Status','Notes') VALUES ('','Algeria','Algiers','Tram','1435','2011','Open','');
INSERT INTO Urban_Rail ('Id','Country','City','Type','Gauge','Year','Status','Notes') VALUES ('','Algeria','Batna','Tram','','','Planned','');
But I get errors saying that the name of each column is not valid. That does not look true to me. I am wondering if it has something to do with the Id instead which is an auto increment identity which I have left without value in my query. What am I doing wrong here? Some help will be appreciated.
Either remove the ID from the Insert (as it is an Identity) or if you want specific ID's turn Identity_Insert on before running the insert and off again afterwards.
SET IDENTITY_INSERT [dbo].[Urban_Rail] ON
INSERT INTO Urban_Rail (Id,Country,City,Type,Gauge,Year,Status,Notes) VALUES (1,'Algeria','Algiers','Metro','1435','2011','Open','');
SET IDENTITY_INSERT [dbo].[Urban_Rail] OFF
An IDENTITY column should not be included in the INSERT statement. It will automatically populate with the next value.
The column "ID" is an identity column and you're not allowed to insert it since the database assigns it. Take it off the column name and values list in your inserts.
If you DO need to insert the identity column, you can use
SET IDENTITY_INSERT <table> ON
But am guessing you don't need that since your ID's look blank.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm SORRY everyone, It wasn't allowing me to comment. you are right. It's the ALTER I'm having issues with. How do I add the Cumulative GPA column to the table (using the alter statement) where the gpa is displayed between 0.00 and 4.00
CREATE database "IS4440_DuBoseJasmine"
CREATE TABLE StudentInformation (
StudentID CHAR(7) not null,
StudentSSN CHAR(9) null,
StudentFirstName VARCHAR(50) null,
StudentLastName VARCHAR(50) null,
StudentMiddleName VARCHAR(50) null,
StudentHomeCountry CHAR(2) not null
)
/*2*/
ALTER TABLE StudentInformation ADD Cumulative GPA ;
/*3*/
INSERT INTO StudentInformation (StudentID, StudentLastName, StudentFirstName, StudentMiddleName, StudentHomeCountry)
VALUES ('1352154', 'DuBose', 'Jasmine', 'Leigh', 'US')
INSERT INTO StudentInformation (StudentID, StudentLastName, StudentFirstName, StudentMiddleName, StudentHomeCountry)
VALUES ('1234565', 'Smith', 'Johnny', 'Apple', 'GB');
/*4*/
UPDATE StudentInformation SET StudentSSN = 123456789
WHERE StudentID = 1352154;
The update works fine (demonstrated on SQL Fiddle), it is the ALTER TABLE statement that fails. This line:
ALTER TABLE StudentInformation ADD Cumulative GPA;
should be:
ALTER TABLE StudentInformation ADD [Cumulative GPA] INT -- OR WHATEVER TYPE IT SHOULD BE;
ALTER TABLE Documentation
As an aside, although this may just be an example, if it isn't you will want to USE your database before you create the table:
CREATE database "IS4440_DuBoseJasmine";
GO
USE IS4440_DuBoseJasmine;
CREATE TABLE ...
Otherwise you will just be creating your table in whatever database you are connected to.
Your update query is fine, Your ALTER statement what fails, You are adding new column to your table without any datatype or constrains, try this to alter your table
You can use Numeric(3,2) or Decimal(3,2), that means total three digits two after decimal point so a max of 9.99 .
ALTER TABLE StudentInformation ADD CumulativeGPA Numeric(3,2) NULL
To alter your table to add new column make that column NULLABLE and while naming your column do not give spaces.
To make column type Not Nullable
ALTER TABLE StudentInformation ALTER COLUMN CumulativeGPA DECIMAL(3,2) NULL ;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
These are my tables simplified..
person
( id [int],
surname [varchar] (30),
ref [int],
)
episode
(
id [int],
ref [int],
typeId [int],
startDate [datetime]
)
type
(
typeId [int],
typeName [varchar]
)
I want to select all the people who have more than 1 episode and the oldest episode started after 1 Jan 2013. I tried using Row_Number and partition but i'm using Sql Server 2005 and it didn't like Row_Number().
use:
having count(*)>1
and min(startDate) >'1 Jan 2013'
Edited: Below comment is right